home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_01 / 1001014a < prev    next >
Text File  |  1991-11-18  |  632b  |  34 lines

  1. Listing 2 -- the file fopen.c
  2.  
  3.  
  4. /* fopen function */
  5. #include <stdlib.h>
  6. #include "xstdio.h"
  7.  
  8. FILE *(fopen)(const char *name, const char *mods)
  9.     {    /* open a file */
  10.     FILE *str;
  11.     size_t i;
  12.  
  13.     for (i = 0; i < FOPEN_MAX; ++i)
  14.         if (_Files[i] == NULL)
  15.             {    /* setup empty _Files[i] */
  16.             str = malloc(sizeof (FILE));
  17.             if (str == NULL)
  18.                 return (NULL);
  19.             _Files[i] = str;
  20.             str->_Mode = _MALFIL;
  21.             break;
  22.             }
  23.         else if (_Files[i]->_Mode == 0)
  24.             {    /* setup preallocated _Files[i] */
  25.             str = _Files[i];
  26.             break;
  27.             }
  28.     if (FOPEN_MAX <= i)
  29.         return (NULL);
  30.     return (_Foprep(name, mods, str));
  31.     }
  32.  
  33.  
  34.