[hackers] [sbase] Compatibility with OpenBSD. Thanks, Steve Dee! || David Galos

From: <git_AT_suckless.org>
Date: Thu, 18 Jul 2013 21:35:56 +0200

commit 0fcb939408ceeeae238e596c6f4ef06193b36949
Author: David Galos <galosd83_AT_students.rowan.edu>
Date: Thu Jul 18 15:28:08 2013 -0400

    Compatibility with OpenBSD. Thanks, Steve Dee!

diff --git a/Makefile b/Makefile
index 2bb244d..bd0c38c 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -88,10 +88,14 @@ OBJ = $(SRC:.c=.o) $(LIB)
 BIN = $(SRC:.c=)
 MAN = $(SRC:.c=.1)
 
-all: $(BIN)
+all: binlib
+
+binlib: util.a
+ $(MAKE) bin
+
+bin: $(BIN)
 
 $(OBJ): util.h config.mk
-$(BIN): util.a
 cat.o fold.o grep.o nl.o sort.o tail.o uniq.o: text.h
 cp.o mv.o rm.o: fs.h
 
diff --git a/env.c b/env.c
index 718b13e..ca497e9 100644
--- a/env.c
+++ b/env.c
_AT_@ -14,7 +14,8 @@ main(int argc, char **argv)
 {
         ARGBEGIN {
         case 'i':
- clearenv();
+ if(environ)
+ *environ = NULL;
                 break;
         case 'u':
                 unsetenv(EARGF(usage()));
diff --git a/who.1 b/who.1
index 68ca7f1..d9c9f47 100644
--- a/who.1
+++ b/who.1
_AT_@ -15,10 +15,6 @@ relies on the utmp file to be updated responsibly. This
 doesn't always happen, which can cause who to print completely
 bogus data.
 
-musl\-libc currently implements all utmpx functions as stubs Obviously,
-this command cannot work under such conditions.
-
 .SH SEE ALSO
-.IR getutxent (3)
-.IR utmpx (5)
+.IR utmp (5)
 
diff --git a/who.c b/who.c
index 08c3c2b..dfc3c1e 100644
--- a/who.c
+++ b/who.c
_AT_@ -3,7 +3,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <time.h>
-#include <utmpx.h>
+#include <utmp.h>
 #include "util.h"
 
 static void usage(void);
_AT_@ -11,21 +11,25 @@ static void usage(void);
 int
 main(int argc, char **argv)
 {
- struct utmpx *ut;
+ struct utmp usr;
+ FILE *ufp;
         time_t t;
         char timebuf[sizeof "yyyy-mm-dd hh:mm"];
 
         if(argc!=1)
                 usage();
 
- while((ut=getutxent())) {
- if(ut->ut_type != USER_PROCESS)
+ if (!(ufp = fopen(_PATH_UTMP, "r"))) {
+ eprintf("fopen:");
+ }
+ while(fread((char *)&usr, sizeof(usr), 1, ufp) == 1) {
+ if (!*usr.ut_name || !*usr.ut_line)
                         continue;
- t = ut->ut_tv.tv_sec;
+ t = usr.ut_time;
                 strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", localtime(&t));
- printf("%-8s %-12s %-16s
", ut->ut_user, ut->ut_line, timebuf);
+ printf("%-8s %-12s %-16s
", usr.ut_name, usr.ut_line, timebuf);
         }
- endutxent();
+ fclose(ufp);
         return 0;
 }
 
Received on Thu Jul 18 2013 - 21:35:56 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 18 2013 - 21:36:15 CEST