* lib/listfile.c: #include "areadlink.h" but not "dircallback.h", since we no longer need to use get_link_name_at. (get_link_name_at): Delete. (get_link_name_cb): Delete. (get_link_name): Delete. * lib/listfile.h: Remove declaration of get_link_name_at. * find/pred.c (match_lname): Use areadlinkat instead of get_link_name_at.
Signed-off-by: James Youngman <[email protected]> --- ChangeLog | 10 +++++++ find/pred.c | 20 +++++++++---- import-gnulib.config | 1 + lib/listfile.c | 73 +++++++++----------------------------------------- lib/listfile.h | 2 - 5 files changed, 38 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index 709235a..db5cb3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2010-04-04 James Youngman <[email protected]> + Make use of gnulib's areadlinkat. + * lib/listfile.c: #include "areadlink.h" but not "dircallback.h", + since we no longer need to use get_link_name_at. + (get_link_name_at): Delete. + (get_link_name_cb): Delete. + (get_link_name): Delete. + * lib/listfile.h: Remove declaration of get_link_name_at. + * find/pred.c (match_lname): Use areadlinkat instead of + get_link_name_at. + Fix Savannah bug #29435: fd_is_cloexec does not work on Fedora buildhosts. Fix open_cloexec on hosts which ignore O_CLOEXEC (i.e. old kernels). diff --git a/find/pred.c b/find/pred.c index 7df37b1..040d9ea 100644 --- a/find/pred.c +++ b/find/pred.c @@ -874,14 +874,16 @@ do_fprintf (struct format_val *dest, if (S_ISLNK (stat_buf->st_mode)) { - linkname = get_link_name_at (pathname, state.cwd_dir_fd, state.rel_pathname); - if (linkname == 0) - state.exit_status = 1; + linkname = areadlinkat (state.cwd_dir_fd, state.rel_pathname); + if (linkname == NULL) + { + nonfatal_file_error (pathname); + state.exit_status = 1; + } } if (linkname) { checked_print_quoted (dest, segment->text, linkname); - free (linkname); } else { @@ -890,6 +892,7 @@ do_fprintf (struct format_val *dest, */ checked_print_quoted (dest, segment->text, ""); } + free (linkname); } #endif /* S_ISLNK */ break; @@ -1320,14 +1323,19 @@ match_lname (const char *pathname, struct stat *stat_buf, struct predicate *pred #ifdef S_ISLNK if (S_ISLNK (stat_buf->st_mode)) { - char *linkname = get_link_name_at (pathname, state.cwd_dir_fd, state.rel_pathname); + char *linkname = areadlinkat (state.cwd_dir_fd, state.rel_pathname); if (linkname) { if (fnmatch (pred_ptr->args.str, linkname, ignore_case ? FNM_CASEFOLD : 0) == 0) ret = true; - free (linkname); } + else + { + nonfatal_file_error (pathname); + state.exit_status = 1; + } + free (linkname); } #endif /* S_ISLNK */ return ret; diff --git a/import-gnulib.config b/import-gnulib.config index 119a3d5..6439333 100644 --- a/import-gnulib.config +++ b/import-gnulib.config @@ -29,6 +29,7 @@ update-copyright # Solaris which lack those functions. modules=' alloca +areadlinkat argmatch assert c-strstr diff --git a/lib/listfile.c b/lib/listfile.c index 19db768..cad4924 100644 --- a/lib/listfile.c +++ b/lib/listfile.c @@ -39,8 +39,8 @@ #include "pathmax.h" #include "error.h" #include "filemode.h" -#include "dircallback.h" #include "idcache.h" +#include "areadlink.h" #include "listfile.h" @@ -259,19 +259,26 @@ list_file (const char *name, print_name (name, stream, literal_control_chars); -#ifdef S_ISLNK if (S_ISLNK (statp->st_mode)) { - char *linkname = get_link_name_at (name, dir_fd, relname); - + char *linkname = areadlinkat (dir_fd, relname); if (linkname) { fputs (" -> ", stream); print_name (linkname, stream, literal_control_chars); - free (linkname); } + else + { + /* POSIX requires in the case of find that if we issue a + * diagnostic we should have a nonzero status. However, + * this function doesn't have a way of telling the caller to + * do that. However, since this function is only used when + * processing "-ls", we're already using an extension. + */ + error (0, errno, "%s", name); + } + free (linkname); } -#endif putc ('\n', stream); } @@ -340,57 +347,3 @@ static void print_name (register const char *p, FILE *stream, int literal_contro else print_name_with_quoting (p, stream); } - -#ifdef S_ISLNK -static char * -get_link_name (const char *name, char *relname) -{ - register char *linkname; - register int linklen; - - /* st_size is wrong for symlinks on AIX, and on - mount points with some automounters. - So allocate a pessimistic PATH_MAX + 1 bytes. */ -#define LINK_BUF PATH_MAX - linkname = xmalloc (LINK_BUF + 1); - linklen = readlink (relname, linkname, LINK_BUF); - if (linklen < 0) - { - error (0, errno, "%s", name); - free (linkname); - return 0; - } - linkname[linklen] = '\0'; - return linkname; -} - -struct link_name_args -{ - const char *name; - char *relname; - char *result; -}; - -static int -get_link_name_cb (void *context) -{ - struct link_name_args *args = context; - args->result = get_link_name (args->name, args->relname); - return 0; -} - -char * -get_link_name_at (const char *name, int dir_fd, char *relname) -{ - struct link_name_args args; - args.result = NULL; - args.name = name; - args.relname = relname; - if (0 == run_in_dir (dir_fd, get_link_name_cb, &args)) - return args.result; - else - return NULL; -} - - -#endif diff --git a/lib/listfile.h b/lib/listfile.h index cf2305a..4861930 100644 --- a/lib/listfile.h +++ b/lib/listfile.h @@ -22,8 +22,6 @@ void list_file (const char *name, int dir_fd, char *relname, const struct stat *statp, time_t current_time, int output_block_size, int literal_control_chars, FILE *stream); -char * get_link_name_at (const char *name, int dir_fd, char *relname); - size_t file_blocksize(const struct stat *p); #endif -- 1.7.0 _______________________________________________ Findutils-patches mailing list [email protected] http://lists.gnu.org/mailman/listinfo/findutils-patches
