OSDN Git Service

e91582f2ef188d8e092524870b95492168edef35
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / sh / pread_write.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7 /*
8  * Based in part on the files
9  *              ./sysdeps/unix/sysv/linux/pwrite.c,
10  *              ./sysdeps/unix/sysv/linux/pread.c,
11  *              sysdeps/posix/pread.c
12  *              sysdeps/posix/pwrite.c
13  * from GNU libc 2.2.5, but reworked considerably...
14  */
15
16 #include <sys/syscall.h>
17 #include <unistd.h>
18 #include <stdint.h>
19 #include <endian.h>
20
21 #ifdef __NR_pread64             /* Newer kernels renamed but it's the same.  */
22 # ifdef __NR_pread
23 #  error "__NR_pread and __NR_pread64 both defined???"
24 # endif
25 # define __NR_pread __NR_pread64
26 #endif
27
28 #ifdef __NR_pread
29 extern __typeof(pread) __libc_pread;
30 # define __NR___syscall_pread __NR_pread
31 static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
32                 size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
33
34 ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
35 {
36         return(__syscall_pread(fd,buf,count,0,__LONG_LONG_PAIR(offset >> 31,offset)));
37 }
38 weak_alias(__libc_pread,pread)
39
40 # ifdef __UCLIBC_HAS_LFS__
41 extern __typeof(pread64) __libc_pread64;
42 ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
43 {
44     uint32_t low = offset & 0xffffffff;
45     uint32_t high = offset >> 32;
46         return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
47 }
48 weak_alias(__libc_pread64,pread64)
49 # endif /* __UCLIBC_HAS_LFS__  */
50 #endif /* __NR_pread */
51
52 /**********************************************************************/
53
54 #ifdef __NR_pwrite64            /* Newer kernels renamed but it's the same.  */
55 # ifdef __NR_pwrite
56 #  error "__NR_pwrite and __NR_pwrite64 both defined???"
57 # endif
58 # define __NR_pwrite __NR_pwrite64
59 #endif
60
61 #ifdef __NR_pwrite
62 extern __typeof(pwrite) __libc_pwrite;
63 # define __NR___syscall_pwrite __NR_pwrite
64 static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
65                 size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
66
67 ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
68 {
69         return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR(offset >> 31,offset)));
70 }
71 weak_alias(__libc_pwrite,pwrite)
72
73 # ifdef __UCLIBC_HAS_LFS__
74 extern __typeof(pwrite64) __libc_pwrite64;
75 ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
76 {
77     uint32_t low = offset & 0xffffffff;
78     uint32_t high = offset >> 32;
79         return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
80 }
81 weak_alias(__libc_pwrite64,pwrite64)
82 # endif /* __UCLIBC_HAS_LFS__  */
83 #endif /* __NR_pwrite */