Some updates for better portability.
authorErik Andersen <andersen@codepoet.org>
Tue, 16 May 2000 20:07:38 +0000 (20:07 -0000)
committerErik Andersen <andersen@codepoet.org>
Tue, 16 May 2000 20:07:38 +0000 (20:07 -0000)
 -Erik

Makefile
coreutils/date.c
date.c
dutmp.c
miscutils/dutmp.c
miscutils/mt.c
mt.c

index e9192f9484db05bc19c55e1800fcdb6ce27b8d0b..d3d71ad77186793f6474dc2384cb6575355d5768 100644 (file)
--- 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)"'
index dd054be6634c650066bbd95155339f7f036f1868..67d61a5101282607dfd25afba08be0ee2d515f53 100644 (file)
@@ -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 dd054be6634c650066bbd95155339f7f036f1868..67d61a5101282607dfd25afba08be0ee2d515f53 100644 (file)
--- 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 fab1a7b994b57c36c17af215682805834b8521e4..f264fd75bfbd8c01808b5d215a655704acbca3f5 100644 (file)
--- 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 <andersen@lineo.com>
  */
 
 #include "internal.h"
-#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include <errno.h>
 #define BB_DECLARE_EXTERN
 #define bb_need_io_error
 #include "messages.c"
-
-#if defined(__GLIBC__)
 #include <utmp.h>
-#else
-#include <utmp-wrap.h>
-#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);
index fab1a7b994b57c36c17af215682805834b8521e4..f264fd75bfbd8c01808b5d215a655704acbca3f5 100644 (file)
@@ -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 <andersen@lineo.com>
  */
 
 #include "internal.h"
-#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include <errno.h>
 #define BB_DECLARE_EXTERN
 #define bb_need_io_error
 #include "messages.c"
-
-#if defined(__GLIBC__)
 #include <utmp.h>
-#else
-#include <utmp-wrap.h>
-#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);
index 28922f8d9227d73ad88d16fac0741ed90dd0eb5c..44f23884c5d61e5ad1dc0bda981c2b22f06b173c 100644 (file)
@@ -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 28922f8d9227d73ad88d16fac0741ed90dd0eb5c..44f23884c5d61e5ad1dc0bda981c2b22f06b173c 100644 (file)
--- 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);
        }