projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
The beginnings of syntax-related checks for gnulib.
[gnulib.git]
/
lib
/
canonicalize.c
diff --git
a/lib/canonicalize.c
b/lib/canonicalize.c
index
822fe6f
..
8c48b42
100644
(file)
--- a/
lib/canonicalize.c
+++ b/
lib/canonicalize.c
@@
-1,5
+1,5
@@
/* Return the canonical absolute name of a given file.
/* Return the canonical absolute name of a given file.
- Copyright (C) 1996-200
5
Free Software Foundation, Inc.
+ Copyright (C) 1996-200
6
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-16,23
+16,12
@@
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
#include "canonicalize.h"
#include "canonicalize.h"
-#ifdef STDC_HEADERS
-# include <stdlib.h>
-#else
-void free ();
-#endif
-
-#if defined STDC_HEADERS || defined HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
+#include <stdlib.h>
+#include <string.h>
#if HAVE_SYS_PARAM_H
# include <sys/param.h>
#if HAVE_SYS_PARAM_H
# include <sys/param.h>
@@
-40,19
+29,19
@@
void free ();
#include <sys/stat.h>
#include <sys/stat.h>
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
+#include <unistd.h>
#include <errno.h>
#include <stddef.h>
#include "cycle-check.h"
#include <errno.h>
#include <stddef.h>
#include "cycle-check.h"
-#include "path-concat.h"
-#include "stat-macros.h"
+#include "filenamecat.h"
#include "xalloc.h"
#include "xgetcwd.h"
#include "xalloc.h"
#include "xgetcwd.h"
+#ifndef ELOOP
+# define ELOOP 0
+#endif
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
@@
-62,8
+51,8
@@
void free ();
#if !HAVE_CANONICALIZE_FILE_NAME
/* Return the canonical absolute name of file NAME. A canonical name
#if !HAVE_CANONICALIZE_FILE_NAME
/* Return the canonical absolute name of file NAME. A canonical name
- does not contain any `.', `..' components nor any repeated
path
- separators ('/') or symlinks. All
path
components must exist.
+ does not contain any `.', `..' components nor any repeated
file name
+ separators ('/') or symlinks. All components must exist.
The result is malloc'd. */
char *
The result is malloc'd. */
char *
@@
-89,7
+78,7
@@
canonicalize_file_name (const char *name)
/* All known hosts with resolvepath (e.g. Solaris 7) don't turn
relative names into absolute ones, so prepend the working
/* All known hosts with resolvepath (e.g. Solaris 7) don't turn
relative names into absolute ones, so prepend the working
- directory if the
path
is not absolute. */
+ directory if the
file name
is not absolute. */
if (name[0] != '/')
{
char *wd;
if (name[0] != '/')
{
char *wd;
@@
-97,7
+86,7
@@
canonicalize_file_name (const char *name)
if (!(wd = xgetcwd ()))
return NULL;
if (!(wd = xgetcwd ()))
return NULL;
- extra_buf =
path
_concat (wd, name, NULL);
+ extra_buf =
file_name
_concat (wd, name, NULL);
name = extra_buf;
free (wd);
}
name = extra_buf;
free (wd);
}
@@
-135,15
+124,17
@@
canonicalize_file_name (const char *name)
#endif /* !HAVE_CANONICALIZE_FILE_NAME */
/* Return the canonical absolute name of file NAME. A canonical name
#endif /* !HAVE_CANONICALIZE_FILE_NAME */
/* Return the canonical absolute name of file NAME. A canonical name
- does not contain any `.', `..' components nor any repeated
path
- separators ('/') or symlinks. Whether
path
components must exist
+ does not contain any `.', `..' components nor any repeated
file name
+ separators ('/') or symlinks. Whether components must exist
or not depends on canonicalize mode. The result is malloc'd. */
char *
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
{
or not depends on canonicalize mode. The result is malloc'd. */
char *
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
{
- char *rpath, *dest, *extra_buf = NULL;
- const char *start, *end, *rpath_limit;
+ char *rname, *dest, *extra_buf = NULL;
+ char const *start;
+ char const *end;
+ char const *rname_limit;
size_t extra_len = 0;
struct cycle_check_state cycle_state;
size_t extra_len = 0;
struct cycle_check_state cycle_state;
@@
-161,38
+152,38
@@
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
if (name[0] != '/')
{
if (name[0] != '/')
{
- r
path
= xgetcwd ();
- if (!r
path
)
+ r
name
= xgetcwd ();
+ if (!r
name
)
return NULL;
return NULL;
- dest = strchr (r
path
, '\0');
- if (dest - r
path
< PATH_MAX)
+ dest = strchr (r
name
, '\0');
+ if (dest - r
name
< PATH_MAX)
{
{
- char *p = xrealloc (r
path
, PATH_MAX);
- dest = p + (dest - r
path
);
- r
path
= p;
- r
path_limit = rpath
+ PATH_MAX;
+ char *p = xrealloc (r
name
, PATH_MAX);
+ dest = p + (dest - r
name
);
+ r
name
= p;
+ r
name_limit = rname
+ PATH_MAX;
}
else
{
}
else
{
- r
path
_limit = dest;
+ r
name
_limit = dest;
}
}
else
{
}
}
else
{
- r
path
= xmalloc (PATH_MAX);
- r
path_limit = rpath
+ PATH_MAX;
- r
path
[0] = '/';
- dest = r
path
+ 1;
+ r
name
= xmalloc (PATH_MAX);
+ r
name_limit = rname
+ PATH_MAX;
+ r
name
[0] = '/';
+ dest = r
name
+ 1;
}
cycle_check_init (&cycle_state);
for (start = end = name; *start; start = end)
{
}
cycle_check_init (&cycle_state);
for (start = end = name; *start; start = end)
{
- /* Skip sequence of multiple
path-
separators. */
+ /* Skip sequence of multiple
file name
separators. */
while (*start == '/')
++start;
while (*start == '/')
++start;
- /* Find end of
path
component. */
+ /* Find end of component. */
for (end = start; *end && *end != '/'; ++end)
/* Nothing. */;
for (end = start; *end && *end != '/'; ++end)
/* Nothing. */;
@@
-203,7
+194,7
@@
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
else if (end - start == 2 && start[0] == '.' && start[1] == '.')
{
/* Back up to previous component, ignore if at root already. */
else if (end - start == 2 && start[0] == '.' && start[1] == '.')
{
/* Back up to previous component, ignore if at root already. */
- if (dest > r
path
+ 1)
+ if (dest > r
name
+ 1)
while ((--dest)[-1] != '/');
}
else
while ((--dest)[-1] != '/');
}
else
@@
-213,26
+204,26
@@
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
if (dest[-1] != '/')
*dest++ = '/';
if (dest[-1] != '/')
*dest++ = '/';
- if (dest + (end - start) >= r
path
_limit)
+ if (dest + (end - start) >= r
name
_limit)
{
{
- ptrdiff_t dest_offset = dest - r
path
;
- size_t new_size = r
path_limit - rpath
;
+ ptrdiff_t dest_offset = dest - r
name
;
+ size_t new_size = r
name_limit - rname
;
if (end - start + 1 > PATH_MAX)
new_size += end - start + 1;
else
new_size += PATH_MAX;
if (end - start + 1 > PATH_MAX)
new_size += end - start + 1;
else
new_size += PATH_MAX;
- r
path = xrealloc (rpath
, new_size);
- r
path_limit = rpath
+ new_size;
+ r
name = xrealloc (rname
, new_size);
+ r
name_limit = rname
+ new_size;
- dest = r
path
+ dest_offset;
+ dest = r
name
+ dest_offset;
}
dest = memcpy (dest, start, end - start);
dest += end - start;
*dest = '\0';
}
dest = memcpy (dest, start, end - start);
dest += end - start;
*dest = '\0';
- if (lstat (r
path, &st) <
0)
+ if (lstat (r
name, &st) !=
0)
{
if (can_mode == CAN_EXISTING)
goto error;
{
if (can_mode == CAN_EXISTING)
goto error;
@@
-255,7
+246,7
@@
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
goto error;
}
goto error;
}
- buf = xreadlink (r
path
, st.st_size);
+ buf = xreadlink (r
name
, st.st_size);
if (!buf)
{
if (can_mode == CAN_MISSING)
if (!buf)
{
if (can_mode == CAN_MISSING)
@@
-284,10
+275,10
@@
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
name = end = memcpy (extra_buf, buf, n);
if (buf[0] == '/')
name = end = memcpy (extra_buf, buf, n);
if (buf[0] == '/')
- dest = r
path
+ 1; /* It's an absolute symlink */
+ dest = r
name
+ 1; /* It's an absolute symlink */
else
/* Back up to previous component, ignore if at root already: */
else
/* Back up to previous component, ignore if at root already: */
- if (dest > r
path
+ 1)
+ if (dest > r
name
+ 1)
while ((--dest)[-1] != '/');
free (buf);
while ((--dest)[-1] != '/');
free (buf);
@@
-302,15
+293,15
@@
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
}
}
}
}
}
}
- if (dest > r
path
+ 1 && dest[-1] == '/')
+ if (dest > r
name
+ 1 && dest[-1] == '/')
--dest;
*dest = '\0';
free (extra_buf);
--dest;
*dest = '\0';
free (extra_buf);
- return r
path
;
+ return r
name
;
error:
free (extra_buf);
error:
free (extra_buf);
- free (r
path
);
+ free (r
name
);
return NULL;
}
return NULL;
}