home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / perl5a1.lha / perl5alpha1 / do / close < prev    next >
Encoding:
Text File  |  1992-08-15  |  942 b   |  46 lines

  1. bool
  2. do_close(stab,explicit)
  3. STAB *stab;
  4. bool explicit;
  5. {
  6.     bool retval = FALSE;
  7.     register STIO *stio;
  8.     int status;
  9.  
  10.     if (!stab)
  11.     stab = argvstab;
  12.     if (!stab) {
  13.     errno = EBADF;
  14.     return FALSE;
  15.     }
  16.     stio = stab_io(stab);
  17.     if (!stio) {        /* never opened */
  18.     if (dowarn && explicit)
  19.         warn("Close on unopened file <%s>",stab_ename(stab));
  20.     return FALSE;
  21.     }
  22.     if (stio->ifp) {
  23.     if (stio->type == '|') {
  24.         status = mypclose(stio->ifp);
  25.         retval = (status == 0);
  26.         statusvalue = (unsigned short)status & 0xffff;
  27.     }
  28.     else if (stio->type == '-')
  29.         retval = TRUE;
  30.     else {
  31.         if (stio->ofp && stio->ofp != stio->ifp) {        /* a socket */
  32.         retval = (fclose(stio->ofp) != EOF);
  33.         fclose(stio->ifp);    /* clear stdio, fd already closed */
  34.         }
  35.         else
  36.         retval = (fclose(stio->ifp) != EOF);
  37.     }
  38.     stio->ofp = stio->ifp = Nullfp;
  39.     }
  40.     if (explicit)
  41.     stio->lines = 0;
  42.     stio->type = ' ';
  43.     return retval;
  44. }
  45.  
  46.