From 88b70560464afbc44c6233abbb7375fd5c464124 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 12 Nov 1992 04:14:54 +0000 Subject: [PATCH] all files: make most variables static and const when possible. declare lots of functions static. --- src/basename.c | 5 ++-- src/date.c | 9 +++---- src/echo.c | 2 +- src/env.c | 7 +++--- src/expr.c | 75 +++++++++++++++++++++++++++++++--------------------------- src/id.c | 23 +++++++++--------- src/nice.c | 11 +++++---- src/pathchk.c | 19 ++++++++------- src/printf.c | 37 +++++++++++++++-------------- src/sleep.c | 5 ++-- src/su.c | 45 ++++++++++++++++++----------------- src/tee.c | 7 +++--- src/test.c | 5 ++-- src/tty.c | 6 ++--- src/uname.c | 11 +++++---- src/who.c | 42 ++++++++++++++++---------------- 16 files changed, 164 insertions(+), 145 deletions(-) diff --git a/src/basename.c b/src/basename.c index 767dbaf..f8d9e17 100644 --- a/src/basename.c +++ b/src/basename.c @@ -30,9 +30,10 @@ #include "system.h" char *basename (); -void remove_suffix (); void strip_trailing_slashes (); +static void remove_suffix (); + void main (argc, argv) int argc; @@ -61,7 +62,7 @@ main (argc, argv) /* Remove SUFFIX from the end of NAME if it is there, unless NAME consists entirely of SUFFIX. */ -void +static void remove_suffix (name, suffix) register char *name, *suffix; { diff --git a/src/date.c b/src/date.c index bb4c581..8ca574e 100644 --- a/src/date.c +++ b/src/date.c @@ -66,8 +66,9 @@ char *xrealloc (); time_t get_date (); time_t posixtime (); void error (); -void show_date (); -void usage (); + +static void show_date (); +static void usage (); /* putenv string to use Universal Coordinated Time. POSIX.2 says it should be "TZ=UCT0" or "TZ=GMT0". */ @@ -147,7 +148,7 @@ main (argc, argv) in FORMAT, followed by a newline. If FORMAT is NULL, use the standard output format (ctime style but with a timezone inserted). */ -void +static void show_date (format, when) char *format; time_t when; @@ -180,7 +181,7 @@ show_date (format, when) free (out); } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/echo.c b/src/echo.c index cae62ce..b8c4e58 100644 --- a/src/echo.c +++ b/src/echo.c @@ -126,7 +126,7 @@ just_echo: register char *s = argv[0]; register int c; - while (c = *s++) + while ((c = *s++)) { if (c == '\\' && *s) { diff --git a/src/env.c b/src/env.c index a9bc501..9633180 100644 --- a/src/env.c +++ b/src/env.c @@ -84,14 +84,15 @@ int putenv (); void error (); -void usage (); + +static void usage (); extern char **environ; /* The name by which this program was run. */ char *program_name; -static struct option longopts[] = +static struct option const longopts[] = { {"ignore-environment", 0, NULL, 'i'}, {"unset", 1, NULL, 'u'}, @@ -157,7 +158,7 @@ main (argc, argv, envp) error (errno == ENOENT ? 127 : 126, errno, "%s", argv[optind]); } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/expr.c b/src/expr.c index 61a6c09..3dd9136 100644 --- a/src/expr.c +++ b/src/expr.c @@ -67,23 +67,27 @@ static char **args; /* The name this program was run with. */ char *program_name; -VALUE *docolon (); -VALUE *eval (); -VALUE *int_value (); -VALUE *str_value (); +void error (); char *xstrdup (); char *strstr (); char *xmalloc (); -int isstring (); -int nextarg (); -int nomoreargs (); -int null (); -int toarith (); -void error (); -void freev (); -void printv (); -void tostring (); -void trace (); + +static VALUE *docolon (); +static VALUE *eval (); +static VALUE *int_value (); +static VALUE *str_value (); +static int isstring (); +static int nextarg (); +static int nomoreargs (); +static int null (); +static int toarith (); +static void freev (); +static void printv (); +static void tostring (); + +#ifdef EVAL_TRACE +static void trace (); +#endif void main (argc, argv) @@ -111,7 +115,7 @@ main (argc, argv) /* Return a VALUE for I. */ -VALUE * +static VALUE * int_value (i) int i; { @@ -125,7 +129,7 @@ int_value (i) /* Return a VALUE for S. */ -VALUE * +static VALUE * str_value (s) char *s; { @@ -139,7 +143,7 @@ str_value (s) /* Free VALUE V, including structure components. */ -void +static void freev (v) VALUE *v; { @@ -150,7 +154,7 @@ freev (v) /* Print VALUE V. */ -void +static void printv (v) VALUE *v; { @@ -167,7 +171,7 @@ printv (v) /* Return nonzero if V is a null-string or zero-number. */ -int +static int null (v) VALUE *v; { @@ -182,7 +186,7 @@ null (v) /* Return nonzero if V is a string value. */ -int +static int isstring (v) VALUE *v; { @@ -191,7 +195,7 @@ isstring (v) /* Coerce V to a string value (can't fail). */ -void +static void tostring (v) VALUE *v; { @@ -212,7 +216,7 @@ tostring (v) /* Coerce V to an integer value. Return 1 on success, 0 on failure. */ -int +static int toarith (v) VALUE *v; { @@ -247,7 +251,7 @@ toarith (v) /* Return nonzero if the next token matches STR exactly. STR must not be NULL. */ -int +static int nextarg (str) char *str; { @@ -258,7 +262,7 @@ nextarg (str) /* Return nonzero if there no more tokens. */ -int +static int nomoreargs () { return *args == 0; @@ -267,6 +271,7 @@ nomoreargs () /* The comparison operator handling functions. */ #define cmpf(name, rel) \ +static \ int name (l, r) VALUE *l; VALUE *r; \ { \ if (isstring (l) || isstring (r)) \ @@ -278,7 +283,6 @@ int name (l, r) VALUE *l; VALUE *r; \ else \ return l->u.i rel r->u.i; \ } - cmpf (less_than, <) cmpf (less_equal, <=) cmpf (equal, ==) @@ -291,6 +295,7 @@ cmpf (greater_than, >) /* The arithmetic operator handling functions. */ #define arithf(name, op) \ +static \ int name (l, r) VALUE *l; VALUE *r; \ { \ if (!toarith (l) || !toarith (r)) \ @@ -309,7 +314,7 @@ arithf (mod, %) #ifdef EVAL_TRACE /* Print evaluation trace and args remaining. */ -void +static void trace (fxn) char *fxn; { @@ -326,7 +331,7 @@ trace (fxn) SV is the VALUE for the lhs (the string), PV is the VALUE for the rhs (the pattern). */ -VALUE * +static VALUE * docolon (sv, pv) VALUE *sv; VALUE *pv; @@ -374,7 +379,7 @@ docolon (sv, pv) /* Handle bare operands and ( expr ) syntax. */ -VALUE * +static VALUE * eval7 () { VALUE *v; @@ -401,7 +406,7 @@ eval7 () /* Handle match, substr, index, and length keywords. */ -VALUE * +static VALUE * eval6 () { VALUE *l; @@ -476,7 +481,7 @@ eval6 () /* Handle : operator (pattern matching). Calls docolon to do the real work. */ -VALUE * +static VALUE * eval5 () { VALUE *l; @@ -505,7 +510,7 @@ eval5 () /* Handle *, /, % operators. */ -VALUE * +static VALUE * eval4 () { VALUE *l; @@ -538,7 +543,7 @@ eval4 () /* Handle +, - operators. */ -VALUE * +static VALUE * eval3 () { VALUE *l; @@ -569,7 +574,7 @@ eval3 () /* Handle comparisons. */ -VALUE * +static VALUE * eval2 () { VALUE *l; @@ -610,7 +615,7 @@ eval2 () /* Handle &. */ -VALUE * +static VALUE * eval1 () { VALUE *l; @@ -642,7 +647,7 @@ eval1 () /* Handle |. */ -VALUE * +static VALUE * eval () { VALUE *l; diff --git a/src/id.c b/src/id.c index 1c9482f..e7aa883 100644 --- a/src/id.c +++ b/src/id.c @@ -58,11 +58,12 @@ gid_t getegid (); char *xmalloc (); int getugroups (); void error (); -void print_user (); -void print_group (); -void print_group_list (); -void print_full_info (); -void usage (); + +static void print_user (); +static void print_group (); +static void print_group_list (); +static void print_full_info (); +static void usage (); /* The name this program was run with. */ char *program_name; @@ -89,7 +90,7 @@ static gid_t rgid, egid; /* The number of errors encountered so far. */ static int problems = 0; -static struct option longopts[] = +static struct option const longopts[] = { {"group", 0, NULL, 'g'}, {"name", 0, NULL, 'n'}, @@ -173,7 +174,7 @@ main (argc, argv) /* Print the name or value of user ID UID. */ -void +static void print_user (uid) int uid; { @@ -194,7 +195,7 @@ print_user (uid) /* Print the name or value of group ID GID. */ -void +static void print_group (gid) int gid; { @@ -215,7 +216,7 @@ print_group (gid) /* Print all of the distinct groups the user is in . */ -void +static void print_group_list (username) char *username; { @@ -258,7 +259,7 @@ print_group_list (username) /* Print all of the info about the user's user and group IDs. */ -void +static void print_full_info (username) char *username; { @@ -336,7 +337,7 @@ print_full_info (username) #endif } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/nice.c b/src/nice.c index 6878a34..52d79ef 100644 --- a/src/nice.c +++ b/src/nice.c @@ -26,14 +26,15 @@ #endif #include "system.h" -int isinteger (); void error (); -void usage (); + +static int isinteger (); +static void usage (); /* The name this program was run with. */ char *program_name; -static struct option longopts[] = +static struct option const longopts[] = { {"adjustment", 1, NULL, 'n'}, {NULL, 0, NULL, 0} @@ -122,7 +123,7 @@ main (argc, argv) /* Return nonzero if S represents a (possibly signed) decimal integer, zero if not. */ -int +static int isinteger (s) char *s; { @@ -139,7 +140,7 @@ isinteger (s) return 1; } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/pathchk.c b/src/pathchk.c index 33b912b..a5f7767 100644 --- a/src/pathchk.c +++ b/src/pathchk.c @@ -88,14 +88,15 @@ #endif char *xstrdup(); -int validate_path (); void error (); -void usage (); + +static int validate_path (); +static void usage (); /* The name this program was run with. */ char *program_name; -static struct option longopts[] = +static struct option const longopts[] = { {"portability", 0, NULL, 'p'}, {NULL, 0, NULL, 0} @@ -136,7 +137,7 @@ main (argc, argv) /* Each element is nonzero if the corresponding ASCII character is in the POSIX portable character set, and zero if it is not. In addition, the entry for `/' is nonzero to simplify checking. */ -static char portable_chars[] = +static char const portable_chars[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0-15 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-31 */ @@ -158,14 +159,14 @@ static char portable_chars[] = /* If PATH contains only portable characters, return 1, else 0. */ -int +static int portable_chars_only (path) char *path; { char *p; for (p = path; *p; ++p) - if (portable_chars[*p] == 0) + if (portable_chars[(unsigned char)*p] == 0) { error (0, 0, "path `%s' contains nonportable character `%c'", path, *p); @@ -177,7 +178,7 @@ portable_chars_only (path) /* Return 1 if PATH is a usable leading directory, 0 if not, 2 if it doesn't exist. */ -int +static int dir_ok (path) char *path; { @@ -222,7 +223,7 @@ dir_ok (path) Return 0 if all of these tests are successful, 1 if any fail. */ -int +static int validate_path (path, portability) char *path; int portability; @@ -322,7 +323,7 @@ validate_path (path, portability) return 0; } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/printf.c b/src/printf.c index 99f5f6b..a9979a6 100644 --- a/src/printf.c +++ b/src/printf.c @@ -59,16 +59,17 @@ unsigned long strtoul (); #define octtobin(c) ((c) - '0') char *xmalloc (); -double xstrtod (); -int print_esc (); -int print_formatted (); -long xstrtol (); -unsigned long xstrtoul (); void error (); -void print_direc (); -void print_esc_char (); -void print_esc_string (); -void verify (); + +static double xstrtod (); +static int print_esc (); +static int print_formatted (); +static long xstrtol (); +static unsigned long xstrtoul (); +static void print_direc (); +static void print_esc_char (); +static void print_esc_string (); +static void verify (); /* The name this program was run with. */ char *program_name; @@ -112,7 +113,7 @@ main (argc, argv) arguments to any `%' directives. Return the number of elements of ARGV used. */ -int +static int print_formatted (format, argc, argv) char *format; int argc; @@ -232,7 +233,7 @@ print_formatted (format, argc, argv) Return the number of characters in the escape sequence besides the backslash. */ -int +static int print_esc (escstart) char *escstart; { @@ -268,7 +269,7 @@ print_esc (escstart) /* Output a single-character \ escape. */ -void +static void print_esc_char (c) char c; { @@ -306,7 +307,7 @@ print_esc_char (c) /* Print string STR, evaluating \ escapes. */ -void +static void print_esc_string (str) char *str; { @@ -322,7 +323,7 @@ print_esc_string (str) If FIELD_WIDTH or PRECISION is non-negative, they are args for '*' values in those fields. */ -void +static void print_direc (start, length, field_width, precision, argument) char *start; int length; @@ -422,7 +423,7 @@ print_direc (start, length, field_width, precision, argument) free (p); } -unsigned long +static unsigned long xstrtoul (s) char *s; { @@ -435,7 +436,7 @@ xstrtoul (s) return val; } -long +static long xstrtol (s) char *s; { @@ -448,7 +449,7 @@ xstrtol (s) return val; } -double +static double xstrtod (s) char *s; { @@ -461,7 +462,7 @@ xstrtod (s) return val; } -void +static void verify (s, end) char *s, *end; { diff --git a/src/sleep.c b/src/sleep.c index 7212ba5..1551eea 100644 --- a/src/sleep.c +++ b/src/sleep.c @@ -19,9 +19,10 @@ #include #include "system.h" -long argdecode (); void error (); +static long argdecode (); + /* The name by which this program was run. */ char *program_name; @@ -49,7 +50,7 @@ main (argc, argv) exit (0); } -long +static long argdecode (s) char *s; { diff --git a/src/su.c b/src/su.c index d118f4a..bc33f15 100644 --- a/src/su.c +++ b/src/su.c @@ -77,7 +77,7 @@ #ifdef HAVE_SYSLOG_H #include -void log_su (); +static void log_su (); #else #ifdef SYSLOG_SUCCESS #undef SYSLOG_SUCCESS @@ -134,18 +134,19 @@ void endusershell (); void setusershell (); char *basename (); -char *concat (); char *xmalloc (); char *xrealloc (); -int correct_password (); -int elements (); -int restricted_shell (); -void change_identity (); void error (); -void modify_environment (); -void run_shell (); -void usage (); -void xputenv (); + +static char *concat (); +static int correct_password (); +static int elements (); +static int restricted_shell (); +static void change_identity (); +static void modify_environment (); +static void run_shell (); +static void usage (); +static void xputenv (); extern char **environ; @@ -161,7 +162,7 @@ static int simulate_login; /* If nonzero, change some environment vars to indicate the user su'd to. */ static int change_environment; -static struct option longopts[] = +static struct option const longopts[] = { {"command", 1, 0, 'c'}, {"fast", 0, &fast_startup, 1}, @@ -272,7 +273,7 @@ main (argc, argv) 0 if not. Return 1 without asking for a password if run by UID 0 or if PW has an empty password. */ -int +static int correct_password (pw) struct passwd *pw; { @@ -300,7 +301,7 @@ correct_password (pw) /* Update `environ' for the new shell based on PW, with SHELL being the value for the SHELL environment variable. */ -void +static void modify_environment (pw, shell) struct passwd *pw; char *shell; @@ -342,7 +343,7 @@ modify_environment (pw, shell) /* Become the user and group(s) specified by PW. */ -void +static void change_identity (pw) struct passwd *pw; { @@ -363,7 +364,7 @@ change_identity (pw) If ADDITIONAL_ARGS is nonzero, pass it to the shell as more arguments. */ -void +static void run_shell (shell, command, additional_args) char *shell; char *command; @@ -404,7 +405,7 @@ run_shell (shell, command, additional_args) /* Log the fact that someone has run su to the user given by PW; if SUCCESSFUL is nonzero, they gave the correct password, etc. */ -void +static void log_su (pw, successful) struct passwd *pw; int successful; @@ -448,14 +449,14 @@ log_su (pw, successful) /* Return 1 if SHELL is a restricted shell (one not returned by getusershell), else 0, meaning it is a standard shell. */ -int +static int restricted_shell (shell) char *shell; { char *line; setusershell (); - while (line = getusershell ()) + while ((line = getusershell ()) != NULL) { if (*line != '#' && strcmp (line, shell) == 0) { @@ -469,7 +470,7 @@ restricted_shell (shell) /* Return the number of elements in ARR, a null-terminated array. */ -int +static int elements (arr) char **arr; { @@ -482,7 +483,7 @@ elements (arr) /* Add VAL to the environment, checking for out of memory errors. */ -void +static void xputenv (val) char *val; { @@ -493,7 +494,7 @@ xputenv (val) /* Return a newly-allocated string whose contents concatenate those of S1, S2, S3. */ -char * +static char * concat (s1, s2, s3) char *s1, *s2, *s3; { @@ -508,7 +509,7 @@ concat (s1, s2, s3) return result; } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/tee.c b/src/tee.c index ca8f53a..b06afa8 100644 --- a/src/tee.c +++ b/src/tee.c @@ -24,10 +24,11 @@ #include "system.h" char *xmalloc (); -int tee (); void error (); void xwrite (); +static int tee (); + /* If nonzero, append to output files rather than truncating them. */ static int append; @@ -37,7 +38,7 @@ static int ignore_interrupts; /* The name that this program was run with. */ char *program_name; -static struct option long_options[] = +static struct option const long_options[] = { {"append", 0, NULL, 'a'}, {"ignore-interrupts", 0, NULL, 'i'}, @@ -101,7 +102,7 @@ Usage: %s [-ai] [--append] [--ignore-interrupts] [file...]\n", and into the standard output. Return 0 if successful, 1 if any errors occur. */ -int +static int tee (nfiles, files) int nfiles; char **files; diff --git a/src/test.c b/src/test.c index a78af09..0bc44e5 100644 --- a/src/test.c +++ b/src/test.c @@ -133,6 +133,8 @@ static int term (); static int and (); static int or (); +static int group_member (); + static void test_syntax_error (format, arg) char *format, *arg; @@ -165,7 +167,6 @@ eaccess (path, mode) char *path; int mode; { - extern int group_member (); struct stat st; static int euid = -1; @@ -206,7 +207,7 @@ static int default_group_array_size = 0; #endif /* HAVE_GETGROUPS */ /* Return non-zero if GID is one that we have in our groups list. */ -int +static int group_member (gid) gid_t gid; { diff --git a/src/tty.c b/src/tty.c index 8396aa9..7549149 100644 --- a/src/tty.c +++ b/src/tty.c @@ -26,7 +26,7 @@ #include #include "system.h" -void usage (); +static void usage (); /* The name under which this program was run. */ char *program_name; @@ -34,7 +34,7 @@ char *program_name; /* If nonzero, return an exit status but produce no output. */ static int silent; -static struct option longopts[] = +static struct option const longopts[] = { {"silent", 0, NULL, 's'}, {"quiet", 0, NULL, 's'}, @@ -79,7 +79,7 @@ main (argc, argv) exit (tty == NULL); } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/uname.c b/src/uname.c index 4b7a6f5..5ddd631 100644 --- a/src/uname.c +++ b/src/uname.c @@ -35,8 +35,9 @@ #include "system.h" void error (); -void print_element (); -void usage (); + +static void print_element (); +static void usage (); /* Values that are bitwise or'd into `toprint'. */ /* Operating system name. */ @@ -60,7 +61,7 @@ static unsigned char toprint; /* The name this program was run with, for error messages. */ char *program_name; -static struct option long_options[] = +static struct option const long_options[] = { {"sysname", 0, NULL, 's'}, {"nodename", 0, NULL, 'n'}, @@ -133,7 +134,7 @@ main (argc, argv) print ELEMENT; then print a space unless it is the last element to be printed, in which case print a newline. */ -void +static void print_element (mask, element) unsigned char mask; char *element; @@ -145,7 +146,7 @@ print_element (mask, element) } } -void +static void usage () { fprintf (stderr, "\ diff --git a/src/who.c b/src/who.c index 0612b6d..aa90c02 100644 --- a/src/who.c +++ b/src/who.c @@ -56,19 +56,21 @@ #define MESG_BIT 020 /* Group write bit. */ -char *ttyname (); char *idle_string (); char *xmalloc (); -struct utmp *search_entries (); void error (); -void list_entries (); -void print_entry (); -void print_heading (); -void scan_entries (); -void usage (); -void who (); -void who_am_i (); + + +static char *ttyname (); +static struct utmp *search_entries (); +static void list_entries (); +static void print_entry (); +static void print_heading (); +static void scan_entries (); +static void usage (); +static void who (); +static void who_am_i (); /* The name this program was run with. */ char *program_name; @@ -90,7 +92,7 @@ static int include_heading; or a `?' if their tty cannot be statted. */ static int include_mesg; -static struct option longopts[] = +static struct option const longopts[] = { {"count", 0, NULL, 'q'}, {"idle", 0, NULL, 'u'}, @@ -180,7 +182,7 @@ static struct utmp *utmp_contents; /* Display a list of who is on the system, according to utmp file FILENAME. */ -void +static void who (filename) char *filename; { @@ -196,7 +198,7 @@ who (filename) /* Read the utmp file FILENAME into UTMP_CONTENTS and return the number of entries it contains. */ -int +static int read_utmp (filename) char *filename; { @@ -228,7 +230,7 @@ read_utmp (filename) /* Display a line of information about entry THIS. */ -void +static void print_entry (this) struct utmp *this; { @@ -277,7 +279,7 @@ print_entry (this) /* Print the username of each valid entry and the number of valid entries in `utmp_contents', which should have N elements. */ -void +static void list_entries (n) int n; { @@ -300,7 +302,7 @@ list_entries (n) printf ("\n# users=%u\n", entries); } -void +static void print_heading () { struct utmp *ut; @@ -317,7 +319,7 @@ print_heading () /* Display `utmp_contents', which should have N entries. */ -void +static void scan_entries (n) int n; { @@ -343,7 +345,7 @@ scan_entries (n) Return the first matching entry found, or NULL if there is no matching entry. */ -struct utmp * +static struct utmp * search_entries (n, line) int n; char *line; @@ -366,7 +368,7 @@ search_entries (n, line) /* Display the entry in utmp file FILENAME for this tty on standard input, or nothing if there is no entry for it. */ -void +static void who_am_i (filename) char *filename; { @@ -399,7 +401,7 @@ who_am_i (filename) /* Return a string representing the time between WHEN and the time that this function is first run. */ -char * +static char * idle_string (when) time_t when; { @@ -423,7 +425,7 @@ idle_string (when) return " old "; } -void +static void usage () { fprintf (stderr, "\ -- 2.7.4