[BusyBox] #define -> static const int

Mark Whitley markw at lineo.com
Fri Jan 5 22:19:11 UTC 2001


Fellow Busyboxers,

I just devoted some time to changing numerous occurrances of #define'ed
integer symbols to 'static const ints'. At first, I thought this was a little
anal retentive of me, but encouraged by the slogan "An engineer is someone who
can't leave well-enough alone", I pressed on.

More seriously, I thought that going through this exersize would help reduce
the size of the busybox bss segment. I was not dissapointed. Here are some
hard numbers:


$ size busybox-orig 
   text    data     bss     dec     hex filename
 236189   29652   65848  331689   50fa9 busybox-orig
$ size busybox      
   text    data     bss     dec     hex filename
 237293   29652   39960  306905   4aed9 busybox


Nice, eh?


One of the first things I found is that the compiler doesn't like it when you
do something like:

	static const int ARYSIZE = 1024;
	static int ary[ARYSIZE]; /* compiler barfs here */

So, I turned a lot of these into:

	static const int ARYSIZE = 1024;
	static int *ary;

	/* ... somewhere near the beginning of applet_main() ... */
	ary = xmalloc(sizeof(int)*ARYSIZE);

Turning a lot of those dynamic buffers into static buffers helped to reduce
the bss size with only a small penalty in the text size. It also means that we
pay the memory penalty for that static buffer only when that particular applet
is invoked, rather than all the time.

I'm sure there's more of this kind of thing that could be swatted, but I got
the big, obvious ones.


