Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 Oct 2011 08:59:17 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r226961 - in head/bin: cat ln mkdir mv rm test
Message-ID:  <201110310859.p9V8xHSr007401@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Mon Oct 31 08:59:17 2011
New Revision: 226961
URL: http://svn.freebsd.org/changeset/base/226961

Log:
  Put some static keywords in the source code.
  
  For these simple utilities, it doesn't harm to make all global variables
  static. In fact, this allows the compiler to perform better forms of
  optimisation and analysis.

Modified:
  head/bin/cat/cat.c
  head/bin/ln/ln.c
  head/bin/mkdir/mkdir.c
  head/bin/mv/mv.c
  head/bin/rm/rm.c
  head/bin/test/test.c

Modified: head/bin/cat/cat.c
==============================================================================
--- head/bin/cat/cat.c	Mon Oct 31 08:48:27 2011	(r226960)
+++ head/bin/cat/cat.c	Mon Oct 31 08:59:17 2011	(r226961)
@@ -64,9 +64,9 @@ __FBSDID("$FreeBSD$");
 #include <unistd.h>
 #include <stddef.h>
 
-int bflag, eflag, nflag, sflag, tflag, vflag;
-int rval;
-const char *filename;
+static int bflag, eflag, nflag, sflag, tflag, vflag;
+static int rval;
+static const char *filename;
 
 static void usage(void);
 static void scanfiles(char *argv[], int cooked);

Modified: head/bin/ln/ln.c
==============================================================================
--- head/bin/ln/ln.c	Mon Oct 31 08:48:27 2011	(r226960)
+++ head/bin/ln/ln.c	Mon Oct 31 08:59:17 2011	(r226961)
@@ -54,16 +54,16 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
-int	fflag;				/* Unlink existing files. */
-int	Fflag;				/* Remove empty directories also. */
-int	hflag;				/* Check new name for symlink first. */
-int	iflag;				/* Interactive mode. */
-int	Pflag;				/* Create hard links to symlinks. */
-int	sflag;				/* Symbolic, not hard, link. */
-int	vflag;				/* Verbose output. */
-int	wflag;				/* Warn if symlink target does not
+static int	fflag;			/* Unlink existing files. */
+static int	Fflag;			/* Remove empty directories also. */
+static int	hflag;			/* Check new name for symlink first. */
+static int	iflag;			/* Interactive mode. */
+static int	Pflag;			/* Create hard links to symlinks. */
+static int	sflag;			/* Symbolic, not hard, link. */
+static int	vflag;			/* Verbose output. */
+static int	wflag;			/* Warn if symlink target does not
 					 * exist, and -f is not enabled. */
-char	linkch;
+static char	linkch;
 
 int	linkit(const char *, const char *, int);
 void	usage(void);

Modified: head/bin/mkdir/mkdir.c
==============================================================================
--- head/bin/mkdir/mkdir.c	Mon Oct 31 08:48:27 2011	(r226960)
+++ head/bin/mkdir/mkdir.c	Mon Oct 31 08:59:17 2011	(r226961)
@@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$");
 static int	build(char *, mode_t);
 static void	usage(void);
 
-int vflag;
+static int	vflag;
 
 int
 main(int argc, char *argv[])

Modified: head/bin/mv/mv.c
==============================================================================
--- head/bin/mv/mv.c	Mon Oct 31 08:48:27 2011	(r226960)
+++ head/bin/mv/mv.c	Mon Oct 31 08:59:17 2011	(r226961)
@@ -68,7 +68,7 @@ __FBSDID("$FreeBSD$");
 /* Exit code for a failed exec. */
 #define EXEC_FAILED 127
 
-int fflg, iflg, nflg, vflg;
+static int	fflg, iflg, nflg, vflg;
 
 static int	copy(const char *, const char *);
 static int	do_move(const char *, const char *);

Modified: head/bin/rm/rm.c
==============================================================================
--- head/bin/rm/rm.c	Mon Oct 31 08:48:27 2011	(r226960)
+++ head/bin/rm/rm.c	Mon Oct 31 08:59:17 2011	(r226961)
@@ -57,10 +57,10 @@ __FBSDID("$FreeBSD$");
 #include <sysexits.h>
 #include <unistd.h>
 
-int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
-int rflag, Iflag;
-uid_t uid;
-volatile sig_atomic_t info;
+static int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
+static int rflag, Iflag;
+static uid_t uid;
+static volatile sig_atomic_t info;
 
 int	check(char *, char *, struct stat *);
 int	check2(char **);

Modified: head/bin/test/test.c
==============================================================================
--- head/bin/test/test.c	Mon Oct 31 08:48:27 2011	(r226960)
+++ head/bin/test/test.c	Mon Oct 31 08:59:17 2011	(r226961)
@@ -118,7 +118,7 @@ enum token_types {
 	PAREN
 };
 
-struct t_op {
+static struct t_op {
 	const char *op_text;
 	short op_num, op_type;
 } const ops [] = {
@@ -165,10 +165,10 @@ struct t_op {
 	{0,	0,	0}
 };
 
-struct t_op const *t_wp_op;
-int nargc;
-char **t_wp;
-int parenlevel;
+static struct t_op const *t_wp_op;
+static int nargc;
+static char **t_wp;
+static int parenlevel;
 
 static int	aexpr(enum token);
 static int	binop(void);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110310859.p9V8xHSr007401>