diff options
author | Jim Meyering <jim@meyering.net> | 1993-12-28 21:18:17 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1993-12-28 21:18:17 +0000 |
commit | 704a7eba4a17dd28daa9eecace2c741e3401c0bc (patch) | |
tree | 123baf7e6745756612b36d168fa29747fc32b3b6 /src | |
parent | 2db44d14e45b2ae891722bac76ddb6692494fce2 (diff) | |
download | coreutils-704a7eba4a17dd28daa9eecace2c741e3401c0bc.tar.xz |
who.c
Diffstat (limited to 'src')
-rw-r--r-- | src/date.c | 2 | ||||
-rw-r--r-- | src/tee.c | 9 | ||||
-rw-r--r-- | src/who.c | 33 |
3 files changed, 27 insertions, 17 deletions
diff --git a/src/date.c b/src/date.c index b6159f209..2fe4783d4 100644 --- a/src/date.c +++ b/src/date.c @@ -270,7 +270,7 @@ FORMAT controls the output. Interpreted sequences are:\n\ %%r time, 12-hour (hh:mm:ss [AP]M)\n\ %%s seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension)\n\ %%t a horizontal tab\n\ - %%w day of week (0..6)\n\ + %%w day of week (0..6); 0 represents Sunday\n\ %%x locale's date representation (mm/dd/yy)\n\ %%y last two digits of year (00..99)\n\ "); @@ -182,8 +182,15 @@ tee (nfiles, files) } } - while ((bytes_read = read (0, buffer, sizeof buffer)) > 0) + while (1) { + bytes_read = read (0, buffer, sizeof buffer); +#ifdef EINTR + if (bytes_read < 0 && errno == EINTR) + continue; +#endif + if (bytes_read <= 0) + break; xwrite (1, buffer, bytes_read); for (i = 0; i < nfiles; i++) if (descriptors[i] != -1) @@ -195,9 +195,6 @@ main (argc, argv) if (show_help) usage (0); - if (chdir ("/dev")) - error (1, errno, "cannot change directory to /dev"); - switch (argc - optind) { case 0: /* who */ @@ -249,27 +246,27 @@ static int read_utmp (filename) char *filename; { - register int desc; + FILE *utmp; struct stat file_stats; + int n_read; - desc = open (filename, O_RDONLY, 0); - if (desc < 0) + utmp = fopen (filename, "r"); + if (utmp == NULL) error (1, errno, "%s", filename); - fstat (desc, &file_stats); + fstat (fileno (utmp), &file_stats); if (file_stats.st_size > 0) utmp_contents = (STRUCT_UTMP *) xmalloc ((unsigned) file_stats.st_size); else { - close (desc); + fclose (utmp); return 0; } /* Use < instead of != in case the utmp just grew. */ - if (read (desc, utmp_contents, file_stats.st_size) < file_stats.st_size) - error (1, errno, "%s", filename); - - if (close (desc) != 0) + n_read = fread (utmp_contents, 1, file_stats.st_size, utmp); + if (ferror (utmp) || fclose (utmp) == EOF + || n_read < file_stats.st_size) error (1, errno, "%s", filename); return file_stats.st_size / sizeof (STRUCT_UTMP); @@ -284,10 +281,16 @@ print_entry (this) struct stat stats; time_t last_change; char mesg; - char line[sizeof (this->ut_line) + 1]; - strncpy (line, this->ut_line, sizeof (this->ut_line)); - line[sizeof (this->ut_line)] = 0; +#define DEV_DIR_WITH_TRAILING_SLASH "/dev/" +#define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1) + + char line[sizeof (this->ut_line) + DEV_DIR_LEN + 1]; + + strcpy(line, DEV_DIR_WITH_TRAILING_SLASH); + strncpy (line + DEV_DIR_LEN, this->ut_line, sizeof (this->ut_line)); + line[DEV_DIR_LEN + sizeof (this->ut_line)] = '\0'; + if (stat (line, &stats) == 0) { mesg = (stats.st_mode & S_IWGRP) ? '+' : '-'; |