Created
April 20, 2017 06:43
-
-
Save lf-/ecfecbb48d032bb96652f1908dcd25eb to your computer and use it in GitHub Desktop.
Because POSIX behaviour is obnoxious sometimes. A super thin syscall wrapper so posix will never bother us again.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <string.h> | |
typedef int (*scfunc)(const char *, const char *); | |
struct SysCall { | |
char* name; | |
scfunc func; | |
}; | |
struct SysCall syscalls[] = { | |
{"rename", rename}, | |
{"link", link}, | |
{"symlink", symlink} | |
}; | |
int main (int argc, char **argv) { | |
if (argc < 2) { | |
printf("Usage: %s funcname arg1 arg2\n", argv[0]); | |
return -1; | |
} | |
char *a1 = argv[2]; | |
char *a2 = argv[3]; | |
struct SysCall sc; | |
for (int i = 0; i < sizeof(syscalls) / sizeof(struct SysCall); ++i) { | |
sc = syscalls[i]; | |
if (!strcmp(argv[1], sc.name)) { | |
// printf("%s(%s, %s)\n", argv[1], a1, a2); | |
int res = sc.func(a1, a2); | |
if (res != 0) { | |
puts(strerror(res)); | |
} | |
return 0; | |
} | |
} | |
puts("Could not find supported syscall"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment