test for pread and use it instead of lseek+read in cdb and io_mmapwritefile
This commit is contained in:
12
cdb/cdb.c
12
cdb/cdb.c
@@ -6,6 +6,7 @@
|
||||
#include <errno.h>
|
||||
#include "byte.h"
|
||||
#include "cdb.h"
|
||||
#include "havepread.h"
|
||||
#ifdef __MINGW32__
|
||||
#include "windows.h"
|
||||
#else
|
||||
@@ -63,16 +64,25 @@ int cdb_read(struct cdb *c,unsigned char *buf,unsigned long len,uint32 pos) {
|
||||
byte_copy(buf,len,c->map + pos);
|
||||
}
|
||||
else {
|
||||
#ifndef HAVE_PREAD
|
||||
if (lseek(c->fd,pos,SEEK_SET) == -1) return -1;
|
||||
#endif
|
||||
while (len > 0) {
|
||||
int r;
|
||||
ssize_t r;
|
||||
do
|
||||
#ifdef HAVE_PREAD
|
||||
r = pread(c->fd,buf,len,pos);
|
||||
#else
|
||||
r = read(c->fd,buf,len);
|
||||
#endif
|
||||
while ((r == -1) && (errno == EINTR));
|
||||
if (r == -1) return -1;
|
||||
if (r == 0) goto FORMAT;
|
||||
buf += r;
|
||||
len -= r;
|
||||
#ifdef HAVE_PREAD
|
||||
pos += r;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user