can someone please check this out, it makes "head -n" about five
times faster.  (also nukes a 'register', sorry :))


cvs diff: Diffing .
Index: head.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/head/head.c,v
retrieving revision 1.10
diff -c -r1.10 head.c
*** head.c      28 Aug 1999 01:01:58 -0000      1.10
--- head.c      2 Nov 2001 08:18:07 -0000
***************
*** 131,146 ****
  void
  head(fp, cnt)
        FILE *fp;
!       register int cnt;
  {
!       register int ch;
  
!       while (cnt && (ch = getc(fp)) != EOF) {
!                       if (putchar(ch) == EOF)
!                               err(1, "stdout");
!                       if (ch == '\n')
!                               cnt--;
!               }
  }
  
  void
--- 131,147 ----
  void
  head(fp, cnt)
        FILE *fp;
!       int cnt;
  {
!       char *cp;
!       int error, readlen;
  
!       while (cnt && (cp = fgetln(fp, &readlen)) != NULL) {
!               error = fwrite(cp, sizeof(char), readlen, stdout);
!               if (error != readlen)
!                       err(1, "stdout");
!               cnt--;
!       }
  }
  
  void


-- 
-Alfred Perlstein [[EMAIL PROTECTED]]
'Instead of asking why a piece of software is using "1970s technology,"
 start asking why software is ignoring 30 years of accumulated wisdom.'
                           http://www.morons.org/rants/gpl-harmful.php3

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to