summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley2001-01-23 22:30:04 +0000
committerMark Whitley2001-01-23 22:30:04 +0000
commit59ab025363d884deb2013dcaae6c968585a6ec72 (patch)
tree852d97bdc34c44dbcf29cc8b5cd9257a8c90f7b3
parent2b8d07c590249991fae975652aae86f5fca91f81 (diff)
downloadbusybox-59ab025363d884deb2013dcaae6c968585a6ec72.zip
busybox-59ab025363d884deb2013dcaae6c968585a6ec72.tar.gz
#define -> static const int. Also got rid of some big static buffers.
-rw-r--r--archival/gunzip.c51
-rw-r--r--archival/tar.c8
-rw-r--r--chvt.c4
-rw-r--r--cmdedit.c9
-rw-r--r--console-tools/chvt.c4
-rw-r--r--console-tools/deallocvt.c2
-rw-r--r--console-tools/dumpkmap.c6
-rw-r--r--console-tools/loadfont.c12
-rw-r--r--console-tools/loadkmap.c6
-rw-r--r--console-tools/setkeycodes.c2
-rw-r--r--coreutils/ln.c6
-rw-r--r--coreutils/ls.c75
-rw-r--r--coreutils/md5sum.c6
-rw-r--r--coreutils/printf.c2
-rw-r--r--coreutils/tr.c40
-rw-r--r--coreutils/uname.c12
-rw-r--r--cp_mv.c10
-rw-r--r--deallocvt.c2
-rw-r--r--dumpkmap.c6
-rw-r--r--fbset.c94
-rw-r--r--fsck_minix.c38
-rw-r--r--getopt.c6
-rw-r--r--gunzip.c51
-rw-r--r--init.c14
-rw-r--r--init/init.c14
-rw-r--r--insmod.c38
-rw-r--r--kill.c4
-rw-r--r--lash.c4
-rw-r--r--ln.c6
-rw-r--r--loadfont.c12
-rw-r--r--loadkmap.c6
-rw-r--r--ls.c75
-rw-r--r--lsmod.c22
-rw-r--r--md5sum.c6
-rw-r--r--mkswap.c2
-rw-r--r--modutils/insmod.c38
-rw-r--r--modutils/lsmod.c22
-rw-r--r--mount.c30
-rw-r--r--networking/ping.c20
-rw-r--r--networking/telnet.c28
-rw-r--r--networking/wget.c4
-rw-r--r--nfsmount.c61
-rw-r--r--ping.c20
-rw-r--r--printf.c2
-rw-r--r--procps/kill.c4
-rw-r--r--procps/ps.c2
-rw-r--r--procps/uptime.c2
-rw-r--r--ps.c2
-rw-r--r--rdate.c2
-rw-r--r--rpmunpack.c18
-rw-r--r--setkeycodes.c2
-rw-r--r--sh.c4
-rw-r--r--shell/cmdedit.c9
-rw-r--r--shell/lash.c4
-rw-r--r--swaponoff.c4
-rw-r--r--sysklogd/syslogd.c4
-rw-r--r--syslogd.c4
-rw-r--r--tar.c8
-rw-r--r--telnet.c28
-rw-r--r--tr.c40
-rw-r--r--umount.c8
-rw-r--r--uname.c12
-rw-r--r--uptime.c2
-rw-r--r--util-linux/fbset.c94
-rw-r--r--util-linux/fsck_minix.c38
-rw-r--r--util-linux/getopt.c6
-rw-r--r--util-linux/mkswap.c2
-rw-r--r--util-linux/mount.c30
-rw-r--r--util-linux/nfsmount.c61
-rw-r--r--util-linux/rdate.c2
-rw-r--r--util-linux/swaponoff.c4
-rw-r--r--util-linux/umount.c8
-rw-r--r--utility.c10
-rw-r--r--wget.c4
74 files changed, 674 insertions, 624 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c
index 8558573..1949216 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -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
+static const int OK = 0;
+static const int ERROR = 1;
+static const int 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 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) */
@@ -1225,6 +1225,9 @@ int gunzip_main(int argc, char **argv)
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;
tostdout = 1;
diff --git a/archival/tar.c b/archival/tar.c
index 2699550..51a857d 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -64,7 +64,7 @@ extern int gunzip_init();
#define MINOR(dev) ((dev)&0xff)
#endif
-#define NAME_SIZE 100
+enum { NAME_SIZE = 100 }; /* because gcc won't let me use 'static const int' */
/* 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
diff --git a/chvt.c b/chvt.c
index 76d4b53..c715e67 100644
--- a/chvt.c
+++ b/chvt.c
@@ -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)
{
diff --git a/cmdedit.c b/cmdedit.c
index 722a36a..12c78dc 100644
--- a/cmdedit.c
+++ b/cmdedit.c
@@ -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 */
+
+enum {
+ ESC = 27,
+ DEL = 127,
+};
-#define ESC 27
-#define DEL 127
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
diff --git a/console-tools/chvt.c b/console-tools/chvt.c
index 76d4b53..c715e67 100644
--- a/console-tools/chvt.c
+++ b/console-tools/chvt.c
@@ -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)
{
diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c
index 3dd90c0..fad7a2b 100644
--- a/console-tools/deallocvt.c
+++ b/console-tools/deallocvt.c
@@ -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[])
{
diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c
index c5a2ea7..b438ba2 100644
--- a/console-tools/dumpkmap.c
+++ b/console-tools/dumpkmap.c
@@ -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)
{
diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c
index 13a196f..08e0761 100644
--- a/console-tools/loadfont.c
+++ b/console-tools/loadfont.c
@@ -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 */
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c
index fc24398..43c1cc7 100644
--- a/console-tools/loadkmap.c
+++ b/console-tools/loadkmap.c
@@ -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)
{
diff --git a/console-tools/setkeycodes.c b/console-tools/setkeycodes.c
index 7db398d..be9b1b7 100644
--- a/console-tools/setkeycodes.c
+++ b/console-tools/setkeycodes.c
@@ -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)
diff --git a/coreutils/ln.c b/coreutils/ln.c
index ead5322..e69cb02 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -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,
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 754a6d4..0807680 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -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;
@@ -710,10 +709,16 @@ 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;
/* process options */
diff --git a/coreutils/md5sum.c b/coreutils/md5sum.c
index 3458f2e..ad40780 100644
--- a/coreutils/md5sum.c
+++ b/coreutils/md5sum.c
@@ -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, void *resbuf)
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 *buffer, size_t len, struct md5_ctx *ctx)
/* 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 */
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 832ca13..72bc7ae 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -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)
diff --git a/coreutils/tr.c b/coreutils/tr.c
index fd547b8..d21e672 100644
--- a/coreutils/tr.c
+++ b/coreutils/tr.c
@@ -34,14 +34,15 @@
#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 short in_index, out_index;
+/* these last are pointers to static buffers declared in tr_main */
+static unsigned char *poutput, *pinput;
+static unsigned char *pvector;
+static char *pinvec, *poutvec;
static void convert()
@@ -52,22 +53,22 @@ static void convert()
for (;;) {
if (in_index == read_chars) {
- if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) {
- if (write(1, (char *) output, out_index) != out_index)
+ if ((read_chars = read(0, (char *) pinput, BUFSIZ)) <= 0) {
+ if (write(1, (char *) poutput, out_index) != out_index)
write(2, write_error, strlen(write_error));
exit(0);
}
in_index = 0;
}
- c = input[in_index++];
- coded = vector[c];
- if (del_fl && invec[c])
+ c = pinput[in_index++];
+ coded = pvector[c];
+ if (del_fl && pinvec[c])
continue;
- if (sq_fl && last == coded && (invec[c] || outvec[coded]))
+ if (sq_fl && last == coded && (pinvec[c] || poutvec[coded]))
continue;
- output[out_index++] = last = coded;
+ poutput[out_index++] = last = coded;
if (out_index == BUFSIZ) {
- if (write(1, (char *) output, out_index) != out_index) {
+ if (write(1, (char *) poutput, out_index) != out_index) {
write(2, write_error, strlen(write_error));
exit(1);
}
@@ -86,9 +87,9 @@ static void map(register unsigned char *string1, unsigned int string1_len,
for (j = 0, i = 0; i < string1_len; i++) {
if (string2_len <= j)
- vector[string1[i]] = last;
+ pvector[string1[i]] = last;
else
- vector[string1[i]] = last = string2[j++];
+ pvector[string1[i]] = last = string2[j++];
}
}
@@ -143,6 +144,17 @@ extern int tr_main(int argc, char **argv)
int output_length=0, input_length;
int index = 1;
int i;
+ /* set up big arrays here (better than making a bunch of static arrays up top) */
+ unsigned char output[BUFSIZ], input[BUFSIZ];
+ unsigned char vector[ASCII + 1];
+ char invec[ASCII + 1], outvec[ASCII + 1];
+
+ /* ... but make them available globally */
+ poutput = output;
+ pinput = input;
+ pvector = vector;
+ pinvec = invec;
+ poutvec = outvec;
if (argc > 1 && argv[index][0] == '-') {
for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
diff --git a/coreutils/uname.c b/coreutils/uname.c
index e7e9ff3..4f7c643 100644
--- a/coreutils/uname.c
+++ b/coreutils/uname.c
@@ -44,22 +44,22 @@ static void print_element(unsigned int mask, char *element);
/* 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;
diff --git a/cp_mv.c b/cp_mv.c
index 0b32882..5548350 100644
--- a/cp_mv.c
+++ b/cp_mv.c
@@ -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 *pBaseDestName;
static size_t baseDestLen;
static int destDirFlag;
static struct stat destStatBuf;
@@ -104,7 +104,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
const char *srcBasename;
char *name;
- strcpy(destName, baseDestName);
+ strcpy(destName, pBaseDestName);
destLen = strlen(destName);
if (srcDirFlag == TRUE) {
@@ -175,6 +175,8 @@ extern int cp_mv_main(int argc, char **argv)
{
volatile int i;
int c;
+ char baseDestName[BUFSIZ + 1]; /* not declared globally == less bss used */
+ pBaseDestName = baseDestName; /* but available globally */
if (*applet_name == 'c' && *(applet_name + 1) == 'p')
dz_i = is_cp;
diff --git a/deallocvt.c b/deallocvt.c
index 3dd90c0..fad7a2b 100644
--- a/deallocvt.c
+++ b/deallocvt.c
@@ -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[])
{
diff --git a/dumpkmap.c b/dumpkmap.c
index c5a2ea7..b438ba2 100644
--- a/dumpkmap.c
+++ b/dumpkmap.c
@@ -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)
{
diff --git a/fbset.c b/fbset.c
index 40a907b..845be84 100644
--- a/fbset.c
+++ b/fbset.c
@@ -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)
diff --git a/fsck_minix.c b/fsck_minix.c
index b35e6bb..18841ec 100644
--- a/fsck_minix.c
+++ b/fsck_minix.c
@@ -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;
diff --git a/getopt.c b/getopt.c
index 0ebf9df..ff55a3e 100644
--- a/getopt.c
+++ b/getopt.c
@@ -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 argc,const char *optstr,
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. */
diff --git a/gunzip.c b/gunzip.c
index 8558573..1949216 100644
--- a/gunzip.c
+++ b/gunzip.c
@@ -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
+static const int OK = 0;
+static const int ERROR = 1;
+static const int 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 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) */
@@ -1225,6 +1225,9 @@ int gunzip_main(int argc, char **argv)
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;
tostdout = 1;
diff --git a/init.c b/init.c
index 0e9b741..ac0f72b 100644
--- a/init.c
+++ b/init.c
@@ -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, int, data);
#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 {
diff --git a/init/init.c b/init/init.c
index 0e9b741..ac0f72b 100644
--- a/init/init.c
+++ b/init/init.c
@@ -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, int, data);
#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 {
diff --git a/insmod.c b/insmod.c
index a499bcd..be27a1f 100644
--- a/insmod.c
+++ b/insmod.c
@@ -76,9 +76,9 @@
#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 $"
+#ident "$Id: insmod.c,v 1.36 2001/01/23 22:30:04 markw Exp $"
/* This file contains the structures used by the 2.0 and 2.1 kernels.
We do not use the kernel headers directly because we do not wish
@@ -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, char *code, unsigned codesize,
#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 which, void *buf, size_t bufsize,
/* 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,9 +282,9 @@ 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 $"
+#ident "$Id: insmod.c,v 1.36 2001/01/23 22:30:04 markw Exp $"
/* The relocatable object is manipulated using elfin types. */
@@ -517,7 +517,7 @@ int arch_init_module (struct obj_file *f, struct new_module *);
#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"
diff --git a/kill.c b/kill.c
index 8fa9da7..19ca187 100644
--- a/kill.c
+++ b/kill.c
@@ -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;
diff --git a/lash.c b/lash.c
index 52c87ee..b9685ab 100644
--- a/lash.c
+++ b/lash.c
@@ -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;
diff --git a/ln.c b/ln.c
index ead5322..e69cb02 100644
--- a/ln.c
+++ b/ln.c
@@ -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,
diff --git a/loadfont.c b/loadfont.c
index 13a196f..08e0761 100644
--- a/loadfont.c
+++ b/loadfont.c
@@ -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 */
diff --git a/loadkmap.c b/loadkmap.c
index fc24398..43c1cc7 100644
--- a/loadkmap.c
+++ b/loadkmap.c
@@ -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)
{
diff --git a/ls.c b/ls.c
index 754a6d4..0807680 100644
--- a/ls.c
+++ b/ls.c
@@ -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;
@@ -710,10 +709,16 @@ 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;
/* process options */
diff --git a/lsmod.c b/lsmod.c
index 4c50bf4..586920d 100644
--- a/lsmod.c
+++ b/lsmod.c
@@ -59,19 +59,19 @@ int query_module(const char *name, int which, void *buf, size_t bufsize,
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)
diff --git a/md5sum.c b/md5sum.c
index 3458f2e..ad40780 100644
--- a/md5sum.c
+++ b/md5sum.c
@@ -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, void *resbuf)
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 *buffer, size_t len, struct md5_ctx *ctx)
/* 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 */
diff --git a/mkswap.c b/mkswap.c
index e7fab4e..5b908da 100644
--- a/mkswap.c
+++ b/mkswap.c
@@ -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)
diff --git a/modutils/insmod.c b/modutils/insmod.c
index a499bcd..be27a1f 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -76,9 +76,9 @@
#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 $"
+#ident "$Id: insmod.c,v 1.36 2001/01/23 22:30:04 markw Exp $"
/* This file contains the structures used by the 2.0 and 2.1 kernels.
We do not use the kernel headers directly because we do not wish
@@ -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, char *code, unsigned codesize,
#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 which, void *buf, size_t bufsize,
/* 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,9 +282,9 @@ 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 $"
+#ident "$Id: insmod.c,v 1.36 2001/01/23 22:30:04 markw Exp $"
/* The relocatable object is manipulated using elfin types. */
@@ -517,7 +517,7 @@ int arch_init_module (struct obj_file *f, struct new_module *);
#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"
diff --git a/modutils/lsmod.c b/modutils/lsmod.c
index 4c50bf4..586920d 100644
--- a/modutils/lsmod.c
+++ b/modutils/lsmod.c
@@ -59,19 +59,19 @@ int query_module(const char *name, int which, void *buf, size_t bufsize,
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)
diff --git a/mount.c b/mount.c
index 88e45fc..f78786e 100644
--- a/mount.c
+++ b/mount.c
@@ -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
diff --git a/networking/ping.c b/networking/ping.c
index 8276dda..f5769b7 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
- * $Id: ping.c,v 1.31 2001/01/22 22:48:42 andersen Exp $
+ * $Id: ping.c,v 1.32 2001/01/23 22:30:04 markw Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -58,7 +58,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
{
@@ -134,13 +134,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)
@@ -262,7 +262,7 @@ extern int ping_main(int argc, char **argv)
static char *hostname = NULL;
static struct sockaddr_in pingaddr;
static int pingsock = -1;
-static int datalen = DEFDATALEN;
+static int datalen; /* intentionally uninitialized to work around gcc bug */
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
static int myid = 0, options = 0;
@@ -508,6 +508,8 @@ extern int ping_main(int argc, char **argv)
{
char *thisarg;
+ datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
+
argc--;
argv++;
options = 0;
diff --git a/networking/telnet.c b/networking/telnet.c
index 76956e9..ac6813e 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -50,7 +50,7 @@
#include <netdb.h>
#if 0
-#define DOTRACE 1
+static const int DOTRACE = 1;
#endif
#ifdef DOTRACE
@@ -67,21 +67,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
+static const int CHM_TRY = 0;
+static const int CHM_ON = 1;
+static const int CHM_OFF = 2;
-#define UF_ECHO 0x01
-#define UF_SGA 0x02
+static const int UF_ECHO = 0x01;
+static const int UF_SGA = 0x02;
-#define TS_0 1
-#define TS_IAC 2
-#define TS_OPT 3
-#define TS_SUB1 4
-#define TS_SUB2 5
+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)
diff --git a/networking/wget.c b/networking/wget.c
index a5c3e7b..e3e6eed 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -49,7 +49,7 @@ static char *curfile; /* Name of current file being transferred. */
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)
@@ -515,7 +515,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.17 2001/01/22 22:48:42 andersen Exp $
+ * $Id: wget.c,v 1.18 2001/01/23 22:30:04 markw Exp $
*/
diff --git a/nfsmount.c b/nfsmount.c
index b5c3821..d661a99 100644
--- a/nfsmount.c
+++ b/nfsmount.c
@@ -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;
+static 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;
diff --git a/ping.c b/ping.c
index 8276dda..f5769b7 100644
--- a/ping.c
+++ b/ping.c
@@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
- * $Id: ping.c,v 1.31 2001/01/22 22:48:42 andersen Exp $
+ * $Id: ping.c,v 1.32 2001/01/23 22:30:04 markw Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -58,7 +58,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
{
@@ -134,13 +134,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)
@@ -262,7 +262,7 @@ extern int ping_main(int argc, char **argv)
static char *hostname = NULL;
static struct sockaddr_in pingaddr;
static int pingsock = -1;
-static int datalen = DEFDATALEN;
+static int datalen; /* intentionally uninitialized to work around gcc bug */
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
static int myid = 0, options = 0;
@@ -508,6 +508,8 @@ extern int ping_main(int argc, char **argv)
{
char *thisarg;
+ datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
+
argc--;
argv++;
options = 0;
diff --git a/printf.c b/printf.c
index 832ca13..72bc7ae 100644
--- a/printf.c
+++ b/printf.c
@@ -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)
diff --git a/procps/kill.c b/procps/kill.c
index 8fa9da7..19ca187 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -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;
diff --git a/procps/ps.c b/procps/ps.c
index ec63bb5..cb4c21e 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -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 */
diff --git a/procps/uptime.c b/procps/uptime.c
index fb3d347..f5e12f1 100644
--- a/procps/uptime.c
+++ b/procps/uptime.c
@@ -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)
diff --git a/ps.c b/ps.c
index ec63bb5..cb4c21e 100644
--- a/ps.c
+++ b/ps.c
@@ -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 */
diff --git a/rdate.c b/rdate.c
index bb53927..954982a 100644
--- a/rdate.c
+++ b/rdate.c
@@ -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;
diff --git a/rpmunpack.c b/rpmunpack.c
index 249d223..512d638 100644
--- a/rpmunpack.c
+++ b/rpmunpack.c
@@ -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,14 +27,13 @@
/*
* Global variables
*/
-static char buffer[BUFSIZE];
static char *progname;
static int infile, outfile;
/*
* Read a specified number of bytes from input file
*/
-static void myread(int num)
+static void myread(int num, char *buffer)
{
int err;
@@ -52,6 +51,7 @@ static void myread(int num)
int rpmunpack_main(int argc, char **argv)
{
int len, status = 0;
+ char buffer[BUFSIZ];
/* Get our own program name */
if ((progname = strrchr(argv[0], '/')) == NULL)
@@ -71,13 +71,13 @@ int rpmunpack_main(int argc, char **argv)
perror_msg_and_die("%s", argv[1]);
/* Read magic ID and output filename */
- myread(4);
+ myread(4, buffer);
if (strncmp(buffer, RPM_MAGIC, 4)) {
fprintf(stderr, "Input file is not in RPM format!\n");
exit(1);
}
- myread(6); /* Skip flags */
- myread(64);
+ myread(6, buffer); /* Skip flags */
+ myread(64, buffer);
buffer[64] = '\0';
/* Open output file */
@@ -97,9 +97,9 @@ int rpmunpack_main(int argc, char **argv)
* never appears before offset 0x200, so we skip these first couple of
* bytes to make the signature scan a little more reliable.
*/
- myread(0x200 - 74);
+ myread(0x200 - 74, buffer);
while (status < 2) {
- myread(1);
+ myread(1, buffer);
if (status == 0 && buffer[0] == GZ_MAGIC_1)
status++;
else if (status == 1 && buffer[0] == GZ_MAGIC_2)
@@ -113,7 +113,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");
}
diff --git a/setkeycodes.c b/setkeycodes.c
index 7db398d..be9b1b7 100644
--- a/setkeycodes.c
+++ b/setkeycodes.c
@@ -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)
diff --git a/sh.c b/sh.c
index 52c87ee..b9685ab 100644
--- a/sh.c
+++ b/sh.c
@@ -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;
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 722a36a..12c78dc 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -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 */
+
+enum {
+ ESC = 27,
+ DEL = 127,
+};
-#define ESC 27
-#define DEL 127
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
diff --git a/shell/lash.c b/shell/lash.c
index 52c87ee..b9685ab 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -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;
diff --git a/swaponoff.c b/swaponoff.c
index 85f3389..eda1510 100644
--- a/swaponoff.c
+++ b/swaponoff.c
@@ -35,8 +35,8 @@ _syscall1(int, swapoff, const char *, path);
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)
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 4217c36..114516e 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -165,7 +165,7 @@ static void logMessage (int pri, char *msg)
#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 ];
diff --git a/syslogd.c b/syslogd.c
index 4217c36..114516e 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -165,7 +165,7 @@ static void logMessage (int pri, char *msg)
#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 ];
diff --git a/tar.c b/tar.c
index 2699550..51a857d 100644
--- a/tar.c
+++ b/tar.c
@@ -64,7 +64,7 @@ extern int gunzip_init();
#define MINOR(dev) ((dev)&0xff)
#endif
-#define NAME_SIZE 100
+enum { NAME_SIZE = 100 }; /* because gcc won't let me use 'static const int' */
/* 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
diff --git a/telnet.c b/telnet.c
index 76956e9..ac6813e 100644
--- a/telnet.c
+++ b/telnet.c
@@ -50,7 +50,7 @@
#include <netdb.h>
#if 0
-#define DOTRACE 1
+static const int DOTRACE = 1;
#endif
#ifdef DOTRACE
@@ -67,21 +67,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
+static const int CHM_TRY = 0;
+static const int CHM_ON = 1;
+static const int CHM_OFF = 2;
-#define UF_ECHO 0x01
-#define UF_SGA 0x02
+static const int UF_ECHO = 0x01;
+static const int UF_SGA = 0x02;
-#define TS_0 1
-#define TS_IAC 2
-#define TS_OPT 3
-#define TS_SUB1 4
-#define TS_SUB2 5
+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)
diff --git a/tr.c b/tr.c
index fd547b8..d21e672 100644
--- a/tr.c
+++ b/tr.c
@@ -34,14 +34,15 @@
#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 short in_index, out_index;
+/* these last are pointers to static buffers declared in tr_main */
+static unsigned char *poutput, *pinput;
+static unsigned char *pvector;
+static char *pinvec, *poutvec;
static void convert()
@@ -52,22 +53,22 @@ static void convert()
for (;;) {
if (in_index == read_chars) {
- if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) {
- if (write(1, (char *) output, out_index) != out_index)
+ if ((read_chars = read(0, (char *) pinput, BUFSIZ)) <= 0) {
+ if (write(1, (char *) poutput, out_index) != out_index)
write(2, write_error, strlen(write_error));
exit(0);
}
in_index = 0;
}
- c = input[in_index++];
- coded = vector[c];
- if (del_fl && invec[c])
+ c = pinput[in_index++];
+ coded = pvector[c];
+ if (del_fl && pinvec[c])
continue;
- if (sq_fl && last == coded && (invec[c] || outvec[coded]))
+ if (sq_fl && last == coded && (pinvec[c] || poutvec[coded]))
continue;
- output[out_index++] = last = coded;
+ poutput[out_index++] = last = coded;
if (out_index == BUFSIZ) {
- if (write(1, (char *) output, out_index) != out_index) {
+ if (write(1, (char *) poutput, out_index) != out_index) {
write(2, write_error, strlen(write_error));
exit(1);
}
@@ -86,9 +87,9 @@ static void map(register unsigned char *string1, unsigned int string1_len,
for (j = 0, i = 0; i < string1_len; i++) {
if (string2_len <= j)
- vector[string1[i]] = last;
+ pvector[string1[i]] = last;
else
- vector[string1[i]] = last = string2[j++];
+ pvector[string1[i]] = last = string2[j++];
}
}
@@ -143,6 +144,17 @@ extern int tr_main(int argc, char **argv)
int output_length=0, input_length;
int index = 1;
int i;
+ /* set up big arrays here (better than making a bunch of static arrays up top) */
+ unsigned char output[BUFSIZ], input[BUFSIZ];
+ unsigned char vector[ASCII + 1];
+ char invec[ASCII + 1], outvec[ASCII + 1];
+
+ /* ... but make them available globally */
+ poutput = output;
+ pinput = input;
+ pvector = vector;
+ pinvec = invec;
+ poutvec = outvec;
if (argc > 1 && argv[index][0] == '-') {
for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
diff --git a/umount.c b/umount.c
index 40d25f9..2e2d95d 100644
--- a/umount.c
+++ b/umount.c
@@ -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,
diff --git a/uname.c b/uname.c
index e7e9ff3..4f7c643 100644
--- a/uname.c
+++ b/uname.c
@@ -44,22 +44,22 @@ static void print_element(unsigned int mask, char *element);
/* 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;
diff --git a/uptime.c b/uptime.c
index fb3d347..f5e12f1 100644
--- a/uptime.c
+++ b/uptime.c
@@ -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)
diff --git a/util-linux/fbset.c b/util-linux/fbset.c
index 40a907b..845be84 100644
--- a/util-linux/fbset.c
+++ b/util-linux/fbset.c
@@ -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)
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c
index b35e6bb..18841ec 100644
--- a/util-linux/fsck_minix.c
+++ b/util-linux/fsck_minix.c
@@ -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;
diff --git a/util-linux/getopt.c b/util-linux/getopt.c
index 0ebf9df..ff55a3e 100644
--- a/util-linux/getopt.c
+++ b/util-linux/getopt.c
@@ -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 argc,const char *optstr,
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. */
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index e7fab4e..5b908da 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -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)
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 88e45fc..f78786e 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -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
diff --git a/util-linux/nfsmount.c b/util-linux/nfsmount.c
index b5c3821..d661a99 100644
--- a/util-linux/nfsmount.c
+++ b/util-linux/nfsmount.c
@@ -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;
+static 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;
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
index bb53927..954982a 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -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;
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 85f3389..eda1510 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -35,8 +35,8 @@ _syscall1(int, swapoff, const char *, path);
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)
diff --git a/util-linux/umount.c b/util-linux/umount.c
index 40d25f9..2e2d95d 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -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,
diff --git a/utility.c b/utility.c
index bff589a..6b637de 100644
--- a/utility.c
+++ b/utility.c
@@ -167,7 +167,7 @@ _syscall1(int, sysinfo, struct sysinfo *, info);
#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
@@ -180,7 +180,7 @@ extern _syscall5(int, mount, const char *, special_file, const char *, dir,
#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);
@@ -975,9 +975,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)
{
diff --git a/wget.c b/wget.c
index a5c3e7b..e3e6eed 100644
--- a/wget.c
+++ b/wget.c
@@ -49,7 +49,7 @@ static char *curfile; /* Name of current file being transferred. */
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)
@@ -515,7 +515,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.17 2001/01/22 22:48:42 andersen Exp $
+ * $Id: wget.c,v 1.18 2001/01/23 22:30:04 markw Exp $
*/