Last active
June 11, 2019 16:16
-
-
Save fmount/32f21a930f798636e2d4fa4f57feb3f6 to your computer and use it in GitHub Desktop.
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> | |
int enter_chroot(const char * root) { | |
/* chroot */ | |
chdir(root); | |
if (chroot(root) != 0) { | |
perror("chroot"); | |
return 1; | |
} | |
} | |
int read_print(const char* path) { | |
FILE *f; | |
f = fopen(path, "r"); | |
if (f == NULL) { | |
perror(path); | |
return 1; | |
} else { | |
char buffer[50]; | |
while (fgets(buffer, sizeof(buffer), f)) { | |
printf("%s", buffer); | |
} | |
} | |
return 0; | |
} | |
int main(void) { | |
//read_print("/etc/hostname"); | |
if(enter_chroot("/home/fmount/projects/c_gopherd/example")) { | |
return 1; | |
} | |
int val = read_print("gophermap"); | |
return val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment