inital commit 1
This commit is contained in:
commit
07738cacaf
76 files changed
+9477
No files matched your search
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char *argv[] = {"/bin/echo", "Helloworld", NULL};
|
||||
char *env[] = {NULL};
|
||||
|
||||
execve("/bin/echo", argv, env);
|
||||
perror("execve");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
|
||||
int execveat_(int fd, const char *path, char **argv, char **envp, int flags)
|
||||
{
|
||||
#ifdef __NR_execveat
|
||||
return syscall(__NR_execveat, fd, path, argv, envp, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main() {
|
||||
#ifndef __NR_execveat
|
||||
printf("syscall not found");
|
||||
return 0;
|
||||
#else
|
||||
char *envp[] = {"test=1", NULL};
|
||||
char *argv[] = {"hello", NULL};
|
||||
|
||||
execveat_(1, "/bin/true", argv, envp, 0);
|
||||
printf("failed %d", errno);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid > 0) {
|
||||
printf("i'm parent");
|
||||
}
|
||||
else if (pid == 0) {
|
||||
printf("i'm children");
|
||||
}
|
||||
else {
|
||||
printf("fork failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// maybe used in qsort function
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("%ld", sysconf(_SC_PAGE_SIZE));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f = fopen(argv[1], argv[2]);
|
||||
if (f == NULL) {
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int flags;
|
||||
if (!strcmp(argv[2], "w")) {
|
||||
flags = O_WRONLY | O_CREAT;
|
||||
}
|
||||
else {
|
||||
flags = O_RDWR | O_CREAT;
|
||||
}
|
||||
int fd = openat(0, argv[1], flags, 0755);
|
||||
if (fd < 0) {
|
||||
return errno;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user