[vlc-commits] commit: Symbian: work-around the absence of pread/pwrite ( Jean-Baptiste Kempf )

git at videolan.org git at videolan.org
Sun Jan 9 18:58:20 CET 2011


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Wed Nov 24 14:21:15 2010 +0100| [72f56af826ad273aae2c8bd1afdf220fb05e4c92] | committer: Jean-Baptiste Kempf 

Symbian: work-around the absence of pread/pwrite

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=72f56af826ad273aae2c8bd1afdf220fb05e4c92
---

 configure.ac     |    2 +-
 src/misc/block.c |   24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index cde8002..543ff61 100644
--- a/configure.ac
+++ b/configure.ac
@@ -547,7 +547,7 @@ dnl Check for system libs needed
 need_libc=false
 
 dnl Check for usual libc functions
-AC_CHECK_FUNCS([daemon fcntl fdopendir fstatvfs fork getenv getpwuid_r gettimeofday isatty lstat memalign mmap openat posix_fadvise posix_madvise posix_memalign setenv setlocale stricmp strnicmp uselocale])
+AC_CHECK_FUNCS([daemon fcntl fdopendir fstatvfs fork getenv getpwuid_r gettimeofday isatty lstat memalign mmap openat pread posix_fadvise posix_madvise posix_memalign setenv setlocale stricmp strnicmp uselocale])
 AC_REPLACE_FUNCS([asprintf atof atoll getcwd getdelim getpid gmtime_r lldiv localtime_r nrand48 rewind strcasecmp strcasestr strdup strlcpy strncasecmp strndup strnlen strsep strtof strtok_r strtoll swab tdestroy vasprintf])
 AC_CHECK_FUNCS(fdatasync,,
   [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
diff --git a/src/misc/block.c b/src/misc/block.c
index efa4fce..78f05ff 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -385,6 +385,30 @@ ssize_t pread (int fd, void *buf, size_t count, off_t offset)
 }
 #endif
 
+#ifndef HAVE_PREAD
+static
+ssize_t pread(int fd, const void * buf, size_t size, off_t offset) {
+    off_t offs0;
+    ssize_t rd;
+    if ((offs0 = lseek(fd, 0, SEEK_CUR)) == (off_t)-1) return -1;
+    if (lseek(fd, offset, SEEK_SET) == (off_t)-1) return -1;
+    rd = read(fd, (void *)buf, size);
+    if (lseek(fd, offs0, SEEK_SET) == (off_t)-1) return -1;
+    return rd;
+}
+
+static
+ssize_t pwrite(int fd, const void * buf, size_t size, off_t offset) {
+    off_t offs0;
+    ssize_t wr;
+    if ((offs0 = lseek(fd, 0, SEEK_CUR)) == (off_t)-1) return -1;
+    if (lseek(fd, offset, SEEK_SET) == (off_t)-1) return -1;
+    wr = write(fd, (void *)buf, size);
+    if (lseek(fd, offs0, SEEK_SET) == (off_t)-1) return -1;
+    return wr;
+}
+#endif
+
 /**
  * Loads a file into a block of memory. If possible a private file mapping is
  * created. Otherwise, the file is read normally. On 32-bits platforms, this



More information about the vlc-commits mailing list