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

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