source: branches/working-0711/ccl/lisp-kernel/unix-calls.c @ 11497

Last change on this file since 11497 was 11497, checked in by gz, 11 years ago

Add a lisp_sigexit kernel-import, to allow exit by resignalling

File size: 2.7 KB
Line 
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
38ssize_t
39lisp_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
48ssize_t
49lisp_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
58int
59lisp_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
68int
69lisp_fchmod(int fd, mode_t mode)
70{
71  return fchmod(fd,mode);
72}
73
74int64_t
75lisp_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
84int
85lisp_close(int fd)
86{
87  return close(fd);
88}
89
90int
91lisp_ftruncate(int fd, off_t length)
92{
93  return ftruncate(fd,length);
94}
95
96int
97lisp_stat(char *path, void *buf)
98{
99  return stat(path,buf);
100}
101
102int
103lisp_fstat(int fd, void *buf)
104{
105  return fstat(fd,buf);
106}
107
108
109int
110lisp_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
120DIR *
121lisp_opendir(char *path)
122{
123  return opendir(path);
124}
125
126struct dirent *
127lisp_readdir(DIR *dir)
128{
129  return readdir(dir);
130}
131
132int
133lisp_closedir(DIR *dir)
134{
135  return closedir(dir);
136}
137
138int
139lisp_pipe(int pipefd[2])
140{
141  return pipe(pipefd);
142}
143
144int
145lisp_gettimeofday(struct timeval *tp, void *tzp)
146{
147  return gettimeofday(tp, tzp);
148}
149
150int
151lisp_sigexit(int signum)
152{
153  signal(signum, SIG_DFL);
154  return kill(getpid(), signum);
155}
Note: See TracBrowser for help on using the repository browser.