2 Replies Latest reply: Nov 27, 2009 3:34 PM by 800381 RSS

    fgets from stdin - Bad file number

    807559
      Hello,

      Here is a sample code that is giving problems:
      while (true) {
         readBufPtr = fgets (buf, sizeof(buf), stdin);
         if (readBufPtr)
           syslog (LOG_INFO, buf);
         else if (EINTR != errno) {
           syslog (LOG_ERR, "[ESReadStdin] read from stdin failed. Reason: [%s]. Exiting.\n", strerror (errno));
           exit(-1);
         }
      }
      The fgets call gives the EBADF error and the program terminates saying :
      [ID 381367 local5.error] [ESReadStdin] read from stdin failed. Reason: [Bad file number]. Exiting

      Why would reading from stdin give an EBADF ? Is there any something I can check on the system. Note that this happening only on one machine.

      Thanks!