📝 Added sandbox (code sketchbook)

This commit is contained in:
z3rOR0ne 2023-04-22 00:41:54 -07:00
parent b475595f7f
commit b5daf18b1a
142 changed files with 100702 additions and 0 deletions

32
sandbox/open.c Normal file
View file

@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char const *argv[]) {
(void)argc;
(void)argv;
int fd;
char buff[1000];
printf("Enter a file you wish to open: \n");
scanf("%s", buff);
if ((fd = open(buff, O_RDONLY)) == -1) {
printf("file opening failed\n");
exit(0);
} else {
printf("file opening successful\n");
printf("file descriptor: %d\n", fd);
}
if (read(fd, buff, sizeof(buff)) == -1) {
printf("Error while reading file\n");
exit(0);
} else {
printf("wrote %lu bytes to the file\n", strlen(buff));
printf("File contents: %s\n", buff);
}
}