I also learned that the variables declared with an 'enum' are more "constant"
than a variable declared 'const' - at least, that's what the compiler
believes. (I think it's a bug.) The compiler typically complained in switch
statments. Example:

	switch (foo) {

		case CONST_VAL:
			/* compiler chokes if CONST_VAL is declared 'static const int',
			 * but has no problem if it is declared 'enum', go figure.
			 */

So, where I couldn't const-ify things, I enumed them. So there.


The only files I didn't touch were gzip.c and mkfs_minix.c because they were a
little too convoluted and will need some more intensive work.


Attached is the (humongous) patch of my const-ification. It is diff'ed with
the current CVS. I have performed all the tests that are currently in the
tests/ directory, but those are kinda skimpy / buggy right now and I'd like
this to be tested more thoroughly before I even think about committing it to
CVS. So please, somebody, apply this patch, test it out on your system, and
see if anything breaks horribly.


Excelsior!

Mark Whitley
markw at lineo.com
-------------- next part --------------
Index: chvt.c
===================================================================
RCS file: /var/cvs/busybox/chvt.c,v
retrieving revision 1.13
diff -u -b -B -p -r1.13 chvt.c
--- chvt.c	2000/12/14 05:44:36	1.13
+++ chvt.c	2001/01/05 21:51:06
@@ -12,8 +12,8 @@
 #include <sys/ioctl.h>
 
 /* From <linux/vt.h> */
-#define VT_ACTIVATE     0x5606  /* make vt active */
-#define VT_WAITACTIVE   0x5607  /* wait for vt active */
+static const int VT_ACTIVATE = 0x5606;  /* make vt active */
+static const int VT_WAITACTIVE = 0x5607;  /* wait for vt active */
 
 int chvt_main(int argc, char **argv)
 {
Index: cmdedit.c
===================================================================
RCS file: /var/cvs/busybox/cmdedit.c,v
retrieving revision 1.27
diff -u -b -B -p -r1.27 cmdedit.c
--- cmdedit.c	2001/01/04 11:08:45	1.27
+++ cmdedit.c	2001/01/05 21:51:06
@@ -44,10 +44,13 @@
 #include <signal.h>
 
 
-#define  MAX_HISTORY   15		/* Maximum length of the linked list for the command line history */
+static const int MAX_HISTORY = 15;		/* Maximum length of the linked list for the command line history */
 
-#define ESC	27
-#define DEL	127
+enum {
+	ESC = 27,
+	DEL = 127,
+};
+
 #define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
 
Index: cp_mv.c
===================================================================
RCS file: /var/cvs/busybox/cp_mv.c,v
retrieving revision 1.26
diff -u -b -B -p -r1.26 cp_mv.c
--- cp_mv.c	2000/12/18 03:57:16	1.26
+++ cp_mv.c	2001/01/05 21:51:06
@@ -43,8 +43,8 @@
 #include <errno.h>
 #include <getopt.h>
 
-#define is_cp 0
-#define is_mv 1
+static const int is_cp = 0;
+static const int is_mv = 1;
 static int         dz_i;		/* index into cp_mv_usage */
 
 static const char *cp_mv_usage[] =	/* .rodata */
@@ -62,7 +62,7 @@ static const char *baseSrcName;
 static int		   srcDirFlag;
 static struct stat srcStatBuf;
 
-static char		   baseDestName[BUFSIZ + 1];
+static char		   *baseDestName;
 static size_t	   baseDestLen;
 static int		   destDirFlag;
 static struct stat destStatBuf;
@@ -182,6 +182,9 @@ extern int cp_mv_main(int argc, char **a
 		dz_i = is_mv;
 	if (argc < 3)
 		usage(cp_mv_usage[dz_i]);
+
+	/* better than declaring a big static buffer */
+	baseDestName = xmalloc(sizeof(char)*(BUFSIZ + 1)); 
 
 	if (dz_i == is_cp) {
 		recursiveFlag = preserveFlag = forceFlag = FALSE;
Index: deallocvt.c
===================================================================
RCS file: /var/cvs/busybox/deallocvt.c,v
retrieving revision 1.19
diff -u -b -B -p -r1.19 deallocvt.c
--- deallocvt.c	2000/12/22 01:48:07	1.19
+++ deallocvt.c	2001/01/05 21:51:06
@@ -11,7 +11,7 @@
 #include <sys/ioctl.h>
 
 /* From <linux/vt.h> */
-#define VT_DISALLOCATE  0x5608  /* free memory associated to vt */
+static const int VT_DISALLOCATE = 0x5608;  /* free memory associated to vt */
 
 int deallocvt_main(int argc, char *argv[])
 {
Index: dumpkmap.c
===================================================================
RCS file: /var/cvs/busybox/dumpkmap.c,v
retrieving revision 1.8
diff -u -b -B -p -r1.8 dumpkmap.c
--- dumpkmap.c	2000/12/18 03:57:16	1.8
+++ dumpkmap.c	2001/01/05 21:51:06
@@ -32,11 +32,11 @@ struct kbentry {
 	unsigned char kb_index;
 	unsigned short kb_value;
 };
-#define KDGKBENT        0x4B46  /* gets one entry in translation table */
+static const int KDGKBENT = 0x4B46;  /* gets one entry in translation table */
 
 /* From <linux/keyboard.h> */
-#define NR_KEYS         128
-#define MAX_NR_KEYMAPS  256
+static const int NR_KEYS = 128;
+static const int MAX_NR_KEYMAPS = 256;
 
 int dumpkmap_main(int argc, char **argv)
 {
Index: fbset.c
===================================================================
RCS file: /var/cvs/busybox/fbset.c,v
retrieving revision 1.18
diff -u -b -B -p -r1.18 fbset.c
--- fbset.c	2000/12/22 01:48:07	1.18
+++ fbset.c	2001/01/05 21:51:06
@@ -36,53 +36,55 @@
 #define DEFAULTFBDEV  "/dev/fb0"
 #define DEFAULTFBMODE "/etc/fb.modes"
 
-#define OPT_CHANGE    1
-#define OPT_INFO      (1 << 1)
-#define OPT_READMODE  (1 << 2)
-
-#define CMD_HELP        0
-#define CMD_FB		1
-#define CMD_DB		2
-#define CMD_GEOMETRY	3
-#define CMD_TIMING	4
-#define CMD_ACCEL	5
-#define CMD_HSYNC	6
-#define CMD_VSYNC	7
-#define CMD_LACED	8
-#define CMD_DOUBLE	9
-/* #define CMD_XCOMPAT     10 */
-#define CMD_ALL         11
-#define CMD_INFO        12
-#define CMD_CHANGE      13
+static const int OPT_CHANGE   = (1 << 0);
+static const int OPT_INFO     = (1 << 1);
+static const int OPT_READMODE = (1 << 2);
+
+enum {
+	CMD_HELP = 0,
+	CMD_FB = 1,
+	CMD_DB = 2,
+	CMD_GEOMETRY = 3,
+	CMD_TIMING = 4,
+	CMD_ACCEL = 5,
+	CMD_HSYNC = 6,
+	CMD_VSYNC = 7,
+	CMD_LACED = 8,
+	CMD_DOUBLE = 9,
+/* 	CMD_XCOMPAT =     10, */
+	CMD_ALL = 11,
+	CMD_INFO = 12,
+	CMD_CHANGE = 13,
 
 #ifdef BB_FEATURE_FBSET_FANCY
-#define CMD_XRES	100
-#define CMD_YRES	101
-#define CMD_VXRES	102
-#define CMD_VYRES	103
-#define CMD_DEPTH	104
-#define CMD_MATCH	105
-#define CMD_PIXCLOCK	106
-#define CMD_LEFT	107
-#define CMD_RIGHT	108
-#define CMD_UPPER	109
-#define CMD_LOWER	110
-#define CMD_HSLEN	111
-#define CMD_VSLEN	112
-#define CMD_CSYNC	113
-#define CMD_GSYNC	114
-#define CMD_EXTSYNC	115
-#define CMD_BCAST	116
-#define CMD_RGBA	117
-#define CMD_STEP	118
-#define CMD_MOVE	119
+	CMD_XRES = 100,
+	CMD_YRES = 101,
+	CMD_VXRES = 102,
+	CMD_VYRES = 103,
+	CMD_DEPTH = 104,
+	CMD_MATCH = 105,
+	CMD_PIXCLOCK = 106,
+	CMD_LEFT = 107,
+	CMD_RIGHT = 108,
+	CMD_UPPER = 109,
+	CMD_LOWER = 110,
+	CMD_HSLEN = 111,
+	CMD_VSLEN = 112,
+	CMD_CSYNC = 113,
+	CMD_GSYNC = 114,
+	CMD_EXTSYNC = 115,
+	CMD_BCAST = 116,
+	CMD_RGBA = 117,
+	CMD_STEP = 118,
+	CMD_MOVE = 119,
 #endif
+};
 
 static unsigned int g_options = 0;
 
 /* Stuff stolen from the kernel's fb.h */
-#define FBIOGET_VSCREENINFO     0x4600
-#define FBIOPUT_VSCREENINFO     0x4601
+static const int FBIOGET_VSCREENINFO = 0x4600;
+static const int FBIOPUT_VSCREENINFO = 0x4601;
 #define __u32			unsigned int
 struct fb_bitfield {
 	__u32 offset;			/* beginning of bitfield	*/
@@ -180,12 +182,12 @@ struct cmdoptions_t {
 
 #ifdef BB_FEATURE_FBSET_READMODE
 /* taken from linux/fb.h */
-#define FB_VMODE_INTERLACED	1	/* interlaced	*/
-#define FB_VMODE_DOUBLE		2	/* double scan */
-#define FB_SYNC_HOR_HIGH_ACT	1	/* horizontal sync high active	*/
-#define FB_SYNC_VERT_HIGH_ACT	2	/* vertical sync high active	*/
-#define FB_SYNC_EXT		4	/* external sync		*/
-#define FB_SYNC_COMP_HIGH_ACT	8	/* composite sync high active   */
+static const int FB_VMODE_INTERLACED = 1;	/* interlaced	*/
+static const int FB_VMODE_DOUBLE = 2;	/* double scan */
+static const int FB_SYNC_HOR_HIGH_ACT = 1;	/* horizontal sync high active	*/
+static const int FB_SYNC_VERT_HIGH_ACT = 2;	/* vertical sync high active	*/
+static const int FB_SYNC_EXT = 4;	/* external sync		*/
+static const int FB_SYNC_COMP_HIGH_ACT = 8;	/* composite sync high active   */
 #endif
 static int readmode(struct fb_var_screeninfo *base, const char *fn,
 					const char *mode)
Index: fsck_minix.c
===================================================================
RCS file: /var/cvs/busybox/fsck_minix.c,v
retrieving revision 1.27
diff -u -b -B -p -r1.27 fsck_minix.c
--- fsck_minix.c	2000/12/12 23:51:43	1.27
+++ fsck_minix.c	2001/01/05 21:51:06
@@ -104,24 +104,24 @@ typedef unsigned short u16;
 typedef unsigned int u32;
 
 
-#define MINIX_ROOT_INO 1
-#define MINIX_LINK_MAX	250
-#define MINIX2_LINK_MAX	65530
-
-#define MINIX_I_MAP_SLOTS	8
-#define MINIX_Z_MAP_SLOTS	64
-#define MINIX_SUPER_MAGIC	0x137F		/* original minix fs */
-#define MINIX_SUPER_MAGIC2	0x138F		/* minix fs, 30 char names */
-#define MINIX2_SUPER_MAGIC	0x2468		/* minix V2 fs */
-#define MINIX2_SUPER_MAGIC2	0x2478		/* minix V2 fs, 30 char names */
-#define MINIX_VALID_FS		0x0001		/* Clean fs. */
-#define MINIX_ERROR_FS		0x0002		/* fs has errors. */
+static const int MINIX_ROOT_INO = 1;
+static const int MINIX_LINK_MAX = 250;
+static const int MINIX2_LINK_MAX = 65530;
+
+static const int MINIX_I_MAP_SLOTS = 8;
+static const int MINIX_Z_MAP_SLOTS = 64;
+static const int MINIX_SUPER_MAGIC = 0x137F;		/* original minix fs */
+static const int MINIX_SUPER_MAGIC2 = 0x138F;		/* minix fs, 30 char names */
+static const int MINIX2_SUPER_MAGIC = 0x2468;		/* minix V2 fs */
+static const int MINIX2_SUPER_MAGIC2 = 0x2478;		/* minix V2 fs, 30 char names */
+static const int MINIX_VALID_FS = 0x0001;		/* Clean fs. */
+static const int MINIX_ERROR_FS = 0x0002;		/* fs has errors. */
 
 #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
 #define MINIX2_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix2_inode)))
 
-#define MINIX_V1		0x0001		/* original minix fs */
-#define MINIX_V2		0x0002		/* minix V2 fs */
+static const int MINIX_V1 = 0x0001;		/* original minix fs */
+static const int MINIX_V2 = 0x0002;		/* minix V2 fs */
 
 #define INODE_VERSION(inode)	inode->i_sb->u.minix_sb.s_version
 
@@ -185,12 +185,6 @@ struct minix_dir_entry {
 
 #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
 
-#define MINIX_VALID_FS               0x0001          /* Clean fs. */
-#define MINIX_ERROR_FS               0x0002          /* fs has errors. */
-
-#define MINIX_SUPER_MAGIC    0x137F          /* original minix fs */
-#define MINIX_SUPER_MAGIC2   0x138F          /* minix fs, 30 char names */
-
 #ifndef BLKGETSIZE
 #define BLKGETSIZE _IO(0x12,96)    /* return device size */
 #endif
@@ -199,7 +193,7 @@ struct minix_dir_entry {
 #define volatile
 #endif
 
-#define ROOT_INO 1
+static const int ROOT_INO = 1;
 
 #define UPPER(size,n) ((size+((n)-1))/(n))
 #define INODE_SIZE (sizeof(struct minix_inode))
@@ -231,7 +225,7 @@ static struct termios termios;
 static int termios_set = 0;
 
 /* File-name data */
-#define MAX_DEPTH 32
+static const int MAX_DEPTH = 32;
 static int name_depth = 0;
 // static char name_list[MAX_DEPTH][BUFSIZ + 1];
 static char **name_list = NULL;
Index: getopt.c
===================================================================
RCS file: /var/cvs/busybox/getopt.c,v
retrieving revision 1.4
diff -u -b -B -p -r1.4 getopt.c
--- getopt.c	2000/12/07 19:56:48	1.4
+++ getopt.c	2001/01/05 21:51:06
@@ -53,9 +53,9 @@
 
 /* NON_OPT is the code that is returned when a non-option is found in '+'
    mode */
-#define NON_OPT 1
+static const int NON_OPT = 1;
 /* LONG_OPT is the code that is returned when a long option is found. */
-#define LONG_OPT 2
+static const int LONG_OPT = 2;
 
 /* The shells recognized. */
 typedef enum {BASH,TCSH} shell_t;
@@ -199,7 +199,7 @@ int generate_output(char * argv[],int ar
 static struct option *long_options=NULL;
 static int long_options_length=0; /* Length of array */
 static int long_options_nr=0; /* Nr of used elements in array */
-#define LONG_OPTIONS_INCR 10
+static const int LONG_OPTIONS_INCR = 10;
 #define init_longopt() add_longopt(NULL,0)
 
 /* Register a long option. The contents of name is copied. */
Index: gunzip.c
===================================================================
RCS file: /var/cvs/busybox/gunzip.c,v
retrieving revision 1.33
diff -u -b -B -p -r1.33 gunzip.c
--- gunzip.c	2000/12/10 01:57:30	1.33
+++ gunzip.c	2001/01/05 21:51:06
@@ -76,40 +76,40 @@ static char *license_msg[] = {
 #define bb_need_name_too_long
 #include "messages.c"
 
-#define RECORD_IO 0
+static const int RECORD_IO = 0;
 
 /* Return codes from gzip */
-#define OK      0
-#define ERROR   1
-#define WARNING 2
-
-#define DEFLATED     8
-#define INBUFSIZ     0x2000	/* input buffer size */
-#define INBUF_EXTRA  64		/* required by unlzw() */
-#define OUTBUFSIZ    8192	/* output buffer size */
-#define OUTBUF_EXTRA 2048	/* required by unlzw() */
-#define DIST_BUFSIZE 0x2000	/* buffer for distances, see trees.c */
+static const int OK = 0;
+static const int ERROR = 1;
+static const int WARNING = 2;
+
+static const int DEFLATED = 8;
+static const int INBUFSIZ = 0x2000;	/* input buffer size */
+static const int INBUF_EXTRA = 64;		/* required by unlzw() */
+static const int OUTBUFSIZ = 8192;	/* output buffer size */
+static const int OUTBUF_EXTRA = 2048;	/* required by unlzw() */
+static const int DIST_BUFSIZE = 0x2000;	/* buffer for distances, see trees.c */
 
 #define	GZIP_MAGIC  "\037\213"	/* Magic header for gzip files, 1F 8B */
 
 /* gzip flag byte */
-#define EXTRA_FIELD  0x04	/* bit 2 set: extra field present */
-#define ORIG_NAME    0x08	/* bit 3 set: original file name present */
-#define COMMENT      0x10	/* bit 4 set: file comment present */
-#define WSIZE 0x8000		/* window size--must be a power of two, and */
+static const int EXTRA_FIELD = 0x04;	/* bit 2 set: extra field present */
+static const int ORIG_NAME = 0x08;	/* bit 3 set: original file name present */
+static const int COMMENT = 0x10;	/* bit 4 set: file comment present */
+static const int WSIZE = 0x8000;		/* window size--must be a power of two, and */
 				/*  at least 32K for zip's deflate method */
 
 /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
-#define BMAX 16		/* maximum bit length of any code (16 for explode) */
-#define N_MAX 288		/* maximum number of codes in any set */
+static const int BMAX = 16;		/* maximum bit length of any code (16 for explode) */
+static const int N_MAX = 288;		/* maximum number of codes in any set */
 
 /* PKZIP header definitions */
-#define LOCSIG 0x04034b50L	/* four-byte lead-in (lsb first) */
-#define LOCCRC 14		/* offset of crc */
-#define LOCLEN 22		/* offset of uncompressed length */
-#define EXTHDR 16		/* size of extended local header, inc sig */
+static const int LOCSIG = 0x04034b50L;	/* four-byte lead-in (lsb first) */
+static const int LOCCRC = 14;		/* offset of crc */
+static const int LOCLEN = 22;		/* offset of uncompressed length */
+static const int EXTHDR = 16;		/* size of extended local header, inc sig */
 
-#define BITS 16
+static const int BITS = 16;
 
 /* Diagnostic functions */
 #ifdef DEBUG
@@ -132,7 +132,7 @@ static char *license_msg[] = {
 #  ifdef BUFSIZ
 #    define MAX_PATH_LEN   BUFSIZ
 #  else
-#    define MAX_PATH_LEN   1024
+static const int MAX_PATH_LEN = 1024;
 #  endif
 #endif
 
@@ -165,8 +165,8 @@ static ush *tab_prefix1;
 /* local variables */
 static int test_mode = 0;	/* check file integrity option */
 static int foreground;		/* set if program run in foreground */
-static int method = DEFLATED;	/* compression method */
-static int exit_code = OK;	/* program exit code */
+static int method;	/* compression method */
+static int exit_code;	/* program exit code */
 static int last_member;	/* set for .zip and .Z files */
 static int part_nb;		/* number of parts in .gz file */
 static long ifile_size;	/* input file size, -1 for devices (debug only) */
@@ -1224,6 +1224,9 @@ int gunzip_main(int argc, char **argv)
 	char *delFileName;
 	char ifname[MAX_PATH_LEN + 1];	/* input file name */
 	char ofname[MAX_PATH_LEN + 1];	/* output file name */
+
+	method = DEFLATED;	/* default compression method */
+	exit_code = OK;	/* let's go out on a limb and assume everything will run fine (wink wink) */
 
 	if (strcmp(applet_name, "zcat") == 0) {
 		force = 1;
Index: init.c
===================================================================
RCS file: /var/cvs/busybox/init.c,v
retrieving revision 1.108
diff -u -b -B -p -r1.108 init.c
--- init.c	2000/12/13 16:41:29	1.108
+++ init.c	2001/01/05 21:51:06
@@ -56,7 +56,7 @@ struct vt_stat {
 	unsigned short v_signal;        /* signal to send */
 	unsigned short v_state;         /* vt bitmask */
 };
-#define VT_GETSTATE     0x5603  /* get global vt state info */
+static const int VT_GETSTATE = 0x5603;  /* get global vt state info */
 
 /* From <linux/serial.h> */
 struct serial_struct {
@@ -79,11 +79,11 @@ struct serial_struct {
 
 
 #ifndef RB_HALT_SYSTEM
-#define RB_HALT_SYSTEM  0xcdef0123
-#define RB_ENABLE_CAD   0x89abcdef
-#define RB_DISABLE_CAD  0
+static const int RB_HALT_SYSTEM = 0xcdef0123;
+static const int RB_ENABLE_CAD = 0x89abcdef;
+static const int RB_DISABLE_CAD = 0;
 #define RB_POWER_OFF    0x4321fedc
-#define RB_AUTOBOOT     0x01234567
+static const int RB_AUTOBOOT = 0x01234567;
 #if defined(__GLIBC__) || defined (__UCLIBC__)
 #include <sys/reboot.h>
   #define init_reboot(magic) reboot(magic)
@@ -131,8 +131,8 @@ static _syscall2(int, bdflush, int, func
 #define INIT_SCRIPT  "/etc/init.d/rcS"   /* Default sysinit script. */
 #endif
 
-#define LOG     0x1
-#define CONSOLE 0x2
+static const int LOG = 0x1;
+static const int CONSOLE = 0x2;
 
 /* Allowed init action types */
 typedef enum {
Index: insmod.c
===================================================================
RCS file: /var/cvs/busybox/insmod.c,v
retrieving revision 1.35
diff -u -b -B -p -r1.35 insmod.c
--- insmod.c	2001/01/04 02:00:17	1.35
+++ insmod.c	2001/01/05 21:51:06
@@ -76,7 +76,7 @@
 
 
 #ifndef MODUTILS_MODULE_H
-#define MODUTILS_MODULE_H 1
+static const int MODUTILS_MODULE_H = 1;
 
 #ident "$Id: insmod.c,v 1.35 2001/01/04 02:00:17 kraai Exp $"
 
@@ -135,7 +135,7 @@ struct old_module
 };
 
 /* Sent to init_module(2) or'ed into the code size parameter.  */
-#define OLD_MOD_AUTOCLEAN 0x40000000 /* big enough, but no sign problems... */
+static const int OLD_MOD_AUTOCLEAN = 0x40000000; /* big enough, but no sign problems... */
 
 int get_kernel_syms(struct old_kernel_sym *);
 int old_sys_init_module(const char *name, char *code, unsigned codesize,
@@ -158,9 +158,9 @@ int old_sys_init_module(const char *name
 #undef tgt_sizeof_char_p
 #undef tgt_sizeof_void_p
 #undef tgt_long
-#define tgt_sizeof_long		8
-#define tgt_sizeof_char_p	8
-#define tgt_sizeof_void_p	8
+static const int tgt_sizeof_long = 8;
+static const int tgt_sizeof_char_p = 8;
+static const int tgt_sizeof_void_p = 8;
 #define tgt_long		long long
 #endif
 
@@ -222,11 +222,11 @@ struct new_module_info
 };
 
 /* Bits of module.flags.  */
-#define NEW_MOD_RUNNING		1
-#define NEW_MOD_DELETED		2
-#define NEW_MOD_AUTOCLEAN	4
-#define NEW_MOD_VISITED		8
-#define NEW_MOD_USED_ONCE	16
+static const int NEW_MOD_RUNNING = 1;
+static const int NEW_MOD_DELETED = 2;
+static const int NEW_MOD_AUTOCLEAN = 4;
+static const int NEW_MOD_VISITED = 8;
+static const int NEW_MOD_USED_ONCE = 16;
 
 int new_sys_init_module(const char *name, const struct new_module *);
 int query_module(const char *name, int which, void *buf, size_t bufsize,
@@ -234,11 +234,11 @@ int query_module(const char *name, int w
 
 /* Values for query_module's which.  */
 
-#define QM_MODULES	1
-#define QM_DEPS		2
-#define QM_REFS		3
-#define QM_SYMBOLS	4
-#define QM_INFO		5
+static const int QM_MODULES = 1;
+static const int QM_DEPS = 2;
+static const int QM_REFS = 3;
+static const int QM_SYMBOLS = 4;
+static const int QM_INFO = 5;
 
 /*======================================================================*/
 /* The system calls unchanged between 2.0 and 2.1.  */
@@ -282,7 +282,7 @@ int delete_module(const char *);
 
 
 #ifndef MODUTILS_OBJ_H
-#define MODUTILS_OBJ_H 1
+static const int MODUTILS_OBJ_H = 1;
 
 #ident "$Id: insmod.c,v 1.35 2001/01/04 02:00:17 kraai Exp $"
 
@@ -517,7 +517,7 @@ int arch_init_module (struct obj_file *f
 
 
 #define _PATH_MODULES	"/lib/modules"
-#define STRVERSIONLEN	32
+static const int STRVERSIONLEN = 32;
 
 #if !defined(BB_FEATURE_INSMOD_NEW_KERNEL) && !defined(BB_FEATURE_INSMOD_OLD_KERNEL)
 #error "Must have ether BB_FEATURE_INSMOD_NEW_KERNEL or BB_FEATURE_INSMOD_OLD_KERNEL defined"
Index: kill.c
===================================================================
RCS file: /var/cvs/busybox/kill.c,v
retrieving revision 1.29
diff -u -b -B -p -r1.29 kill.c
--- kill.c	2000/12/18 03:57:16	1.29
+++ kill.c	2001/01/05 21:51:06
@@ -30,8 +30,8 @@
 #include <ctype.h>
 #include <unistd.h>
 
-#define KILL	0
-#define KILLALL	1
+static const int KILL = 0;
+static const int KILLALL = 1;
 
 struct signal_name {
 	const char *name;
Index: ln.c
===================================================================
RCS file: /var/cvs/busybox/ln.c,v
retrieving revision 1.30
diff -u -b -B -p -r1.30 ln.c
--- ln.c	2000/12/07 19:56:48	1.30
+++ ln.c	2001/01/05 21:51:06
@@ -30,9 +30,9 @@
 #include <dirent.h>
 #include <errno.h>
 
-#define LN_SYMLINK		1
-#define LN_FORCE			2
-#define LN_NODEREFERENCE	4
+static const int LN_SYMLINK = 1;
+static const int LN_FORCE = 2;
+static const int LN_NODEREFERENCE = 4;
 
 /*
  * linkDestName is where the link points to,
Index: loadfont.c
===================================================================
RCS file: /var/cvs/busybox/loadfont.c,v
retrieving revision 1.14
diff -u -b -B -p -r1.14 loadfont.c
--- loadfont.c	2000/12/07 19:56:48	1.14
+++ loadfont.c	2001/01/05 21:51:06
@@ -21,13 +21,13 @@
 #include <sys/kd.h>
 #include <endian.h>
 
-#define PSF_MAGIC1	0x36
-#define PSF_MAGIC2	0x04
+static const int PSF_MAGIC1 = 0x36;
+static const int PSF_MAGIC2 = 0x04;
 
-#define PSF_MODE512    0x01
-#define PSF_MODEHASTAB 0x02
-#define PSF_MAXMODE    0x03
-#define PSF_SEPARATOR  0xFFFF
+static const int PSF_MODE512 = 0x01;
+static const int PSF_MODEHASTAB = 0x02;
+static const int PSF_MAXMODE = 0x03;
+static const int PSF_SEPARATOR = 0xFFFF;
 
 struct psf_header {
 	unsigned char magic1, magic2;	/* Magic number */
Index: loadkmap.c
===================================================================
RCS file: /var/cvs/busybox/loadkmap.c,v
retrieving revision 1.19
diff -u -b -B -p -r1.19 loadkmap.c
--- loadkmap.c	2000/12/07 19:56:48	1.19
+++ loadkmap.c	2001/01/05 21:51:06
@@ -34,11 +34,11 @@ struct kbentry {
 	unsigned char kb_index;
 	unsigned short kb_value;
 };
-#define KDSKBENT        0x4B47  /* sets one entry in translation table */
+static const int KDSKBENT = 0x4B47;  /* sets one entry in translation table */
 
 /* From <linux/keyboard.h> */
-#define NR_KEYS         128
-#define MAX_NR_KEYMAPS  256
+static const int NR_KEYS = 128;
+static const int MAX_NR_KEYMAPS = 256;
 
 int loadkmap_main(int argc, char **argv)
 {
Index: ls.c
===================================================================
RCS file: /var/cvs/busybox/ls.c,v
retrieving revision 1.49
diff -u -b -B -p -r1.49 ls.c
--- ls.c	2000/12/18 03:57:16	1.49
+++ ls.c	2001/01/05 21:51:06
@@ -41,9 +41,9 @@
  * 1. requires lstat (BSD) - how do you do it without?
  */
 
-#define TERMINAL_WIDTH	80		/* use 79 if your terminal has linefold bug */
-#define COLUMN_WIDTH	14		/* default if AUTOWIDTH not defined */
-#define COLUMN_GAP	2			/* includes the file type char, if present */
+static const int TERMINAL_WIDTH = 80;		/* use 79 if your terminal has linefold bug */
+static const int COLUMN_WIDTH = 14;		/* default if AUTOWIDTH not defined */
+static const int COLUMN_GAP = 2;			/* includes the file type char, if present */
 
 /************************************************************************/
 
@@ -66,10 +66,12 @@
 #endif
 
 /* what is the overall style of the listing */
-#define STYLE_AUTO		0
-#define STYLE_LONG		1		/* one record per line, extended info */
-#define STYLE_SINGLE	2		/* one record per line */
-#define STYLE_COLUMNS	3		/* fill columns */
+enum {
+STYLE_AUTO = 0,
+STYLE_LONG = 1,		/* one record per line, extended info */
+STYLE_SINGLE = 2,		/* one record per line */
+STYLE_COLUMNS = 3		/* fill columns */
+};
 
 /* 51306 lrwxrwxrwx  1 root     root         2 May 11 01:43 /bin/view -> vi* */
 /* what file information will be listed */
@@ -99,23 +101,23 @@
 
 #ifdef BB_FEATURE_LS_SORTFILES
 /* how will the files be sorted */
-#define SORT_FORWARD    0		/* sort in reverse order */
-#define SORT_REVERSE    1		/* sort in reverse order */
-#define SORT_NAME		2		/* sort by file name */
-#define SORT_SIZE		3		/* sort by file size */
-#define SORT_ATIME		4		/* sort by last access time */
-#define SORT_CTIME		5		/* sort by last change time */
-#define SORT_MTIME		6		/* sort by last modification time */
-#define SORT_VERSION	7		/* sort by version */
-#define SORT_EXT		8		/* sort by file name extension */
-#define SORT_DIR		9		/* sort by file or directory */
+static const int SORT_FORWARD = 0;		/* sort in reverse order */
+static const int SORT_REVERSE = 1;		/* sort in reverse order */
+static const int SORT_NAME = 2;		/* sort by file name */
+static const int SORT_SIZE = 3;		/* sort by file size */
+static const int SORT_ATIME = 4;		/* sort by last access time */
+static const int SORT_CTIME = 5;		/* sort by last change time */
+static const int SORT_MTIME = 6;		/* sort by last modification time */
+static const int SORT_VERSION = 7;		/* sort by version */
+static const int SORT_EXT = 8;		/* sort by file name extension */
+static const int SORT_DIR = 9;		/* sort by file or directory */
 #endif
 
 #ifdef BB_FEATURE_LS_TIMESTAMPS
 /* which of the three times will be used */
-#define TIME_MOD    0
-#define TIME_CHANGE 1
-#define TIME_ACCESS 2
+static const int TIME_MOD = 0;
+static const int TIME_CHANGE = 1;
+static const int TIME_ACCESS = 2;
 #endif
 
 #define LIST_SHORT		(LIST_FILENAME)
@@ -125,9 +127,9 @@
 						LIST_SYMLINK)
 #define LIST_ILONG		(LIST_INO | LIST_LONG)
 
-#define SPLIT_DIR		0
-#define SPLIT_FILE		1
-#define SPLIT_SUBDIR	2
+static const int SPLIT_DIR = 0;
+static const int SPLIT_FILE = 1;
+static const int SPLIT_SUBDIR = 2;
 
 #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
 #define TYPECHAR(mode)  ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
@@ -150,15 +152,15 @@ struct dnode **list_dir(char *);
 struct dnode **dnalloc(int);
 int list_single(struct dnode *);
 
-static unsigned int disp_opts=	DISP_NORMAL;
-static unsigned int style_fmt=	STYLE_AUTO ;
-static unsigned int list_fmt=	LIST_SHORT ;
+static unsigned int disp_opts;
+static unsigned int style_fmt;
+static unsigned int list_fmt;
 #ifdef BB_FEATURE_LS_SORTFILES
-static unsigned int sort_opts=	SORT_FORWARD;
-static unsigned int sort_order=	SORT_FORWARD;
+static unsigned int sort_opts;
+static unsigned int sort_order;
 #endif
 #ifdef BB_FEATURE_LS_TIMESTAMPS
-static unsigned int time_fmt=	TIME_MOD;
+static unsigned int time_fmt;
 #endif
 #ifdef BB_FEATURE_LS_FOLLOWLINKS
 static unsigned int follow_links=FALSE;
@@ -166,12 +168,9 @@ static unsigned int follow_links=FALSE;
 
 static unsigned short column = 0;
 #ifdef BB_FEATURE_AUTOWIDTH
-static unsigned short terminal_width = TERMINAL_WIDTH;
-static unsigned short column_width = COLUMN_WIDTH;
-static unsigned short tabstops = 8;
-#else
-#define terminal_width  TERMINAL_WIDTH
-#define column_width    COLUMN_WIDTH
+static unsigned short terminal_width;
+static unsigned short column_width;
+static unsigned short tabstops;
 #endif
 
 static int status = EXIT_SUCCESS;
@@ -698,9 +697,15 @@ extern int ls_main(int argc, char **argv
 	list_fmt=  LIST_SHORT;
 #ifdef BB_FEATURE_LS_SORTFILES
 	sort_opts= SORT_NAME;
+	sort_order=	SORT_FORWARD;
 #endif
 #ifdef BB_FEATURE_LS_TIMESTAMPS
 	time_fmt= TIME_MOD;
+#endif
+#ifdef BB_FEATURE_AUTOWIDTH
+	terminal_width = TERMINAL_WIDTH;
+	column_width = COLUMN_WIDTH;
+	tabstops = 8;
 #endif
 	nfiles=0;
 
Index: lsmod.c
===================================================================
RCS file: /var/cvs/busybox/lsmod.c,v
retrieving revision 1.18
diff -u -b -B -p -r1.18 lsmod.c
--- lsmod.c	2000/12/18 03:08:29	1.18
+++ lsmod.c	2001/01/05 21:51:06
@@ -59,19 +59,19 @@ int query_module(const char *name, int w
 		 size_t *ret);
 
 /* Values for query_module's which.  */
-#define QM_MODULES	1
-#define QM_DEPS		2
-#define QM_REFS		3
-#define QM_SYMBOLS	4
-#define QM_INFO		5
+static const int QM_MODULES = 1;
+static const int QM_DEPS = 2;
+static const int QM_REFS = 3;
+static const int QM_SYMBOLS = 4;
+static const int QM_INFO = 5;
 
 /* Bits of module.flags.  */
-#define NEW_MOD_RUNNING		1
-#define NEW_MOD_DELETED		2
-#define NEW_MOD_AUTOCLEAN	4
-#define NEW_MOD_VISITED		8
-#define NEW_MOD_USED_ONCE	16
-#define NEW_MOD_INITIALIZING	64
+static const int NEW_MOD_RUNNING = 1;
+static const int NEW_MOD_DELETED = 2;
+static const int NEW_MOD_AUTOCLEAN = 4;
+static const int NEW_MOD_VISITED = 8;
+static const int NEW_MOD_USED_ONCE = 16;
+static const int NEW_MOD_INITIALIZING = 64;
 
 
 extern int lsmod_main(int argc, char **argv)
Index: md5sum.c
===================================================================
RCS file: /var/cvs/busybox/md5sum.c,v
retrieving revision 1.13
diff -u -b -B -p -r1.13 md5sum.c
--- md5sum.c	2000/12/20 23:19:42	1.13
+++ md5sum.c	2001/01/05 21:51:06
@@ -91,7 +91,7 @@
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #ifndef _MD5_H
-#define _MD5_H 1
+static const int _MD5_H = 1;
 
 #include <stdio.h>
 
@@ -251,7 +251,7 @@ void *md5_finish_ctx(struct md5_ctx *ctx
 int md5_stream(FILE *stream, void *resblock)
 {
   /* Important: BLOCKSIZE must be a multiple of 64.  */
-#define BLOCKSIZE 4096
+static const int BLOCKSIZE = 4096;
   struct md5_ctx ctx;
   char buffer[BLOCKSIZE + 72];
   size_t sum;
@@ -529,7 +529,7 @@ void md5_process_block(const void *buffe
 /* The minimum length of a valid digest line in a file produced
    by `md5sum FILE' and read by `md5sum -c'.  This length does
    not include any newline character at the end of a line.  */
-#define MIN_DIGEST_LINE_LENGTH 35 /* 32 - message digest length
+static const int MIN_DIGEST_LINE_LENGTH = 35; /* 32 - message digest length
                                       2 - blank and binary indicator
                                       1 - minimum filename length */
 
Index: mkswap.c
===================================================================
RCS file: /var/cvs/busybox/mkswap.c,v
retrieving revision 1.18
diff -u -b -B -p -r1.18 mkswap.c
--- mkswap.c	2000/12/22 01:48:07	1.18
+++ mkswap.c	2001/01/05 21:51:06
@@ -48,7 +48,7 @@
 
 #ifndef _IO
 /* pre-1.3.45 */
-#define BLKGETSIZE 0x1260
+static const int BLKGETSIZE = 0x1260;
 #else
 /* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
 #define BLKGETSIZE _IO(0x12,96)
Index: mount.c
===================================================================
RCS file: /var/cvs/busybox/mount.c,v
retrieving revision 1.58
diff -u -b -B -p -r1.58 mount.c
--- mount.c	2000/12/22 01:48:07	1.58
+++ mount.c	2001/01/05 21:51:06
@@ -55,21 +55,21 @@
 #include <linux/devmtab.h> /* For Erik's nifty devmtab device driver */
 #endif
 
-
-#define MS_MGC_VAL		0xc0ed0000 /* Magic number indicatng "new" flags */
-#define MS_RDONLY        1      /* Mount read-only */
-#define MS_NOSUID        2      /* Ignore suid and sgid bits */
-#define MS_NODEV         4      /* Disallow access to device special files */
-#define MS_NOEXEC        8      /* Disallow program execution */
-#define MS_SYNCHRONOUS  16      /* Writes are synced at once */
-#define MS_REMOUNT      32      /* Alter flags of a mounted FS */
-#define MS_MANDLOCK     64      /* Allow mandatory locks on an FS */
-#define S_QUOTA         128     /* Quota initialized for file/directory/symlink */
-#define S_APPEND        256     /* Append-only file */
-#define S_IMMUTABLE     512     /* Immutable file */
-#define MS_NOATIME      1024    /* Do not update access times. */
-#define MS_NODIRATIME   2048    /* Do not update directory access times */
-
+enum {
+	MS_MGC_VAL = 0xc0ed0000, /* Magic number indicatng "new" flags */
+	MS_RDONLY = 1,      /* Mount read-only */
+	MS_NOSUID = 2,      /* Ignore suid and sgid bits */
+	MS_NODEV = 4,      /* Disallow access to device special files */
+	MS_NOEXEC = 8,      /* Disallow program execution */
+	MS_SYNCHRONOUS = 16,      /* Writes are synced at once */
+	MS_REMOUNT = 32,      /* Alter flags of a mounted FS */
+	MS_MANDLOCK = 64,      /* Allow mandatory locks on an FS */
+	S_QUOTA = 128,     /* Quota initialized for file/directory/symlink */
+	S_APPEND = 256,     /* Append-only file */
+	S_IMMUTABLE = 512,     /* Immutable file */
+	MS_NOATIME = 1024,    /* Do not update access times. */
+	MS_NODIRATIME = 2048,    /* Do not update directory access times */
+};
 
 
 #if defined BB_FEATURE_MOUNT_LOOP
Index: nfsmount.c
===================================================================
RCS file: /var/cvs/busybox/nfsmount.c,v
retrieving revision 1.11
diff -u -b -B -p -r1.11 nfsmount.c
--- nfsmount.c	2001/01/02 01:16:02	1.11
+++ nfsmount.c	2001/01/05 21:51:06
@@ -54,10 +54,10 @@
 #include <linux/nfs.h>  /* For the kernels nfs stuff */
 
 #ifndef NFS_FHSIZE
-#define NFS_FHSIZE	32
+static const int NFS_FHSIZE = 32;
 #endif
 #ifndef NFS_PORT
-#define NFS_PORT	2049
+static const int NFS_PORT = 2049;
 #endif
 
 /* Disable the nls stuff */
@@ -68,19 +68,19 @@
 # define _(Text) (Text)
 # define N_(Text) (Text)
 
-#define MS_MGC_VAL		0xc0ed0000 /* Magic number indicatng "new" flags */
-#define MS_RDONLY        1      /* Mount read-only */
-#define MS_NOSUID        2      /* Ignore suid and sgid bits */
-#define MS_NODEV         4      /* Disallow access to device special files */
-#define MS_NOEXEC        8      /* Disallow program execution */
-#define MS_SYNCHRONOUS  16      /* Writes are synced at once */
-#define MS_REMOUNT      32      /* Alter flags of a mounted FS */
-#define MS_MANDLOCK     64      /* Allow mandatory locks on an FS */
-#define S_QUOTA         128     /* Quota initialized for file/directory/symlink */
-#define S_APPEND        256     /* Append-only file */
-#define S_IMMUTABLE     512     /* Immutable file */
-#define MS_NOATIME      1024    /* Do not update access times. */
-#define MS_NODIRATIME   2048    /* Do not update directory access times */
+static const int MS_MGC_VAL = 0xc0ed0000; /* Magic number indicatng "new" flags */
+static const int MS_RDONLY = 1;      /* Mount read-only */
+static const int MS_NOSUID = 2;      /* Ignore suid and sgid bits */
+static const int MS_NODEV = 4;      /* Disallow access to device special files */
+static const int MS_NOEXEC = 8;      /* Disallow program execution */
+static const int MS_SYNCHRONOUS = 16;      /* Writes are synced at once */
+static const int MS_REMOUNT = 32;      /* Alter flags of a mounted FS */
+static const int MS_MANDLOCK = 64;      /* Allow mandatory locks on an FS */
+static const int S_QUOTA = 128;     /* Quota initialized for file/directory/symlink */
+static const int S_APPEND = 256;     /* Append-only file */
+static const int S_IMMUTABLE = 512;     /* Immutable file */
+static const int MS_NOATIME = 1024;    /* Do not update access times. */
+static const int MS_NODIRATIME = 2048;    /* Do not update directory access times */
 
 
 /*
@@ -93,7 +93,7 @@
  * so it is easiest to ignore the kernel altogether (at compile time).
  */
 
-#define NFS_MOUNT_VERSION	4
+static const int NFS_MOUNT_VERSION = 4;
 
 struct nfs2_fh {
         char                    data[32];
@@ -125,16 +125,16 @@ struct nfs_mount_data {
 
 /* bits in the flags field */
 
-#define NFS_MOUNT_SOFT		0x0001	/* 1 */
-#define NFS_MOUNT_INTR		0x0002	/* 1 */
-#define NFS_MOUNT_SECURE	0x0004	/* 1 */
-#define NFS_MOUNT_POSIX		0x0008	/* 1 */
-#define NFS_MOUNT_NOCTO		0x0010	/* 1 */
-#define NFS_MOUNT_NOAC		0x0020	/* 1 */
-#define NFS_MOUNT_TCP		0x0040	/* 2 */
-#define NFS_MOUNT_VER3		0x0080	/* 3 */
-#define NFS_MOUNT_KERBEROS	0x0100	/* 3 */
-#define NFS_MOUNT_NONLM		0x0200	/* 3 */
+static const int NFS_MOUNT_SOFT = 0x0001;	/* 1 */
+static const int NFS_MOUNT_INTR = 0x0002;	/* 1 */
+static const int NFS_MOUNT_SECURE = 0x0004;	/* 1 */
+static const int NFS_MOUNT_POSIX = 0x0008;	/* 1 */
+static const int NFS_MOUNT_NOCTO = 0x0010;	/* 1 */
+static const int NFS_MOUNT_NOAC = 0x0020;	/* 1 */
+static const int NFS_MOUNT_TCP = 0x0040;	/* 2 */
+static const int NFS_MOUNT_VER3 = 0x0080;	/* 3 */
+static const int NFS_MOUNT_KERBEROS = 0x0100;	/* 3 */
+static const int NFS_MOUNT_NONLM = 0x0200;	/* 3 */
 
 
 #define UTIL_LINUX_VERSION "2.10m"
@@ -160,14 +160,14 @@ static char *nfs_strerror(int stat);
 #define MAKE_VERSION(p,q,r)	(65536*(p) + 256*(q) + (r))
 #define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2)
 
-#define EX_FAIL			32       /* mount failure */
-#define EX_BG			256       /* retry in background (internal only) */
+static const int EX_FAIL = 32;       /* mount failure */
+static const int EX_BG = 256;       /* retry in background (internal only) */
 
 
 /*
  * nfs_mount_version according to the sources seen at compile time.
  */
-int nfs_mount_version = NFS_MOUNT_VERSION;
+int nfs_mount_version;
 
 /*
  * Unfortunately, the kernel prints annoying console messages
@@ -187,8 +187,9 @@ find_kernel_nfs_mount_version(void) {
 	if (kernel_version)
 		return;
 
-	kernel_version = get_kernel_revision();
+	nfs_mount_version = NFS_MOUNT_VERSION; /* default */
 
+	kernel_version = get_kernel_revision();
 	if (kernel_version) {
 	     if (kernel_version < MAKE_VERSION(2,1,32))
 		  nfs_mount_version = 1;
Index: ping.c
===================================================================
RCS file: /var/cvs/busybox/ping.c,v
retrieving revision 1.30
diff -u -b -B -p -r1.30 ping.c
--- ping.c	2000/12/22 01:48:07	1.30
+++ ping.c	2001/01/05 21:51:06
@@ -54,7 +54,7 @@
 #if ! defined __GLIBC__ && ! defined __UCLIBC__
 typedef unsigned int socklen_t;
 
-#define	ICMP_MINLEN	8				/* abs minimum */
+static const int ICMP_MINLEN = 8;				/* abs minimum */
 
 struct icmp_ra_addr
 {
@@ -130,13 +130,13 @@ struct icmp
 };
 #endif
 
-#define DEFDATALEN      56
-#define	MAXIPLEN	60
-#define	MAXICMPLEN	76
-#define	MAXPACKET	65468
+static const int DEFDATALEN = 56;
+static const int MAXIPLEN = 60;
+static const int MAXICMPLEN = 76;
+static const int MAXPACKET = 65468;
 #define	MAX_DUP_CHK	(8 * 128)
-#define MAXWAIT         10
-#define PINGINTERVAL    1		/* second */
+static const int MAXWAIT = 10;
+static const int PINGINTERVAL = 1;		/* second */
 
 #define O_QUIET         (1 << 0)
 
@@ -258,7 +258,7 @@ extern int ping_main(int argc, char **ar
 static char *hostname = NULL;
 static struct sockaddr_in pingaddr;
 static int pingsock = -1;
-static int datalen = DEFDATALEN;
+static int datalen;
 
 static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
 static int myid = 0, options = 0;
@@ -503,6 +503,8 @@ static void ping(const char *host)
 extern int ping_main(int argc, char **argv)
 {
 	char *thisarg;
+
+	datalen = DEFDATALEN; /* default */
 
 	argc--;
 	argv++;
Index: printf.c
===================================================================
RCS file: /var/cvs/busybox/printf.c,v
retrieving revision 1.13
diff -u -b -B -p -r1.13 printf.c
--- printf.c	2000/09/25 21:45:58	1.13
+++ printf.c	2001/01/05 21:51:06
@@ -59,7 +59,7 @@
 
 
 #ifndef S_IFMT
-# define S_IFMT 0170000
+static const int S_IFMT = 0170000;
 #endif
 #if !defined(S_ISBLK) && defined(S_IFBLK)
 # define	S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
Index: ps.c
===================================================================
RCS file: /var/cvs/busybox/ps.c,v
retrieving revision 1.30
diff -u -b -B -p -r1.30 ps.c
--- ps.c	2000/12/18 03:57:16	1.30
+++ ps.c	2001/01/05 21:51:06
@@ -40,7 +40,7 @@
 #define bb_need_help
 #include "messages.c"
 
-#define TERMINAL_WIDTH  79      /* not 80 in case terminal has linefold bug */
+static const int TERMINAL_WIDTH = 79;      /* not 80 in case terminal has linefold bug */
 
 
 
Index: rdate.c
===================================================================
RCS file: /var/cvs/busybox/rdate.c,v
retrieving revision 1.7
diff -u -b -B -p -r1.7 rdate.c
--- rdate.c	2000/12/18 03:57:16	1.7
+++ rdate.c	2001/01/05 21:51:06
@@ -33,7 +33,7 @@
 #include <getopt.h>
 
 
-#define RFC_868_BIAS	2208988800UL
+static const int RFC_868_BIAS = 2208988800UL;
 
 int setdate= 0;
 int printdate= 0;
Index: rpmunpack.c
===================================================================
RCS file: /var/cvs/busybox/rpmunpack.c,v
retrieving revision 1.2
diff -u -b -B -p -r1.2 rpmunpack.c
--- rpmunpack.c	2000/12/22 01:48:07	1.2
+++ rpmunpack.c	2001/01/05 21:51:06
@@ -19,7 +19,7 @@
 /*
  * Some general definitions
  */
-#define BUFSIZE		512
+
 #define RPM_MAGIC	"\355\253\356\333"
 #define GZ_MAGIC_1	'\037'
 #define GZ_MAGIC_2	'\213'
@@ -27,7 +27,7 @@
 /*
  * Global variables
  */
-static char buffer[BUFSIZE];
+static char *buffer;
 static char *progname;
 static int infile, outfile;
 
@@ -53,6 +53,8 @@ int rpmunpack_main(int argc, char **argv
 {
   int len, status = 0;
 
+  buffer = xmalloc(sizeof(char)*BUFSIZ);
+
   /* Get our own program name */
   if ((progname = strrchr(argv[0], '/')) == NULL)
 	progname = argv[0];
@@ -113,7 +115,7 @@ int rpmunpack_main(int argc, char **argv
 	perror_msg_and_die("write");
 
   /* Now simply copy the GZIP archive into the output file */
-  while ((len = read(infile, buffer, BUFSIZE)) > 0) {
+  while ((len = read(infile, buffer, BUFSIZ)) > 0) {
 	if (write(outfile, buffer, len) < 0)
 		perror_msg_and_die("write");
   }
Index: setkeycodes.c
===================================================================
RCS file: /var/cvs/busybox/setkeycodes.c,v
retrieving revision 1.7
diff -u -b -B -p -r1.7 setkeycodes.c
--- setkeycodes.c	2000/12/07 19:56:48	1.7
+++ setkeycodes.c	2001/01/05 21:51:06
@@ -33,7 +33,7 @@
 struct kbkeycode {
 	unsigned int scancode, keycode;
 };
-#define KDSETKEYCODE    0x4B4D  /* write kernel keycode table entry */
+static const int KDSETKEYCODE = 0x4B4D;  /* write kernel keycode table entry */
 
 extern int 
 setkeycodes_main(int argc, char** argv)
Index: sh.c
===================================================================
RCS file: /var/cvs/busybox/sh.c,v
retrieving revision 1.73
diff -u -b -B -p -r1.73 sh.c
--- sh.c	2001/01/05 21:23:44	1.73
+++ sh.c	2001/01/05 21:51:06
@@ -64,8 +64,8 @@
 #include <getopt.h>
 #include "cmdedit.h"
 
-#define MAX_LINE	256	/* size of input buffer for cwd data */
-#define MAX_READ	128	/* size of input buffer for `read' builtin */
+static const int MAX_LINE = 256;	/* size of input buffer for cwd data */
+static const int MAX_READ = 128;	/* size of input buffer for `read' builtin */
 #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
 extern size_t NUM_APPLETS;
 
Index: swaponoff.c
===================================================================
RCS file: /var/cvs/busybox/swaponoff.c,v
retrieving revision 1.19
diff -u -b -B -p -r1.19 swaponoff.c
--- swaponoff.c	2000/12/22 01:48:07	1.19
+++ swaponoff.c	2001/01/05 21:51:06
@@ -35,8 +35,8 @@ _syscall1(int, swapoff, const char *, pa
 
 static int whichApp;
 
-#define SWAPON_APP   1
-#define SWAPOFF_APP  2
+static const int SWAPON_APP = 1;
+static const int SWAPOFF_APP = 2;
 
 
 static void swap_enable_disable(char *device)
Index: syslogd.c
===================================================================
RCS file: /var/cvs/busybox/syslogd.c,v
retrieving revision 1.51
diff -u -b -B -p -r1.51 syslogd.c
--- syslogd.c	2000/12/18 03:57:16	1.51
+++ syslogd.c	2001/01/05 21:51:06
@@ -165,7 +165,7 @@ static void logMessage (int pri, char *m
 #ifdef BB_FEATURE_REMOTE_LOG
 	/* send message to remote logger */
 	if ( -1 != remotefd){
-#define IOV_COUNT 2
+static const int IOV_COUNT = 2;
 		struct iovec iov[IOV_COUNT];
 		struct iovec *v = iov;
 
@@ -206,7 +206,7 @@ static void domark(int sig)
 	}
 }
 
-#define BUFSIZE 1023
+static const int BUFSIZE = 1023;
 static int serveConnection (int conn)
 {
 	char   buf[ BUFSIZE + 1 ];
Index: tar.c
===================================================================
RCS file: /var/cvs/busybox/tar.c,v
retrieving revision 1.86
diff -u -b -B -p -r1.86 tar.c
--- tar.c	2001/01/03 17:22:10	1.86
+++ tar.c	2001/01/05 21:51:06
@@ -64,7 +64,7 @@ extern int gunzip_init();
 #define MINOR(dev) ((dev)&0xff)
 #endif
 
-#define NAME_SIZE	100
+enum { NAME_SIZE = 100 };
 
 /* POSIX tar Header Block, from POSIX 1003.1-1990  */
 struct TarHeader
@@ -94,9 +94,9 @@ typedef struct TarHeader TarHeader;
 /* A few useful constants */
 #define TAR_MAGIC          "ustar"        /* ustar and a null */
 #define TAR_VERSION        "  "           /* Be compatable with GNU tar format */
-#define TAR_MAGIC_LEN       6
-#define TAR_VERSION_LEN     2
-#define TAR_BLOCK_SIZE      512
+static const int TAR_MAGIC_LEN = 6;
+static const int TAR_VERSION_LEN = 2;
+static const int TAR_BLOCK_SIZE = 512;
 
 /* A nice enum with all the possible tar file content types */
 enum TarFileType 
Index: telnet.c
===================================================================
RCS file: /var/cvs/busybox/telnet.c,v
retrieving revision 1.10
diff -u -b -B -p -r1.10 telnet.c
--- telnet.c	2000/12/18 03:57:16	1.10
+++ telnet.c	2001/01/05 21:51:06
@@ -46,7 +46,7 @@
 #include <netdb.h>
 
 #if 0
-#define DOTRACE 1
+static const int DOTRACE = 1;
 #endif
 
 #ifdef DOTRACE
@@ -63,21 +63,23 @@
 #include <sys/time.h>
 #endif
 
-#define DATABUFSIZE 128
-#define IACBUFSIZE 128
+static const int DATABUFSIZE = 128;
+static const int IACBUFSIZE = 128;
 
-#define CHM_TRY 0
-#define CHM_ON	1
-#define CHM_OFF	2
-
-#define UF_ECHO	0x01
-#define UF_SGA	0x02
-
-#define TS_0	1
-#define TS_IAC	2
-#define TS_OPT	3
-#define TS_SUB1 4
-#define TS_SUB2	5
+static const int CHM_TRY = 0;
+static const int CHM_ON = 1;
+static const int CHM_OFF = 2;
+
+static const int UF_ECHO = 0x01;
+static const int UF_SGA = 0x02;
+
+enum {
+	TS_0 = 1,
+	TS_IAC = 2,
+	TS_OPT = 3,
+	TS_SUB1 = 4,
+	TS_SUB2 = 5,
+};
 
 #define WriteCS(fd, str) write(fd, str, sizeof str -1)
 
Index: tr.c
===================================================================
RCS file: /var/cvs/busybox/tr.c,v
retrieving revision 1.18
diff -u -b -B -p -r1.18 tr.c
--- tr.c	2000/12/07 19:56:48	1.18
+++ tr.c	2001/01/05 21:51:06
@@ -34,13 +34,13 @@
 #define bb_need_write_error
 #include "messages.c"
 
-#define ASCII		0377
+static const int ASCII = 0377;
 
 /* some glabals shared across this file */
 static char com_fl, del_fl, sq_fl;
-static unsigned char output[BUFSIZ], input[BUFSIZ];
-static unsigned char vector[ASCII + 1];
-static char invec[ASCII + 1], outvec[ASCII + 1];
+static unsigned char *output, *input;
+static unsigned char *vector;
+static char *invec, *outvec;
 static short in_index, out_index;
 
 
@@ -162,6 +162,14 @@ extern int tr_main(int argc, char **argv
 		}
 		index++;
 	}
+
+	/* set up big arrays here, better than making a bunch of static arrays up top */
+	output = xmalloc(sizeof(char)*BUFSIZ);
+	input  = xmalloc(sizeof(char)*BUFSIZ);
+	vector = xmalloc(sizeof(char)*(ASCII + 1));
+	invec  = xmalloc(sizeof(char)*(ASCII + 1));
+	outvec = xmalloc(sizeof(char)*(ASCII + 1));
+
 	for (i = 0; i <= ASCII; i++) {
 		vector[i] = i;
 		invec[i] = outvec[i] = FALSE;
Index: umount.c
===================================================================
RCS file: /var/cvs/busybox/umount.c,v
retrieving revision 1.44
diff -u -b -B -p -r1.44 umount.c
--- umount.c	2000/12/22 01:48:07	1.44
+++ umount.c	2001/01/05 21:51:06
@@ -28,10 +28,10 @@
 #include <errno.h>
 
 
-#define MNT_FORCE		1
-#define MS_MGC_VAL		0xc0ed0000 /* Magic number indicatng "new" flags */
-#define MS_REMOUNT		32	/* Alter flags of a mounted FS.  */
-#define MS_RDONLY		1	/* Mount read-only.  */
+static const int MNT_FORCE = 1;
+static const int MS_MGC_VAL = 0xc0ed0000; /* Magic number indicatng "new" flags */
+static const int MS_REMOUNT = 32;	/* Alter flags of a mounted FS.  */
+static const int MS_RDONLY = 1;	/* Mount read-only.  */
 
 extern int mount (__const char *__special_file, __const char *__dir,
 			__const char *__fstype, unsigned long int __rwflag,
Index: uname.c
===================================================================
RCS file: /var/cvs/busybox/uname.c,v
retrieving revision 1.10
diff -u -b -B -p -r1.10 uname.c
--- uname.c	2000/12/22 01:48:07	1.10
+++ uname.c	2001/01/05 21:51:06
@@ -44,22 +44,22 @@ static void print_element(unsigned int m
 
 /* Values that are bitwise or'd into `toprint'. */
 /* Operating system name. */
-#define PRINT_SYSNAME 1
+static const int PRINT_SYSNAME = 1;
 
 /* Node name on a communications network. */
-#define PRINT_NODENAME 2
+static const int PRINT_NODENAME = 2;
 
 /* Operating system release. */
-#define PRINT_RELEASE 4
+static const int PRINT_RELEASE = 4;
 
 /* Operating system version. */
-#define PRINT_VERSION 8
+static const int PRINT_VERSION = 8;
 
 /* Machine hardware name. */
-#define PRINT_MACHINE 16
+static const int PRINT_MACHINE = 16;
 
  /* Host processor type. */
-#define PRINT_PROCESSOR 32
+static const int PRINT_PROCESSOR = 32;
 
 /* Mask indicating which elements of the name to print. */
 static unsigned char toprint;
Index: uptime.c
===================================================================
RCS file: /var/cvs/busybox/uptime.c,v
retrieving revision 1.8
diff -u -b -B -p -r1.8 uptime.c
--- uptime.c	2000/12/01 02:55:13	1.8
+++ uptime.c	2001/01/05 21:51:06
@@ -33,7 +33,7 @@
 #include <time.h>
 #include <errno.h>
 
-#define FSHIFT          16              /* nr of bits of precision */
+static const int FSHIFT = 16;              /* nr of bits of precision */
 #define FIXED_1         (1<<FSHIFT)     /* 1.0 as fixed-point */
 #define LOAD_INT(x) ((x) >> FSHIFT)
 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
Index: utility.c
===================================================================
RCS file: /var/cvs/busybox/utility.c,v
retrieving revision 1.182
diff -u -b -B -p -r1.182 utility.c
--- utility.c	2001/01/03 01:38:29	1.182
+++ utility.c	2001/01/05 21:51:06
@@ -172,7 +172,7 @@ _syscall1(int, sysinfo, struct sysinfo *
 #if defined BB_MOUNT || defined BB_UMOUNT
 
 #ifndef __NR_umount2
-#define __NR_umount2           52
+static const int __NR_umount2 = 52;
 #endif
 
 /* Include our own version of <sys/mount.h>, since libc5 doesn't
@@ -185,7 +185,7 @@ extern _syscall5(int, mount, const char 
 
 #if defined BB_INSMOD || defined BB_LSMOD
 #ifndef __NR_query_module
-#define __NR_query_module     167
+static const int __NR_query_module = 167;
 #endif
 _syscall5(int, query_module, const char *, name, int, which,
 		void *, buf, size_t, bufsize, size_t*, ret);
@@ -980,9 +980,9 @@ long my_getpwnamegid(char *name)
 #if (defined BB_CHVT) || (defined BB_DEALLOCVT) || (defined BB_SETKEYCODES)
 
 /* From <linux/kd.h> */ 
-#define KDGKBTYPE       0x4B33  /* get keyboard type */
-#define         KB_84           0x01
-#define         KB_101          0x02    /* this is what we always answer */
+static const int KDGKBTYPE = 0x4B33;  /* get keyboard type */
+static const int KB_84 = 0x01;
+static const int KB_101 = 0x02;    /* this is what we always answer */
 
 int is_a_console(int fd)
 {
Index: wget.c
===================================================================
RCS file: /var/cvs/busybox/wget.c,v
retrieving revision 1.15
diff -u -b -B -p -r1.15 wget.c
--- wget.c	2001/01/03 16:15:15	1.15
+++ wget.c	2001/01/05 21:51:06
@@ -45,7 +45,7 @@ static char *curfile;			/* Name of curre
 static struct timeval start;	/* Time a transfer started. */
 volatile unsigned long statbytes; /* Number of bytes transferred so far. */
 /* For progressmeter() -- number of seconds before xfer considered "stalled" */
-#define STALLTIME	5
+static const int STALLTIME = 5;
 #endif
 
 int wget_main(int argc, char **argv)


More information about the busybox mailing list