From 499f65fb98a8258f8704b52efb3a99da0c82f785 Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Tue, 16 May 2000 20:07:38 +0000 Subject: [PATCH] Some updates for better portability. -Erik --- Makefile | 18 ++++++++++-------- coreutils/date.c | 4 ++-- date.c | 4 ++-- dutmp.c | 35 ++++++++++++++++------------------- miscutils/dutmp.c | 35 ++++++++++++++++------------------- miscutils/mt.c | 2 +- mt.c | 2 +- 7 files changed, 48 insertions(+), 52 deletions(-) diff --git a/Makefile b/Makefile index e9192f948..d3d71ad77 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,12 @@ DODEBUG = false # If you want a static binary, turn this on. DOSTATIC = false +# To compile vs an alternative libc, you may need to use/adjust +# the following lines to meet your needs. This is how I did it... +#CFLAGS+=-nostdinc -I/home/andersen/CVS/uC-libc/include -I/usr/include/linux +#LDFLAGS+=-nostdlib -L/home/andersen/CVS/libc.a + + CC = gcc # use '-Os' optimization if available, else use -O2 @@ -43,10 +49,6 @@ ifndef $(STRIPTOOL) STRIPTOOL = strip endif -# TODO: Try compiling vs other libcs. -# See what -nostdinc and -nostdlib do for them. -# also try --prefix=/usr/my-libc-stuff - # -D_GNU_SOURCE is needed because environ is used in init.c ifeq ($(DODEBUG),true) CFLAGS += -Wall -g -D_GNU_SOURCE @@ -65,11 +67,10 @@ else #want to give it a shot... # #ifeq ($(shell $(CC) -ffunction-sections -fdata-sections -S \ - # -o /dev/null -xc /dev/null && $(LD) --gc-sections -v >/dev/null && echo 1),1) - # CFLAGS += -ffunction-sections -fdata-sections -DFUNCTION_SECTIONS - # LDFLAGS += --gc-sections + # -o /dev/null -xc /dev/null 2>/dev/null && $(LD) --gc-sections -v >/dev/null && echo 1),1) + # CFLAGS += -ffunction-sections -fdata-sections + # LDFLAGS += --gc-sections #endif - # endif endif @@ -77,6 +78,7 @@ ifndef $(PREFIX) PREFIX = `pwd`/_install endif + LIBRARIES = OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o CFLAGS += -DBB_VER='"$(VERSION)"' diff --git a/coreutils/date.c b/coreutils/date.c index dd054be66..67d61a510 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -181,7 +181,7 @@ int date_main(int argc, char **argv) set_time = 1; if (date_str != NULL) usage(date_usage); - date_str = optarg; + date_str = *argv; break; case 'u': utc = 1; @@ -192,7 +192,7 @@ int date_main(int argc, char **argv) use_arg = 1; if (date_str != NULL) usage(date_usage); - date_str = optarg; + date_str = *argv; break; case '-': usage(date_usage); diff --git a/date.c b/date.c index dd054be66..67d61a510 100644 --- a/date.c +++ b/date.c @@ -181,7 +181,7 @@ int date_main(int argc, char **argv) set_time = 1; if (date_str != NULL) usage(date_usage); - date_str = optarg; + date_str = *argv; break; case 'u': utc = 1; @@ -192,7 +192,7 @@ int date_main(int argc, char **argv) use_arg = 1; if (date_str != NULL) usage(date_usage); - date_str = optarg; + date_str = *argv; break; case '-': usage(date_usage); diff --git a/dutmp.c b/dutmp.c index fab1a7b99..f264fd75b 100644 --- a/dutmp.c +++ b/dutmp.c @@ -8,22 +8,20 @@ * versions of 'who', 'last', etc. IP Addr is output in hex, * little endian on x86. * - * made against libc6 + * Modified to support all sort of libcs by + * Erik Andersen */ #include "internal.h" -#include +#include +#include +#include + #include #define BB_DECLARE_EXTERN #define bb_need_io_error #include "messages.c" - -#if defined(__GLIBC__) #include -#else -#include -#define utmp new_utmp -#endif static const char dutmp_usage[] = "dutmp [FILE]\n" @@ -36,27 +34,26 @@ static const char dutmp_usage[] = "dutmp [FILE]\n" extern int dutmp_main(int argc, char **argv) { - FILE *f; + int file; struct utmp ut; if (argc<2) { - f = stdin; + file = fileno(stdin); } else if (*argv[1] == '-' ) { usage(dutmp_usage); } else { - f = fopen(argv[1], "r"); - if (f == NULL) { + file = open(argv[1], O_RDONLY); + if (file < 0) { fatalError(io_error, argv[1], strerror(errno)); } } - while (fread(&ut, sizeof(struct utmp), 1, f)) { - printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", - ut.ut_type, ut.ut_pid, ut.ut_line, - ut.ut_id, ut.ut_user, ut.ut_host, - ut.ut_exit.e_termination, ut.ut_exit.e_exit, - ut.ut_session, ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, - ut.ut_addr_v6[0]); + while (read(file, (void*)&ut, sizeof(struct utmp))) { + printf("%d|%d|%s|%s|%s|%s|%s|%lx\n", + ut.ut_type, ut.ut_pid, ut.ut_line, + ut.ut_id, ut.ut_user, ut.ut_host, + ctime(&(ut.ut_time)), + (long)ut.ut_addr); } exit(TRUE); diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c index fab1a7b99..f264fd75b 100644 --- a/miscutils/dutmp.c +++ b/miscutils/dutmp.c @@ -8,22 +8,20 @@ * versions of 'who', 'last', etc. IP Addr is output in hex, * little endian on x86. * - * made against libc6 + * Modified to support all sort of libcs by + * Erik Andersen */ #include "internal.h" -#include +#include +#include +#include + #include #define BB_DECLARE_EXTERN #define bb_need_io_error #include "messages.c" - -#if defined(__GLIBC__) #include -#else -#include -#define utmp new_utmp -#endif static const char dutmp_usage[] = "dutmp [FILE]\n" @@ -36,27 +34,26 @@ static const char dutmp_usage[] = "dutmp [FILE]\n" extern int dutmp_main(int argc, char **argv) { - FILE *f; + int file; struct utmp ut; if (argc<2) { - f = stdin; + file = fileno(stdin); } else if (*argv[1] == '-' ) { usage(dutmp_usage); } else { - f = fopen(argv[1], "r"); - if (f == NULL) { + file = open(argv[1], O_RDONLY); + if (file < 0) { fatalError(io_error, argv[1], strerror(errno)); } } - while (fread(&ut, sizeof(struct utmp), 1, f)) { - printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", - ut.ut_type, ut.ut_pid, ut.ut_line, - ut.ut_id, ut.ut_user, ut.ut_host, - ut.ut_exit.e_termination, ut.ut_exit.e_exit, - ut.ut_session, ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, - ut.ut_addr_v6[0]); + while (read(file, (void*)&ut, sizeof(struct utmp))) { + printf("%d|%d|%s|%s|%s|%s|%s|%lx\n", + ut.ut_type, ut.ut_pid, ut.ut_line, + ut.ut_id, ut.ut_user, ut.ut_host, + ctime(&(ut.ut_time)), + (long)ut.ut_addr); } exit(TRUE); diff --git a/miscutils/mt.c b/miscutils/mt.c index 28922f8d9..44f23884c 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c @@ -61,7 +61,7 @@ extern int mt_main(int argc, char **argv) struct mtop op; int fd; - if ((argc != 2 && argc != 3) || **(argv + 1) == '-') { + if ((argc != 2 && argc != 3) && **(argv + 1) != '-') { usage(mt_usage); } diff --git a/mt.c b/mt.c index 28922f8d9..44f23884c 100644 --- a/mt.c +++ b/mt.c @@ -61,7 +61,7 @@ extern int mt_main(int argc, char **argv) struct mtop op; int fd; - if ((argc != 2 && argc != 3) || **(argv + 1) == '-') { + if ((argc != 2 && argc != 3) && **(argv + 1) != '-') { usage(mt_usage); } -- 2.25.1