]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
who.c
authorJim Meyering <jim@meyering.net>
Tue, 28 Dec 1993 21:18:17 +0000 (21:18 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 28 Dec 1993 21:18:17 +0000 (21:18 +0000)
src/date.c
src/tee.c
src/who.c

index b6159f2092f992812689716d29d993bf806d38aa..2fe4783d48e2c51055a8b76ba8fb04dcc1250ce7 100644 (file)
@@ -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\
 ");
index 4cfa93ce1044445faf77c15aa7fade8cd0ca742e..316a4572d436440dd62b3865ef174c3b51fd6992 100644 (file)
--- a/src/tee.c
+++ b/src/tee.c
@@ -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)
index e885a342736a8db01a8304d26d87db6debb602d4..1e046993ede9601f95034bbfcb58439f2fdc148e 100644 (file)
--- a/src/who.c
+++ b/src/who.c
@@ -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) ? '+' : '-';