home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dos / io / _open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-31  |  1.0 KB  |  51 lines

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