Back to index

glibc  2.9
pread.c
Go to the documentation of this file.
00001 /* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <assert.h>
00022 #include <errno.h>
00023 #include <unistd.h>
00024 
00025 #include <sysdep-cancel.h>
00026 #include <sys/syscall.h>
00027 #include <bp-checks.h>
00028 
00029 #include <kernel-features.h>
00030 
00031 #if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
00032 
00033 # if __ASSUME_PREAD_SYSCALL == 0
00034 static ssize_t __emulate_pread (int fd, void *buf, size_t count,
00035                             off_t offset) internal_function;
00036 # endif
00037 
00038 
00039 ssize_t
00040 __libc_pread (fd, buf, count, offset)
00041      int fd;
00042      void *buf;
00043      size_t count;
00044      off_t offset;
00045 {
00046   ssize_t result;
00047 
00048   if (SINGLE_THREAD_P)
00049     {
00050       result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count,
00051                                 offset);
00052 # if __ASSUME_PREAD_SYSCALL == 0
00053       if (result == -1 && errno == ENOSYS)
00054        /* No system call available.  Use the emulation.  */
00055        result = __emulate_pread (fd, buf, count, offset);
00056 # endif
00057 
00058       return result;
00059     }
00060 
00061   int oldtype = LIBC_CANCEL_ASYNC ();
00062 
00063   result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count,
00064                             offset);
00065 # if __ASSUME_PREAD_SYSCALL == 0
00066   if (result == -1 && errno == ENOSYS)
00067     /* No system call available.  Use the emulation.  */
00068     result = __emulate_pread (fd, buf, count, offset);
00069 # endif
00070 
00071   LIBC_CANCEL_RESET (oldtype);
00072 
00073   return result;
00074 }
00075 
00076 strong_alias (__libc_pread, __pread)
00077 weak_alias (__libc_pread, pread)
00078 
00079 # define __libc_pread(fd, buf, count, offset) \
00080      static internal_function __emulate_pread (fd, buf, count, offset)
00081 #endif
00082 
00083 #if __ASSUME_PREAD_SYSCALL == 0
00084 # include <sysdeps/posix/pread.c>
00085 #endif