]> Sergey Matveev's repositories - public-inbox.git/blob - devel/syscall-list
lei: use RENAME_NOREPLACE on Linux 3.15+
[public-inbox.git] / devel / syscall-list
1 # Copyright all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <http://www.gnu.org/licenses/agpl-3.0.txt>
3 # Dump syscall numbers under Linux and any other kernel which
4 # promises stable syscall numbers.  This is to maintain
5 # PublicInbox::Syscall
6 # DO NOT USE this for *BSDs, none of the current BSD kernels
7 # we know about promise stable syscall numbers, we'll use
8 # Inline::C to support them.
9 eval 'exec perl -S $0 ${1+"$@"}' # no shebang
10         if 0; # running under some shell
11 use strict;
12 use v5.10.1;
13 use File::Temp 0.19;
14 use POSIX qw(uname);
15 say '$machine='.(POSIX::uname())[-1];
16 my $cc = $ENV{CC} // 'cc';
17 my @cflags = split(/\s+/, $ENV{CFLAGS} // '-Wall');
18 my $str = do { local $/; <DATA> };
19 my $tmp = File::Temp->newdir('syscall-list-XXXX', TMPDIR => 1);
20 my $f = "$tmp/sc.c";
21 my $x = "$tmp/sc";
22 open my $fh, '>', $f or die "open $f $!";
23 print $fh $str or die "print $f $!";
24 close $fh or die "close $f $!";
25 system($cc, '-o', $x, $f, @cflags) == 0 or die "cc failed \$?=$?";
26 exec($x);
27 __DATA__
28 #define _GNU_SOURCE
29 #include <unistd.h>
30 #include <sys/syscall.h>
31 #include <stdio.h>
32
33 #define D(x) printf("$" #x " = %ld;\n", (long)x)
34
35 int main(void)
36 {
37 #ifdef __linux__
38         D(SYS_epoll_create1);
39         D(SYS_epoll_ctl);
40 #ifdef SYS_epoll_wait
41         D(SYS_epoll_wait);
42 #endif
43         D(SYS_epoll_pwait);
44         D(SYS_signalfd4);
45         D(SYS_inotify_init1);
46         D(SYS_inotify_add_watch);
47         D(SYS_inotify_rm_watch);
48         D(SYS_prctl);
49 #ifdef SYS_renameat2
50         D(SYS_renameat2);
51 #endif
52 #endif /* Linux, any other OSes with stable syscalls? */
53         printf("size_t=%zu off_t=%zu\n", sizeof(size_t), sizeof(off_t));
54         return 0;
55 }