home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / nfiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  956 b   |  59 lines

  1. /* nfiles.c (emx+gcc) */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <io.h>
  7. #include <fcntl.h>
  8.  
  9. static int verbose = 0;
  10.  
  11. static int nstreams (void)
  12. {
  13.   FILE *f;
  14.   int i;
  15.  
  16.   f = fopen ("nul", "r");
  17.   if (f == NULL)
  18.     {
  19.       if (verbose)
  20.         putchar ('\n');
  21.       return (0);
  22.     }
  23.   if (verbose)
  24.     printf ("%d ", fileno (f));
  25.   i = nstreams () + 1;
  26.   fclose (f);
  27.   return (i);
  28. }
  29.  
  30.  
  31. static int nhandles (void)
  32. {
  33.   int h, i;
  34.  
  35.   h = open ("nul", O_RDONLY);
  36.   if (h < 0)
  37.     {
  38.       if (verbose)
  39.         putchar ('\n');
  40.       return (0);
  41.     }
  42.   if (verbose)
  43.     printf ("%d ", h);
  44.   i = nhandles () + 1;
  45.   close (h);
  46.   return (i);
  47. }
  48.  
  49.  
  50. int main (int argc, char *argv[])
  51. {
  52.   if (argc == 2 && strcmp (argv[1], "-v") == 0)
  53.     verbose = 1;
  54.   printf ("_nfiles=%d\n", _nfiles);
  55.   printf ("%d handles\n", nhandles ());
  56.   printf ("%d streams\n", nstreams ());
  57.   return (0);
  58. }
  59.