home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / dos / io / _open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-25  |  945 b   |  49 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <errno.h>
  6. #include <go32.h>
  7. #include <dpmi.h>
  8. #include <io.h>
  9. #include <libc/dosio.h>
  10. #include <sys/fsext.h>
  11.  
  12. int
  13. _open(const char* filename, int oflag)
  14. {
  15.   __dpmi_regs r;
  16.   int rv;
  17.  
  18.   if (filename == 0)
  19.   {
  20.     errno = EINVAL;
  21.     return -1;
  22.   }
  23.  
  24.   if (__FSEXT_call_open_handlers(__FSEXT_open, &rv, &filename))
  25.     return rv;
  26.  
  27.   _put_path(filename);
  28.   if(_USE_LFN) {
  29.     r.x.ax = 0x716c;
  30.     r.x.bx = oflag;
  31.     r.x.dx = 1;            /* Open existing file */
  32.     r.x.si = __tb_offset;
  33.   } else {
  34.     r.h.ah = 0x3d;
  35.     r.h.al = oflag;
  36.     r.x.dx = __tb_offset;
  37.   }
  38.   r.x.cx = 0;
  39.   r.x.ds = __tb_segment;
  40.   __dpmi_int(0x21, &r);
  41.   if(r.x.flags & 1)
  42.   {
  43.     errno = __doserr_to_errno(r.x.ax);
  44.     return -1;
  45.   }
  46.   __file_handle_set(r.x.ax, O_BINARY);
  47.   return r.x.ax;
  48. }
  49.