home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / IO / PCLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  570 b   |  26 lines

  1. /* pclose.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <process.h>
  6. #include <errno.h>
  7.  
  8. int pclose (FILE *stream)
  9. {
  10.   int rc, write_mode;
  11.  
  12.   if (!(stream->flags & _IOOPEN))
  13.     {
  14.       errno = EBADF;
  15.       return (-1);
  16.     }
  17.   write_mode = (stream->flags & _IOWRT);
  18.   if (write_mode && fclose (stream) != 0)
  19.     return (-1);
  20.   if (waitpid (stream->pid, &rc, 0) == -1)
  21.     return (-1);
  22.   if (!write_mode && fclose (stream) != 0 && errno != EBADF)
  23.     return (-1);
  24.   return (rc);
  25. }
  26.