Remove #ifdefs around code using pread(3) and pwrite(3).

This commit is contained in:
Todd C. Miller
2021-01-02 10:43:34 -07:00
parent 06bfbecd64
commit 6e1986e915
3 changed files with 2 additions and 26 deletions

View File

@@ -591,11 +591,10 @@ iolog_open(struct iolog_file *iol, int dfd, int iofd, const char *mode)
iol->compressed = iolog_compress;
} else {
/* check for gzip magic number */
if (read(fd, magic, sizeof(magic)) == ssizeof(magic)) {
if (pread(fd, magic, sizeof(magic), 0) == ssizeof(magic)) {
if (magic[0] == gzip_magic[0] && magic[1] == gzip_magic[1])
iol->compressed = true;
}
(void)lseek(fd, 0, SEEK_SET);
}
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
#ifdef HAVE_ZLIB_H

View File

@@ -115,14 +115,10 @@ is_script(int fd)
char magic[2];
debug_decl(is_script, SUDOERS_DEBUG_MATCH);
if (read(fd, magic, 2) == 2) {
if (pread(fd, magic, 2, 0) == 2) {
if (magic[0] == '#' && magic[1] == '!')
ret = true;
}
if (lseek(fd, (off_t)0, SEEK_SET) == -1) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO|SUDO_DEBUG_LINENO,
"unable to rewind script fd");
}
debug_return_int(ret);
}

View File

@@ -307,17 +307,7 @@ ts_write(int fd, const char *fname, struct timestamp_entry *entry, off_t offset)
nwritten = write(fd, entry, entry->size);
} else {
old_eof = offset;
#ifdef HAVE_PWRITE
nwritten = pwrite(fd, entry, entry->size, offset);
#else
if (lseek(fd, offset, SEEK_SET) == -1) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO|SUDO_DEBUG_LINENO,
"unable to seek to %lld", (long long)offset);
nwritten = -1;
} else {
nwritten = write(fd, entry, entry->size);
}
#endif
}
if ((size_t)nwritten != entry->size) {
if (nwritten == -1) {
@@ -577,16 +567,7 @@ ts_read(struct ts_cookie *cookie, struct timestamp_entry *entry)
}
/* Seek to the record position and read it. */
#ifdef HAVE_PREAD
nread = pread(cookie->fd, entry, sizeof(*entry), cookie->pos);
#else
if (lseek(cookie->fd, cookie->pos, SEEK_SET) == -1) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO|SUDO_DEBUG_LINENO,
"unable to seek to %lld", (long long)cookie->pos);
goto done;
}
nread = read(cookie->fd, entry, sizeof(*entry));
#endif
if (nread != sizeof(*entry)) {
/* short read, should not happen */
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,