Compatibility with OpenBSD. Thanks, Steve Dee!

This commit is contained in:
David Galos 2013-07-18 15:28:08 -04:00
parent cd1526715f
commit 0fcb939408
4 changed files with 22 additions and 17 deletions

View File

@ -88,10 +88,14 @@ OBJ = $(SRC:.c=.o) $(LIB)
BIN = $(SRC:.c=) BIN = $(SRC:.c=)
MAN = $(SRC:.c=.1) MAN = $(SRC:.c=.1)
all: $(BIN) all: binlib
binlib: util.a
$(MAKE) bin
bin: $(BIN)
$(OBJ): util.h config.mk $(OBJ): util.h config.mk
$(BIN): util.a
cat.o fold.o grep.o nl.o sort.o tail.o uniq.o: text.h cat.o fold.o grep.o nl.o sort.o tail.o uniq.o: text.h
cp.o mv.o rm.o: fs.h cp.o mv.o rm.o: fs.h

3
env.c
View File

@ -14,7 +14,8 @@ main(int argc, char **argv)
{ {
ARGBEGIN { ARGBEGIN {
case 'i': case 'i':
clearenv(); if(environ)
*environ = NULL;
break; break;
case 'u': case 'u':
unsetenv(EARGF(usage())); unsetenv(EARGF(usage()));

6
who.1
View File

@ -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 doesn't always happen, which can cause who to print completely
bogus data. bogus data.
musl\-libc currently implements all utmpx functions as stubs Obviously,
this command cannot work under such conditions.
.SH SEE ALSO .SH SEE ALSO
.IR getutxent (3) .IR utmp (5)
.IR utmpx (5)

22
who.c
View File

@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <utmpx.h> #include <utmp.h>
#include "util.h" #include "util.h"
static void usage(void); static void usage(void);
@ -11,21 +11,25 @@ static void usage(void);
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct utmpx *ut; struct utmp usr;
FILE *ufp;
time_t t; time_t t;
char timebuf[sizeof "yyyy-mm-dd hh:mm"]; char timebuf[sizeof "yyyy-mm-dd hh:mm"];
if(argc!=1) if(argc!=1)
usage(); usage();
while((ut=getutxent())) { if (!(ufp = fopen(_PATH_UTMP, "r"))) {
if(ut->ut_type != USER_PROCESS) eprintf("fopen:");
continue;
t = ut->ut_tv.tv_sec;
strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", localtime(&t));
printf("%-8s %-12s %-16s\n", ut->ut_user, ut->ut_line, timebuf);
} }
endutxent(); while(fread((char *)&usr, sizeof(usr), 1, ufp) == 1) {
if (!*usr.ut_name || !*usr.ut_line)
continue;
t = usr.ut_time;
strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", localtime(&t));
printf("%-8s %-12s %-16s\n", usr.ut_name, usr.ut_line, timebuf);
}
fclose(ufp);
return 0; return 0;
} }