aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tls/compat/pread.c14
-rw-r--r--tls/compat/pwrite.c14
2 files changed, 18 insertions, 10 deletions
diff --git a/tls/compat/pread.c b/tls/compat/pread.c
index b9d6b09..0b994f4 100644
--- a/tls/compat/pread.c
+++ b/tls/compat/pread.c
@@ -8,21 +8,25 @@
8 8
9#define NO_REDEF_POSIX_FUNCTIONS 9#define NO_REDEF_POSIX_FUNCTIONS
10 10
11#include <errno.h>
11#include <unistd.h> 12#include <unistd.h>
12 13
13ssize_t 14ssize_t
14pread(int d, void *buf, size_t nbytes, off_t offset) 15pread(int d, void *buf, size_t nbytes, off_t offset)
15{ 16{
16 off_t cpos, opos, rpos; 17 off_t cpos;
17 ssize_t bytes; 18 ssize_t bytes;
19 int save_errno;
20
18 if((cpos = lseek(d, 0, SEEK_CUR)) == -1) 21 if((cpos = lseek(d, 0, SEEK_CUR)) == -1)
19 return -1; 22 return -1;
20 if((opos = lseek(d, offset, SEEK_SET)) == -1) 23 if(lseek(d, offset, SEEK_SET) == -1)
21 return -1;
22 if((bytes = read(d, buf, nbytes)) == -1)
23 return -1; 24 return -1;
24 if((rpos = lseek(d, cpos, SEEK_SET)) == -1) 25 bytes = read(d, buf, nbytes);
26 save_errno = errno;
27 if(lseek(d, cpos, SEEK_SET) == -1)
25 return -1; 28 return -1;
29 errno = save_errno;
26 return bytes; 30 return bytes;
27} 31}
28 32
diff --git a/tls/compat/pwrite.c b/tls/compat/pwrite.c
index 82f5f55..ab88241 100644
--- a/tls/compat/pwrite.c
+++ b/tls/compat/pwrite.c
@@ -8,21 +8,25 @@
8 8
9#define NO_REDEF_POSIX_FUNCTIONS 9#define NO_REDEF_POSIX_FUNCTIONS
10 10
11#include <errno.h>
11#include <unistd.h> 12#include <unistd.h>
12 13
13ssize_t 14ssize_t
14pwrite(int d, const void *buf, size_t nbytes, off_t offset) 15pwrite(int d, const void *buf, size_t nbytes, off_t offset)
15{ 16{
16 off_t cpos, opos, rpos; 17 off_t cpos;
17 ssize_t bytes; 18 ssize_t bytes;
19 int save_errno;
20
18 if((cpos = lseek(d, 0, SEEK_CUR)) == -1) 21 if((cpos = lseek(d, 0, SEEK_CUR)) == -1)
19 return -1; 22 return -1;
20 if((opos = lseek(d, offset, SEEK_SET)) == -1) 23 if(lseek(d, offset, SEEK_SET) == -1)
21 return -1;
22 if((bytes = write(d, buf, nbytes)) == -1)
23 return -1; 24 return -1;
24 if((rpos = lseek(d, cpos, SEEK_SET)) == -1) 25 bytes = write(d, buf, nbytes);
26 save_errno = errno;
27 if(lseek(d, cpos, SEEK_SET) == -1)
25 return -1; 28 return -1;
29 errno = save_errno;
26 return bytes; 30 return bytes;
27} 31}
28 32