Commit a7879d806c92a4500b9a547c57b35b91057e6052

Thomas de Grivel 2018-03-05T17:46:12

add functions up to rmdir, no -at functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
diff --git a/cffi-unistd.lisp b/cffi-unistd.lisp
index f573bc4..5edb30e 100644
--- a/cffi-unistd.lisp
+++ b/cffi-unistd.lisp
@@ -348,6 +348,256 @@ without changing the file pointer. Returns number of bytes written."
 #+test
 (getenv "HOME")
 
+(defcfun ("execve" c-execve) :int
+  (path :string)
+  (argv (:pointer :string))
+  (envp (:pointer :string)))
+
+(defun execve (path argv envp)
+  (let ((r (c-execve path argv envp)))
+    (if (= -1 r)
+        (error-errno path)
+        (error "execve ~S" path))))
+
+(defcfun ("execv" c-execv) :int
+  (path :string)
+  (argv (:pointer :string)))
+
+(defun execv (path argv)
+  (let ((r (c-execv path argv)))
+    (if (= -1 r)
+        (error-errno path)
+        (error "execv ~S" path))))
+
+(defcfun ("execvp" c-execvp) :int
+  (path :string)
+  (argv (:pointer :string)))
+
+(defun execvp (path argv)
+  (let ((r (c-execvp path argv)))
+    (if (= -1 r)
+        (error-errno path)
+        (error "execv ~S" path))))
+
+(defcfun ("execvpe" c-execvpe) :int
+  (path :string)
+  (argv (:pointer :string))
+  (envp (:pointer :string)))
+
+(defun execvpe (path argv envp)
+  (let ((r (c-execvpe path argv envp)))
+    (if (= -1 r)
+        (error-errno path)
+        (error "execvpe ~S" path))))
+
+(defcfun ("nice" c-nice) :int
+  (inc :int))
+
+(defun nice (inc)
+  (setf errno 0)
+  (let ((r (c-nice inc)))
+    (unless (= 0 errno)
+      (error-errno "nice"))
+    r))
+
+(defcfun ("_exit" c-_exit) :void
+  (status :int))
+
+(defun _exit (status)
+  (c-_exit status))
+
+(defcfun ("pathconf" c-pathconf) :long
+  (path :string)
+  (name :int))
+
+(defun pathconf (path name)
+  (c-pathconf path name))
+
+(defcfun ("sysconf" c-sysconf) :long
+  (name :int))
+
+(defun sysconf (name)
+  (c-sysconf name))
+
+(defcfun ("getpid" c-getpid) pid-t)
+
+(defun getpid ()
+  (c-getpid))
+
+(defcfun ("getppid" c-getppid) pid-t)
+
+(defun getppid ()
+  (c-getppid))
+
+(defcfun ("getpgrp" c-getpgrp) pid-t)
+
+(defun getpgrp ()
+  (c-getpgrp))
+
+(defcfun ("getpgid" c-getpgid) pid-t)
+
+(defun getpgid ()
+  (c-getpgid))
+
+(defcfun ("setpgid" c-setpgid) pid-t)
+
+(defun setpgid ()
+  (c-setpgid))
+
+(defcfun ("setpgrp" c-setpgrp) :int)
+
+(defun setpgrp ()
+  (c-setpgrp))
+
+(defcfun ("setsid" c-setsid) pid-t)
+
+(defun setsid ()
+  (c-setsid))
+
+(defcfun ("getsid" c-getsid) pid-t
+  (pid pid-t))
+
+(defun getsid (pid)
+  (c-getsid pid))
+
+(defcfun ("getuid" c-getuid) pid-t)
+
+(defun getuid ()
+  (c-getuid))
+
+(defcfun ("geteuid" c-geteuid) pid-t)
+
+(defun geteuid ()
+  (c-geteuid))
+
+(defcfun ("getgid" c-getgid) pid-t)
+
+(defun getgid ()
+  (c-getgid))
+
+(defcfun ("getegid" c-getegid) pid-t)
+
+(defun getegid ()
+  (c-getegid))
+
+(defcfun ("getgroups" c-getgroups) :int
+  (size :int)
+  (list gid-t))
+
+(defcfun ("setuid" c-setuid) :int
+  (uid uid-t))
+
+(defun setuid (uid)
+  (c-setuid uid))
+
+(defcfun ("seteuid" c-seteuid) :int
+  (uid uid-t))
+
+(defun seteuid (uid)
+  (c-seteuid uid))
+
+(defcfun ("setgid" c-setgid) :int
+  (gid gid-t))
+
+(defun setgid (gid)
+  (c-setgid gid))
+
+(defcfun ("setegid" c-setegid) :int
+  (gid gid-t))
+
+(defun setegid (gid)
+  (c-setegid gid))
+
+(defcfun ("fork" c-fork) pid-t)
+
+(defun fork ()
+  (let ((r (c-fork)))
+    (when (= -1 r)
+      (error-errno "fork"))
+    r))
+
+(defcfun ("vfork" c-vfork) pid-t)
+
+(defun vfork ()
+  (let ((r (c-vfork)))
+    (when (= -1 r)
+      (error-errno "vfork"))
+    r))
+
+(defcfun ("ttyname" c-ttyname) :string
+  (fd :int))
+
+(defun ttyname (fd)
+  (or (c-ttyname fd)
+      (error-errno "ttyname")))
+
+(defcfun ("isatty" c-isatty) :int
+  (fd :int))
+
+(defun isatty (fd)
+  (let ((r (c-isatty fd)))
+    (when (= -1 r)
+      (error-errno "isatty"))
+    r))
+
+(defcfun ("link" c-link) :int
+  (from :string)
+  (to :string))
+
+(defun link (from to)
+  (let ((r (c-link from to)))
+    (when (= -1 r)
+      (error-errno "link"))
+    r))
+
+(defcfun ("symlink" c-symlink) :int
+  (from :string)
+  (to :string))
+
+(defun symlink (from to)
+  (let ((r (c-symlink from to)))
+    (when (= -1 r)
+      (error-errno "symlink"))
+    r))
+
+(defcfun ("readlink" c-readlink) ssize-t
+  (path :string)
+  (buf :string)
+  (len size-t))
+
+(defun readlink (path)
+  (let ((len *path-max*))
+    (with-foreign-object (buf :char len)
+      (let ((r (c-readlink path buf len)))
+        (when (= -1 r)
+          (error-errno path))
+        (let ((octets (make-array `(,r) :element-type '(unsigned-byte 8)
+                                  :initial-element 0)))
+          (dotimes (i r)
+            (setf (aref octets i) (mem-aref buf :unsigned-char i)))
+          (babel:octets-to-string octets :encoding :utf-8))))))
+
+#+nil
+(readlink "/home/dx/common-lisp/RailsOnLisp/rol/assets")
+
+(defcfun ("unlink" c-unlink) :int
+  (name :string))
+
+(defun unlink (name)
+  (let ((r (c-unlink name)))
+    (when (= -1 r)
+      (error-errno "unlink"))
+    r))
+
+(defcfun ("rmdir" c-rmdir) :int
+  (path :string))
+
+(defun rmdir (path)
+  (let ((r (c-rmdir path)))
+    (when (= -1 r)
+      (error-errno "rmdir"))
+    r))
+
 ;;  Select
 
 (defcstruct fd-set
diff --git a/package.lisp b/package.lisp
index 91db247..3bb20d5 100644
--- a/package.lisp
+++ b/package.lisp
@@ -30,6 +30,7 @@
    #:sleep
    #:write)
   (:export
+   #:_exit
    #:+f-ok+
    #:+fd-setsize+
    #:+nfdbits+
@@ -46,6 +47,7 @@
    #:+x-ok+
    #:access
    #:alarm
+   #:c-_exit
    #:c-access
    #:c-alarm
    #:c-chdir
@@ -56,22 +58,55 @@
    #:c-dup3
    #:c-environ
    #:c-euidaccess
+   #:c-execv
+   #:c-execve
+   #:c-execvp
+   #:c-execvpe
    #:c-fchdir
    #:c-fchown
    #:c-fchownat
+   #:c-fork
    #:c-getcwd
+   #:c-getegid
+   #:c-geteuid
+   #:c-getgid
+   #:c-getgroups
+   #:c-getpgid
+   #:c-getpgrp
+   #:c-getpid
+   #:c-getppid
+   #:c-getsid
+   #:c-getuid
+   #:c-isatty
    #:c-lchown
+   #:c-link
    #:c-lseek
+   #:c-nice
+   #:c-pathconf
    #:c-pause
    #:c-pipe
    #:c-pipe2
    #:c-pread
    #:c-pwrite
    #:c-read
+   #:c-readlink
+   #:c-rmdir
    #:c-select
+   #:c-setegid
+   #:c-seteuid
+   #:c-setgid
+   #:c-setpgid
+   #:c-setpgrp
+   #:c-setsid
+   #:c-setuid
    #:c-sleep
+   #:c-symlink
+   #:c-sysconf
+   #:c-ttyname
    #:c-ualarm
+   #:c-unlink
    #:c-usleep
+   #:c-vfork
    #:c-write
    #:chdir
    #:chown
@@ -82,6 +117,10 @@
    #:dup3
    #:environ
    #:euidaccess
+   #:execv
+   #:execve
+   #:execvp
+   #:execvpe
    #:fchdir
    #:fchown
    #:fchownat
@@ -93,14 +132,28 @@
    #:fd-set-filter
    #:fd-zero
    #:fds-bits
+   #:fork
    #:getcwd
+   #:getegid
+   #:geteuid
    #:getenv
+   #:getgid
+   #:getgroups
+   #:getpgid
+   #:getpid
+   #:getppid
+   #:getsid
+   #:getuid
    #:gid-t
    #:intptr-t
+   #:isatty
    #:lchown
+   #:link
    #:list-to-fd-set
    #:lseek
+   #:nice
    #:off-t
+   #:pathconf
    #:pause
    #:pid-t
    #:pipe
@@ -109,19 +162,33 @@
    #:pwrite
    #:read
    #:read-non-blocking
+   #:readlink
+   #:rmdir
    #:seconds-to-timeval
    #:select
+   #:setegid
+   #:seteuid
+   #:setgid
+   #:setpgid
+   #:setpgrp
+   #:setsid
+   #:setuid
    #:size-t
    #:sleep
    #:socklen-t
    #:ssize-t
+   #:symlink
+   #:sysconf
    #:timeval
+   #:ttyname
    #:tv-sec
    #:tv-usec
    #:ualarm
    #:uid-t
+   #:unlink
    #:useconds-t
    #:usleep
+   #:vfork
    #:with-pipe
    #:with-selected
    #:write