-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhen.ns
More file actions
executable file
·59 lines (46 loc) · 1.21 KB
/
when.ns
File metadata and controls
executable file
·59 lines (46 loc) · 1.21 KB
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
#! /usr/bin/env nop
\ SPDX-License-Identifier: MIT
\ Copyright (c) 2021 Iruatã Martins dos Santos Souza
fload clib
( inotify support )
library:
0 1 Cfunction: inotify_init inotify_init
3 1 Cfunction: inotify_add_watch inotify_add_watch
record:
4 field: inotify-event-wd
4 field: inotify-event-mask
4 field: inotify-event-cookie
4 field: inotify-event-len
0 field: inotify-event-name
value /inotify-event
2 value IN_MODIFY
( fork support )
0 1 Cfunction: fork fork
2 1 Cfunction: execvp execvp
( application )
-1 value fd
-1 value wd
/inotify-event ( NAME_MAX + ) value #event
create event #event allot
: usage
" usage: " type 0 arg type " file command" println
1 sysexit ;
: ?add-watch ( fd path mask -> wd )
inotify_add_watch dup -1 = " can't add watch" ?abort ;
: init ( -> fd )
#args 3 < if usage then
inotify_init dup -1 = " can't initialize inotify" ?abort
dup to fd
next-arg drop \ arg is a zstr, discard length
IN_MODIFY ?add-watch to wd ;
: child
arg-offset @ arg drop \ file
arg-offset @ cells args + \ argv
execvp ;
: exec
fork if exit then
child " can't exec" println bye ;
: run
event #event fd sysread 0 <= if exit then
exec run ;
init run