1 | /* |
---|
2 | Copyright (C) 2008, Clozure Associates and contributors |
---|
3 | This file is part of Clozure CL. |
---|
4 | |
---|
5 | Clozure CL is licensed under the terms of the Lisp Lesser GNU Public |
---|
6 | License , known as the LLGPL and distributed with Clozure CL as the |
---|
7 | file "LICENSE". The LLGPL consists of a preamble and the LGPL, |
---|
8 | which is distributed with Clozure CL as the file "LGPL". Where these |
---|
9 | conflict, the preamble takes precedence. |
---|
10 | |
---|
11 | Clozure CL is referenced in the preamble as the "LIBRARY." |
---|
12 | |
---|
13 | The LLGPL is also available online at |
---|
14 | http://opensource.franz.com/preamble.html |
---|
15 | */ |
---|
16 | |
---|
17 | /* Provide wrappers around some standard C library functions that |
---|
18 | can't easily be called from CCL's FFI for some reason (or where |
---|
19 | we want to override/extend the function's default behavior.) |
---|
20 | |
---|
21 | Functions in this file should be referenced via the kernel |
---|
22 | imports table. |
---|
23 | |
---|
24 | Callers should generally expect standard C library error-handling |
---|
25 | conventions (e.g., return -1 or NULL and set errno on error.) |
---|
26 | */ |
---|
27 | |
---|
28 | #define _LARGEFILE64_SOURCE |
---|
29 | #include <errno.h> |
---|
30 | #include <unistd.h> |
---|
31 | #include <sys/stat.h> |
---|
32 | #include <dirent.h> |
---|
33 | #include <sys/syscall.h> |
---|
34 | #include <sys/time.h> |
---|
35 | #include <stdint.h> |
---|
36 | #include <signal.h> |
---|
37 | |
---|
38 | ssize_t |
---|
39 | lisp_read(int fd, void *buf, size_t count) |
---|
40 | { |
---|
41 | #ifdef LINUX |
---|
42 | return syscall(SYS_read,fd,buf,count); |
---|
43 | #else |
---|
44 | return read(fd,buf,count); |
---|
45 | #endif |
---|
46 | } |
---|
47 | |
---|
48 | ssize_t |
---|
49 | lisp_write(int fd, void *buf, size_t count) |
---|
50 | { |
---|
51 | #ifdef LINUX |
---|
52 | return syscall(SYS_write,fd,buf,count); |
---|
53 | #else |
---|
54 | return write(fd,buf,count); |
---|
55 | #endif |
---|
56 | } |
---|
57 | |
---|
58 | int |
---|
59 | lisp_open(char *path, int flags, mode_t mode) |
---|
60 | { |
---|
61 | #ifdef LINUX |
---|
62 | return syscall(SYS_open,path,flags,mode); |
---|
63 | #else |
---|
64 | return open(path,flags,mode); |
---|
65 | #endif |
---|
66 | } |
---|
67 | |
---|
68 | int |
---|
69 | lisp_fchmod(int fd, mode_t mode) |
---|
70 | { |
---|
71 | return fchmod(fd,mode); |
---|
72 | } |
---|
73 | |
---|
74 | int64_t |
---|
75 | lisp_lseek(int fd, int64_t offset, int whence) |
---|
76 | { |
---|
77 | #ifdef LINUX |
---|
78 | return lseek64(fd,offset,whence); |
---|
79 | #else |
---|
80 | return lseek(fd,offset,whence); |
---|
81 | #endif |
---|
82 | } |
---|
83 | |
---|
84 | int |
---|
85 | lisp_close(int fd) |
---|
86 | { |
---|
87 | return close(fd); |
---|
88 | } |
---|
89 | |
---|
90 | int |
---|
91 | lisp_ftruncate(int fd, off_t length) |
---|
92 | { |
---|
93 | return ftruncate(fd,length); |
---|
94 | } |
---|
95 | |
---|
96 | int |
---|
97 | lisp_stat(char *path, void *buf) |
---|
98 | { |
---|
99 | return stat(path,buf); |
---|
100 | } |
---|
101 | |
---|
102 | int |
---|
103 | lisp_fstat(int fd, void *buf) |
---|
104 | { |
---|
105 | return fstat(fd,buf); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | int |
---|
110 | lisp_futex(int *uaddr, int op, int val, void *timeout, int *uaddr2, int val3) |
---|
111 | { |
---|
112 | #ifdef LINUX |
---|
113 | return syscall(SYS_futex,uaddr,op,val,timeout,uaddr2,val3); |
---|
114 | #else |
---|
115 | errno = ENOSYS; |
---|
116 | return -1; |
---|
117 | #endif |
---|
118 | } |
---|
119 | |
---|
120 | DIR * |
---|
121 | lisp_opendir(char *path) |
---|
122 | { |
---|
123 | return opendir(path); |
---|
124 | } |
---|
125 | |
---|
126 | struct dirent * |
---|
127 | lisp_readdir(DIR *dir) |
---|
128 | { |
---|
129 | return readdir(dir); |
---|
130 | } |
---|
131 | |
---|
132 | int |
---|
133 | lisp_closedir(DIR *dir) |
---|
134 | { |
---|
135 | return closedir(dir); |
---|
136 | } |
---|
137 | |
---|
138 | int |
---|
139 | lisp_pipe(int pipefd[2]) |
---|
140 | { |
---|
141 | return pipe(pipefd); |
---|
142 | } |
---|
143 | |
---|
144 | int |
---|
145 | lisp_gettimeofday(struct timeval *tp, void *tzp) |
---|
146 | { |
---|
147 | return gettimeofday(tp, tzp); |
---|
148 | } |
---|
149 | |
---|
150 | int |
---|
151 | lisp_sigexit(int signum) |
---|
152 | { |
---|
153 | signal(signum, SIG_DFL); |
---|
154 | return kill(getpid(), signum); |
---|
155 | } |
---|