home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dos / io / dosio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-24  |  1.4 KB  |  59 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <dpmi.h>
  6.  
  7. #include <libc/dosio.h>
  8. #include <libc/bss.h>
  9.  
  10. static char init_file_handle_modes[20] = {
  11.   O_TEXT,
  12.   O_TEXT,
  13.   O_TEXT,
  14.   O_BINARY,
  15.   O_BINARY
  16. };
  17.  
  18. static int dosio_bss_count = -1;
  19. static size_t count=20;    /* DOS default limit */
  20.  
  21. char *__file_handle_modes = init_file_handle_modes;
  22.  
  23. void
  24. __file_handle_set(int fd, int mode)
  25. {
  26.   __dpmi_regs r;
  27.  
  28.   if (dosio_bss_count != __bss_count)
  29.   {
  30.     dosio_bss_count = __bss_count;
  31.     count = 20;
  32.     __file_handle_modes = init_file_handle_modes;
  33.   }
  34.  
  35.   /* Check for bogus values */
  36.   if (fd < 0)
  37.     return;
  38.  
  39.   /* See if we need to expand the tables.  Check this BEFORE it might fail,
  40.      so that when we hit the count'th request, we've already up'd it. */
  41.   if (fd >= (count-1) && count < 255)
  42.   {
  43.     int oldcount = count;
  44.     count = 255;
  45.  
  46.     __file_handle_modes = (char *)malloc(count * sizeof(*__file_handle_modes));
  47.     memcpy(__file_handle_modes, init_file_handle_modes, sizeof(init_file_handle_modes));
  48.     memset(__file_handle_modes + oldcount, 0, (count-oldcount)*sizeof(__file_handle_modes[0]));
  49.  
  50.     /* Tell DOS to allow more */
  51.     r.h.ah = 0x67;
  52.     r.x.bx = count;
  53.     __dpmi_int(0x21, &r);
  54.   }
  55.  
  56.   /* Fill in the value */
  57.   __file_handle_modes[fd] = mode;
  58. }
  59.