/[meta-cvs]/meta-cvs/F-83F0E6A90D5BBCDFB58440970E850925.c
ViewVC logotype

Contents of /meta-cvs/F-83F0E6A90D5BBCDFB58440970E850925.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Sun Aug 4 18:15:18 2002 UTC (11 years, 8 months ago) by kaz
Branch: MAIN
CVS Tags: mcvs-0-21
Changes since 1.1: +9 -0 lines
File MIME type: text/plain
Working back support for CLISP 2.27.

* code/install.sh: Bogus *null-pointer* hack is no longer added
to the generated mcvs script, since we have our own FFI functions for
doing the test.

* code/unix-bindings/unix.lisp (unix-funcs:null-pointer-p): New
function, tests a C pointer for null, returns T or NIL.
* code/unix-bindings/impl.c (impl_null_pointer_p): New function,
C implementation of unix-funcs:null-pointer-p.

* code/clisp-unix.lisp (pointer-null): New macro, uses
ffi:foreign-address-null under CLISP 2.28 or greater, or
unix-funcs:null-pointer-p, under an older CLISP.
1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <dirent.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7
8 /*
9 * Null pointer test
10 */
11
12 int impl_null_pointer_p(void *ptr)
13 {
14 return ptr == 0;
15 }
16
17 /*
18 * <errno.h> stuff
19 */
20
21 int impl_get_errno(void)
22 {
23 return errno;
24 }
25
26 int impl_set_errno(int value)
27 {
28 return errno = value;
29 }
30
31 /*
32 * <dirent.h> stuff
33 */
34
35 typedef struct {
36 unsigned long d_ino;
37 char d_name[1024];
38 } impl_dirent;
39
40 impl_dirent *impl_readdir(DIR *dir)
41 {
42 static impl_dirent dw;
43 struct dirent *de = readdir(dir);
44 if (de != 0) {
45 strncpy(dw.d_name, de->d_name, sizeof dw.d_name - 1);
46 dw.d_ino = de->d_ino;
47 return &dw;
48 }
49 return 0;
50 }
51
52 /*
53 * <sys/stat.h> stuff
54 */
55
56 struct impl_stat {
57 unsigned long dev;
58 unsigned long ino;
59 unsigned long mode;
60 unsigned int nlink;
61 unsigned int uid;
62 unsigned int gid;
63 unsigned long rdev;
64 unsigned long blksize;
65 unsigned long blocks;
66 unsigned long atime;
67 unsigned long mtime;
68 unsigned long ctime;
69 };
70
71 static void stat_to_impl(struct impl_stat *out, const struct stat *in)
72 {
73 out->dev = in->st_dev;
74 out->ino = in->st_ino;
75 out->mode = in->st_mode;
76 out->nlink = in->st_nlink;
77 out->uid = in->st_uid;
78 out->gid = in->st_gid;
79 out->rdev = in->st_rdev;
80 out->blksize = in->st_blksize;
81 out->blocks = in->st_blocks;
82 out->atime = in->st_atime;
83 out->mtime = in->st_mtime;
84 out->ctime = in->st_ctime;
85 }
86
87 #define IMPL_STAT(FUNC, ARGTYPE) \
88 int impl_ ## FUNC(ARGTYPE arg, struct impl_stat *buf) \
89 { \
90 struct stat sbuf; \
91 int retval = FUNC(arg, &sbuf); \
92 if (retval == 0) \
93 stat_to_impl(buf, &sbuf); \
94 return retval; \
95 }
96
97 IMPL_STAT(stat, const char *)
98 IMPL_STAT(lstat, const char *)
99 IMPL_STAT(fstat, int)

  ViewVC Help
Powered by ViewVC 1.1.5