_off64_t _lseek64_r (struct _reent *ptr, int fd, _off64_t pos, int whence) { _off64_t ret; errno = 0; if ((ret = _lseek64 (fd, pos, whence)) == (_off64_t) -1 && errno != 0) ptr->_errno = errno; return ret; }
int sopen(const char *name, int oflag, int shflag, int mask) { int fail_errno; APIRET rc = 0; HFILE hf = 0; ULONG ulAction = 0; LONGLONG cbFile = 0; ULONG ulAttribute = FILE_NORMAL; ULONG fsOpenFlags = 0; ULONG fsOpenMode = 0; /* Extract the access mode and sharing mode bits. */ fsOpenMode = (shflag & 0xFF) | (oflag & 0x03); /* Translate ERROR_OPEN_FAILED to ENOENT unless O_EXCL is set (see below). */ fail_errno = ENOENT; /* Compute `open_flag' depending on `flags'. Note that _SO_CREAT is set for O_CREAT. */ if (oflag & O_CREAT) { if (oflag & O_EXCL) { fsOpenFlags = OPEN_ACTION_FAIL_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW; fail_errno = EEXIST; } else if (oflag & O_TRUNC) fsOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW; else fsOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW; if (mask & S_IWRITE) ulAttribute = FILE_NORMAL; else ulAttribute = FILE_READONLY; } else if (oflag & O_TRUNC) fsOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW; else fsOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW; /* Try to open the file and handle errors. */ if (_DosOpenL) rc = _DosOpenL( name, &hf, &ulAction, cbFile, ulAttribute, fsOpenFlags, fsOpenMode, NULL); else rc = DosOpen( name, &hf, &ulAction, (LONG) cbFile, ulAttribute, fsOpenFlags, fsOpenMode, NULL); if (rc == ERROR_OPEN_FAILED) { errno = fail_errno; return -1; } if (rc != 0) { _OS2errno( rc); /* set errno */ return -1; } if (oflag & O_APPEND) _lseek64( hf, 0L, SEEK_END); return hf; }