Skip to content

Instantly share code, notes, and snippets.

@fmount
Last active Jun 11, 2019
Embed
What would you like to do?
#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