Created
January 22, 2015 07:05
-
-
Save MinweiShen/03a85d08146ff54bf618 to your computer and use it in GitHub Desktop.
a simple example of using syscall()
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 <fcntl.h> | |
/*arguments of syscall can be found on http://blog.rchapman.org/post/36801038863/linux-system-call-table-for-x86-64*/ | |
int main(int argc, char* argv[]){ | |
const char* fileName[7] = "me.txt"; | |
//create a file that the owner can read/write. flags can be found easily by google | |
syscall(SYS_open,fileName,O_CREAT,S_IRUSR|S_IWUSR); | |
//open it as write only | |
int fd = syscall(SYS_open,fileName,O_WRONLY); | |
//write somehing | |
syscall(SYS_write,fd,"hello",5); | |
//close the file | |
syscall(SYS_close,fd); | |
//change permission to executable | |
syscall(SYS_fchmod,fd,S_IXUSR); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment