tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* bug in fgets?
@ 2000-11-27 15:28 Ken Kleiner
  0 siblings, 0 replies; only message in thread
From: Ken Kleiner @ 2000-11-27 15:28 UTC (permalink / raw)
  To: tru64-unix-managers

Hello...

  I am trying to determine if there is a bug in fgets - Compaq Tru64 5.0a.

  The attached code gets stuck in an infinite loop since fgets never
returns null and/or is not reading end of file.

  This does properly compile and run right on other unix boxes, such as
linux with gcc.

  Has anybody seen any information on this or experienced this?  Thanks
in advance....also please let me know if this is not an appropriate post
to this list.

CODE -------

/* 
 *
 * This example code demonstrates a bug with fgets() when using 
 * the fork() system call.  fgets() never returns NULL when it hits
 * the end of file, and therefore causes an infinite loop.
 * 
 * OSF1 V5.0 1094 alpha
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>



int main(int argc, char **argv) {
  FILE *fin;
  char buf[80];

  fin = fopen("/etc/passwd", "r");

  while (fgets(buf, 80, fin) != NULL) {
    printf ("%s", buf);

  }

  return 0;
}
    

-- 
Ken Kleiner
System Manager
Computer Science Department
Umass Lowell

voice : 978 934 3645
fax : 978 934 3551

ken@cs.uml.edu

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-11-27 15:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-27 15:28 bug in fgets? Ken Kleiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox