[BACK]Return to head.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / head

Diff for /src/usr.bin/head/head.c between version 1.17 and 1.18

version 1.17, 2014/10/07 19:38:57 version 1.18, 2014/10/08 08:31:53
Line 48 
Line 48 
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
           FILE    *fp;
         long    cnt;          long    cnt;
         int     ch, firsttime;          int     ch, firsttime;
         long    linecnt = 10;          long    linecnt = 10;
Line 81 
Line 82 
                         errx(1, "line count %s: %s", errstr, p);                          errx(1, "line count %s: %s", errstr, p);
         }          }
   
         /* setlinebuf(stdout); */  
         for (firsttime = 1; ; firsttime = 0) {          for (firsttime = 1; ; firsttime = 0) {
                 if (!*argv) {                  if (!*argv) {
                         if (!firsttime)                          if (!firsttime)
                                 exit(status);                                  exit(status);
                           fp = stdin;
                 } else {                  } else {
                         if (!freopen(*argv, "r", stdin)) {                          if ((fp = fopen(*argv, "r")) == NULL) {
                                 warn("%s", *argv++);                                  warn("%s", *argv++);
                                 status = 1;                                  status = 1;
                                 continue;                                  continue;
Line 99 
Line 100 
                         }                          }
                         ++argv;                          ++argv;
                 }                  }
                 for (cnt = linecnt; cnt && !feof(stdin); --cnt)                  for (cnt = linecnt; cnt && !feof(fp); --cnt)
                         while ((ch = getchar()) != EOF)                          while ((ch = getc(fp)) != EOF)
                                 if (putchar(ch) == '\n')                                  if (putchar(ch) == '\n')
                                         break;                                          break;
                   fclose(fp);
         }          }
         /*NOTREACHED*/          /*NOTREACHED*/
 }  }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18