Commit f1a0de99 authored by Alexandre Julliard's avatar Alexandre Julliard

Added configure check for pread/pwrite.

parent 99a5cfea
...@@ -818,6 +818,8 @@ AC_CHECK_FUNCS(\ ...@@ -818,6 +818,8 @@ AC_CHECK_FUNCS(\
lstat \ lstat \
memmove \ memmove \
mmap \ mmap \
pread \
pwrite \
rfork \ rfork \
select \ select \
sendmsg \ sendmsg \
......
...@@ -121,6 +121,12 @@ ...@@ -121,6 +121,12 @@
/* Define if you have the openpty function. */ /* Define if you have the openpty function. */
#undef HAVE_OPENPTY #undef HAVE_OPENPTY
/* Define if you have the pread function. */
#undef HAVE_PREAD
/* Define if you have the pwrite function. */
#undef HAVE_PWRITE
/* Define if you have the resizeterm function. */ /* Define if you have the resizeterm function. */
#undef HAVE_RESIZETERM #undef HAVE_RESIZETERM
......
...@@ -14,6 +14,7 @@ extern "C" { ...@@ -14,6 +14,7 @@ extern "C" {
*/ */
typedef enum tagLOCKTYPE typedef enum tagLOCKTYPE
{ {
#undef LOCK_WRITE
LOCK_WRITE = 1, LOCK_WRITE = 1,
LOCK_EXCLUSIVE = 2, LOCK_EXCLUSIVE = 2,
LOCK_ONLYONCE = 4 LOCK_ONLYONCE = 4
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# error You must include config.h to use this header # error You must include config.h to use this header
#endif #endif
#define _GNU_SOURCE /* for pread/pwrite */
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
...@@ -135,6 +136,14 @@ int usleep (unsigned int useconds); ...@@ -135,6 +136,14 @@ int usleep (unsigned int useconds);
int lstat(const char *file_name, struct stat *buf); int lstat(const char *file_name, struct stat *buf);
#endif /* HAVE_LSTAT */ #endif /* HAVE_LSTAT */
#ifndef HAVE_PREAD
ssize_t pread( int fd, void *buf, size_t count, off_t offset );
#endif /* HAVE_PREAD */
#ifndef HAVE_PWRITE
ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
#endif /* HAVE_PWRITE */
#ifndef S_ISLNK #ifndef S_ISLNK
#define S_ISLNK(mod) (0) #define S_ISLNK(mod) (0)
#endif /* S_ISLNK */ #endif /* S_ISLNK */
......
...@@ -379,6 +379,59 @@ int lstat(const char *file_name, struct stat *buf) ...@@ -379,6 +379,59 @@ int lstat(const char *file_name, struct stat *buf)
} }
#endif /* HAVE_LSTAT */ #endif /* HAVE_LSTAT */
/***********************************************************************
* pread
*
* FIXME: this is not thread-safe
*/
#ifndef HAVE_PREAD
ssize_t pread( int fd, void *buf, size_t count, off_t offset )
{
ssize_t ret;
off_t old_pos;
if ((old_pos = lseek( fd, 0, SEEK_CUR )) == -1) return -1;
if (lseek( fd, offset, SEEK_SET ) == -1) return -1;
if ((ret = read( fd, buf, count )) == -1)
{
int err = errno; /* save errno */
lseek( fd, old_pos, SEEK_SET );
errno = err;
return -1;
}
if (lseek( fd, old_pos, SEEK_SET ) == -1) return -1;
return ret;
}
#endif /* HAVE_PREAD */
/***********************************************************************
* pwrite
*
* FIXME: this is not thread-safe
*/
#ifndef HAVE_PWRITE
ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset )
{
ssize_t ret;
off_t old_pos;
if ((old_pos = lseek( fd, 0, SEEK_CUR )) == -1) return -1;
if (lseek( fd, offset, SEEK_SET ) == -1) return -1;
if ((ret = write( fd, buf, count )) == -1)
{
int err = errno; /* save errno */
lseek( fd, old_pos, SEEK_SET );
errno = err;
return -1;
}
if (lseek( fd, old_pos, SEEK_SET ) == -1) return -1;
return ret;
}
#endif /* HAVE_PWRITE */
/*********************************************************************** /***********************************************************************
* getrlimit * getrlimit
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment