* find/find.c (get_current_dirfd): remove unused function. (process_dir): make parameters const: parent, pathname, name. (process_path): make parameters const: parent, pathname, name. (at_top): Modify the function pointer parameter accordingly. * find/ftsfind.c (get_fts_info_name): Now returns const char*, not char*. (show_outstanding_execdirs): Fix type of loop variable to avoid possible overflow. (process_all_startpoints): Avoid compiler warning about overflow of int loop variable. * find/defs.h (struct predicate): Make p_name const. (struct state): make rel_pathname const. * find/exec.c (impl_pred_exec): Make prefix const. (launch): Silence compiler warning about unused parameter argc. * find/pred.c (blank_rtrim): Make str parameter const, since we do not modify it. * find/util.c (debug_option_assoc): name and docstring are now const qualified. (show_valid_debug_options): Avoid signed/unsigned comparison by using a size_t array index. (set_stat_placeholders): Avoid a compiler warning on systems lacking birth time fields (and on which this function therefore does nothing). --- find/defs.h | 3 ++- find/exec.c | 4 +++- find/ftsfind.c | 6 ++++-- find/oldfind.c | 28 +++++++++++++--------------- find/util.c | 5 +++-- 5 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/find/defs.h b/find/defs.h index 2894455..34125a8 100644 --- a/find/defs.h +++ b/find/defs.h @@ -636,7 +636,8 @@ struct state /* The file being operated on, relative to the current directory. Used for stat, readlink, remove, and opendir. */ - char *rel_pathname; + const char *rel_pathname; + /* The directory fd to which rel_pathname is relative. This is relevant * when we're navigating the hierarchy with fts() and using FTS_CWDFD. */ diff --git a/find/exec.c b/find/exec.c index f8bd438..8d20143 100644 --- a/find/exec.c +++ b/find/exec.c @@ -114,7 +114,7 @@ impl_pred_exec (const char *pathname, const char *target; bool result; const bool local = is_exec_in_local_dir (pred_ptr->pred_func); - char *prefix; + const char *prefix; size_t pfxlen; (void) stat_buf; @@ -292,6 +292,8 @@ launch (struct buildcmd_control *ctl, void *usercontext, int argc, char **argv) static int first_time = 1; struct exec_val *execp = usercontext; + (void) argc; /* silence compiler warning */ + /* Make sure output of command doesn't get mixed with find output. */ fflush (stdout); fflush (stderr); diff --git a/find/ftsfind.c b/find/ftsfind.c index cbb46de..5128e57 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -152,7 +152,7 @@ static void init_mounted_dev_list (void); #define STRINGIFY(X) #X #define HANDLECASE(N) case N: return #N; -static char * +static const char * get_fts_info_name (int info) { static char buf[10]; @@ -615,16 +615,18 @@ static bool process_all_startpoints (int argc, char *argv[]) { int i; + bool empty = true; /* figure out how many start points there are */ for (i = 0; i < argc && !looks_like_expression (argv[i], true); i++) { + empty = false; state.starting_path_length = strlen (argv[i]); /* TODO: is this redundant? */ if (!find (argv[i])) return false; } - if (i == 0) + if (empty) { /* * We use a temporary variable here because some actions modify diff --git a/find/oldfind.c b/find/oldfind.c index 986e7b4..cd235c0 100644 --- a/find/oldfind.c +++ b/find/oldfind.c @@ -95,11 +95,9 @@ enum static void init_mounted_dev_list (int mandatory); #endif -static void process_top_path (char *pathname, mode_t mode, ino_t inum); -static int process_path (char *pathname, char *name, bool leaf, char *parent, mode_t type, ino_t inum); -static void process_dir (char *pathname, char *name, int pathlen, const struct stat *statp, char *parent); - - +static void process_top_path (const char *pathname, mode_t mode, ino_t inum); +static int process_path (const char *pathname, const char *name, bool leaf, const char *parent, mode_t type, ino_t inum); +static void process_dir (const char *pathname, const char *name, int pathlen, const struct stat *statp, const char *parent); /* A file descriptor open to the initial working directory. Doing it this way allows us to work when the i.w.d. has @@ -981,12 +979,12 @@ chdir_back (void) * specified directory is a child of "." or is the root directory. */ static void -at_top (char *pathname, +at_top (const char *pathname, mode_t mode, ino_t inum, struct stat *pstat, - void (*action)(char *pathname, - char *basename, + void (*action)(const char *pathname, + const char *basename, int mode, ino_t inum, struct stat *pstat)) @@ -1056,8 +1054,8 @@ at_top (char *pathname, } -static void do_process_top_dir (char *pathname, - char *base, +static void do_process_top_dir (const char *pathname, + const char *base, int mode, ino_t inum, struct stat *pstat) @@ -1069,8 +1067,8 @@ static void do_process_top_dir (char *pathname, } static void -do_process_predicate (char *pathname, - char *base, +do_process_predicate (const char *pathname, + const char *base, int mode, ino_t inum, struct stat *pstat) @@ -1095,7 +1093,7 @@ do_process_predicate (char *pathname, and move to that. */ static void -process_top_path (char *pathname, mode_t mode, ino_t inum) +process_top_path (const char *pathname, mode_t mode, ino_t inum) { at_top (pathname, mode, inum, NULL, do_process_top_dir); } @@ -1181,7 +1179,7 @@ issue_loop_warning (const char *name, const char *pathname, int level) Return nonzero iff PATHNAME is a directory. */ static int -process_path (char *pathname, char *name, bool leaf, char *parent, +process_path (const char *pathname, const char *name, bool leaf, const char *parent, mode_t mode, ino_t inum) { struct stat stat_buf; @@ -1307,7 +1305,7 @@ process_path (char *pathname, char *name, bool leaf, char *parent, starting directory. */ static void -process_dir (char *pathname, char *name, int pathlen, const struct stat *statp, char *parent) +process_dir (const char *pathname, const char *name, int pathlen, const struct stat *statp, const char *parent) { int subdirs_left; /* Number of unexamined subdirs in PATHNAME. */ bool subdirs_unreliable; /* if true, cannot use dir link count as subdir limif (if false, it may STILL be unreliable) */ diff --git a/find/util.c b/find/util.c index cf7965f..1b4a07a 100644 --- a/find/util.c +++ b/find/util.c @@ -55,9 +55,9 @@ struct debug_option_assoc { - char *name; + const char *name; int val; - char *docstring; + const char *docstring; }; static struct debug_option_assoc debugassoc[] = { @@ -176,6 +176,7 @@ usage (FILE *fp, int status, char *msg) void set_stat_placeholders (struct stat *p) { + (void) p; /* silence warning for systems lacking these fields. */ #if HAVE_STRUCT_STAT_ST_BIRTHTIME p->st_birthtime = 0; #endif -- 2.1.4