1 |
greg |
3.1 |
#ifndef lint |
2 |
greg |
3.3 |
static const char RCSid[] = "$Id: preadwrite.c,v 3.2 2003/10/20 16:01:55 greg Exp $"; |
3 |
greg |
3.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Substitute routines for pread(2) and pwrite(2) |
6 |
|
|
*/ |
7 |
|
|
|
8 |
greg |
3.2 |
#include "platform.h" |
9 |
greg |
3.1 |
|
10 |
|
|
|
11 |
|
|
int |
12 |
|
|
pread(fd, buf, siz, offs) /* read buffer from an open file */ |
13 |
|
|
int fd; |
14 |
|
|
char *buf; |
15 |
|
|
unsigned int siz; |
16 |
greg |
3.2 |
long offs; |
17 |
greg |
3.1 |
{ |
18 |
greg |
3.2 |
if (lseek(fd, (off_t)offs, SEEK_SET) != offs) |
19 |
greg |
3.1 |
return(-1); |
20 |
|
|
return(read(fd, buf, siz)); |
21 |
|
|
/* technically, we should reset pointer here */ |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
int |
26 |
|
|
pwrite(fd, buf, siz, offs) /* write buffer to an open file */ |
27 |
|
|
int fd; |
28 |
|
|
char *buf; |
29 |
|
|
unsigned int siz; |
30 |
greg |
3.2 |
long offs; |
31 |
greg |
3.1 |
{ |
32 |
greg |
3.2 |
if (lseek(fd, (off_t)offs, SEEK_SET) != offs) |
33 |
greg |
3.1 |
return(-1); |
34 |
|
|
return(write(fd, buf, siz)); |
35 |
|
|
/* technically, we should reset pointer here */ |
36 |
|
|
} |