* 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). --- ChangeLog | 25 +++++++++++++++++++++++++ find/defs.h | 5 +++-- find/exec.c | 4 +++- find/find.c | 33 +++++++++++++-------------------- find/ftsfind.c | 8 +++++--- find/pred.c | 2 +- find/util.c | 7 ++++--- 7 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/ChangeLog b/ChangeLog index dee336e..6278f0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,30 @@ 2011-07-09 James Youngman <j...@gnu.org> + Fix a number of compiler warnings (mostly const-correctness). + * 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). + Mark strings in find.c as not needing translation. * find/find.c (main): The default name of the program also doesn't need translation, so annotate that accordingly. diff --git a/find/defs.h b/find/defs.h index 6e11174..d5d787d 100644 --- a/find/defs.h +++ b/find/defs.h @@ -258,7 +258,7 @@ struct predicate /* Only used for debugging, but defined unconditionally so individual modules can be compiled with -DDEBUG. */ - char *p_name; + const char *p_name; /* The type of this node. There are two kinds. The first is real predicates ("primaries") such as -perm, -print, or -exec. The @@ -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. Thsi 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 b4039a5..3b04577 100644 --- a/find/exec.c +++ b/find/exec.c @@ -120,7 +120,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; @@ -293,6 +293,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/find.c b/find/find.c index 045e35f..fdf6e8a 100644 --- a/find/find.c +++ b/find/find.c @@ -80,9 +80,9 @@ static void init_mounted_dev_list (int mandatory); #endif -static void process_top_path (char *pathname, mode_t mode); -static int process_path (char *pathname, char *name, bool leaf, char *parent, mode_t type); -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); +static int process_path (const char *pathname, const char *name, bool leaf, const char *parent, mode_t type); +static void process_dir (const char *pathname, const char *name, int pathlen, const struct stat *statp, const char *parent); @@ -116,13 +116,6 @@ enum WdSanityCheckFatality int -get_current_dirfd (void) -{ - return AT_FDCWD; -} - - -int main (int argc, char **argv) { int i; @@ -928,11 +921,11 @@ 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, struct stat *pstat, - void (*action)(char *pathname, - char *basename, + void (*action)(const char *pathname, + const char *basename, int mode, struct stat *pstat)) { @@ -1001,8 +994,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, struct stat *pstat) { @@ -1013,8 +1006,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, struct stat *pstat) { @@ -1038,7 +1031,7 @@ do_process_predicate (char *pathname, and move to that. */ static void -process_top_path (char *pathname, mode_t mode) +process_top_path (const char *pathname, mode_t mode) { at_top (pathname, mode, NULL, do_process_top_dir); } @@ -1124,7 +1117,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) { struct stat stat_buf; @@ -1241,7 +1234,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/ftsfind.c b/find/ftsfind.c index f4c1250..8df4bad 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -156,7 +156,7 @@ static void init_mounted_dev_list (void); #define HANDLECASE(N) case N: return #N; -static char * +static const char * get_fts_info_name (int info) { static char buf[10]; @@ -301,7 +301,7 @@ show_outstanding_execdirs (FILE *fp) pfx = NULL; if (pfx) { - int i; + size_t i; const struct exec_val *execp = &p->args.exec_vec; ++seen; @@ -610,16 +610,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/pred.c b/find/pred.c index 08bcddb..0b37696 100644 --- a/find/pred.c +++ b/find/pred.c @@ -1216,7 +1216,7 @@ pred_context (const char *pathname, struct stat *stat_buf, Return BUF. */ static char * -blank_rtrim (char *str, char *buf) +blank_rtrim (const char *str, char *buf) { int i; diff --git a/find/util.c b/find/util.c index 175b40e..7daf4cd 100644 --- a/find/util.c +++ b/find/util.c @@ -62,9 +62,9 @@ struct debug_option_assoc { - char *name; + const char *name; int val; - char *docstring; + const char *docstring; }; static struct debug_option_assoc debugassoc[] = { @@ -146,7 +146,7 @@ insert_primary_noarg (const struct parser_table *entry) static void show_valid_debug_options (FILE *fp, int full) { - int i; + size_t i; if (full) { fprintf (fp, _("Valid arguments for -D:\n")); @@ -190,6 +190,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 -- 1.7.2.5 _______________________________________________ Findutils-patches mailing list Findutils-patches@gnu.org https://lists.gnu.org/mailman/listinfo/findutils-patches