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 / _creat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-25  |  940 b   |  47 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.  
  17.   if (filename == 0)
  18.   {
  19.     errno = EINVAL;
  20.     return -1;
  21.   }
  22.  
  23.   if (__FSEXT_call_open_handlers(__FSEXT_creat, &rv, &filename))
  24.     return rv;
  25.  
  26.   _put_path(filename);
  27.   if(_USE_LFN) {
  28.     r.x.ax = 0x716c;
  29.     r.x.bx = 0x0002;        /* open r/w */
  30.     r.x.dx = 0x0012;        /* Create, truncate if exists */
  31.     r.x.si = __tb_offset;
  32.   } else {
  33.     r.h.ah = 0x3c;
  34.     r.x.dx = __tb_offset;
  35.   }
  36.   r.x.cx = attrib;
  37.   r.x.ds = __tb_segment;
  38.   __dpmi_int(0x21, &r);
  39.   if(r.x.flags & 1)
  40.   {
  41.     errno = __doserr_to_errno(r.x.ax);
  42.     return -1;
  43.   }
  44.   __file_handle_set(r.x.ax, O_BINARY);
  45.   return r.x.ax;
  46. }
  47.