/*--------------------------------------------------------------------------* Name _dos_commit - commit a file handle Usage unsigned _dos_commit(int handle); Prototype in io.h Description _dos_commit commits the file handle indicated by handle which is obtained from a _dos_creat, _dos_creatnew, or _dos_open call. Return value Upon successful completion, _dos_commit returns 0. Otherwise, the DOS error code is returned, and errno is set to EBADF Bad file number *---------------------------------------------------------------------------*/ unsigned _dos_commit( int fd ) { _AH = 0x68; _BX = fd; geninterrupt(0x21); if (_FLAGS & 1) /* if carry set, error */ return (__DOSerror(_AX)); /* set errno */ else return (0); }
/*-----------------------------------------------------------------------* Name _dos_unlock - resets file sharing locks Usage int _dos_unlock(int handle, long offset, long length); Related functions usage unsigned _dos_lock(int handle, long offset, long length); Prototype in none Description see _dos_lock above Return value see _dos_lock above *------------------------------------------------------------------------*/ unsigned _dos_unlock(int handle, long offset, long length) { _BX = handle; _CX = FP_SEG(offset); _DX = FP_OFF(offset); _SI = FP_SEG(length); _DI = FP_OFF(length); _AX = 0x5c01; geninterrupt(0x21); if (_FLAGS & 1) /* if carry set, error */ return (__DOSerror(_AX)); /* set errno */ else return (0); }
unsigned _RTLENTRY _EXPFUNC _dos_read (int fd, void *buf, unsigned len, unsigned *nread) { DWORD actual; if ((unsigned)fd >= _nfile) { __IOerror(ERROR_INVALID_HANDLE); /* set errno */ return (ERROR_INVALID_HANDLE); /* return fake NT error code */ } if (ReadFile((HANDLE)_handles[fd], buf, (DWORD)len, &actual, NULL) != TRUE) return (__DOSerror()); else { *nread = (unsigned)actual; return (0); } }
unsigned _tDosCreate(_TCHAR *pathP, unsigned attr, int *handlep, unsigned disp) { HANDLE handle; SECURITY_ATTRIBUTES sec; /* used only to set inheritance flag */ unsigned rc, oflag; /* Set the inheritance flag in the security attributes. */ sec.nLength = sizeof(sec); sec.lpSecurityDescriptor = NULL; sec.bInheritHandle = TRUE; /* Create the file. */ if ((handle = CreateFile(pathP, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, &sec, disp, attr, NULL)) == (HANDLE)-1) return (__DOSerror()); /* Save the open flags and find free file handle table slot. * Save the NT file handle in the table, return the table index. */ oflag = O_BINARY; if (__isatty_osfhandle((long)handle)) oflag |= O_DEVICE; if ((attr & FILE_ATTRIBUTE_READONLY) == 0) oflag |= _O_WRITABLE; /* fstat() uses this bit */ _lock_all_handles(); if ((*handlep = _get_handle((long)handle, oflag)) == -1) { __IOerror(rc = ERROR_TOO_MANY_OPEN_FILES); CloseHandle(handle); DeleteFile(pathP); } else rc = 0; _unlock_all_handles(); return rc; }