bug in fgets?

From: Ken Kleiner <ken_at_cs.uml.edu>
Date: Mon, 27 Nov 2000 10:28:39 -0500 (EST)

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_at_cs.uml.edu
Received on Mon Nov 27 2000 - 15:29:50 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:41 NZDT