Last active
December 18, 2021 04:02
-
-
Save cho0h5/a333e71c0c0d7e08858925fe25a7b7ee to your computer and use it in GitHub Desktop.
c file io
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> | |
#include <unistd.h> | |
int main() { | |
int fd = open("foo.txt", O_RDWR | O_CREAT, 0644); | |
if(fd < 0) { | |
printf("failed\n"); | |
return -1; | |
} | |
printf("success\n"); | |
printf("fd: %d\n", fd); | |
char buf[10]; | |
read(fd, buf, 10); | |
close(fd); | |
printf("file content: %s", buf); | |
return 0; | |
} |
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> | |
#include <unistd.h> | |
int main() { | |
int fd = open("foo.txt", O_RDWR | O_CREAT, 0644); | |
if(fd < 0) { | |
printf("failed\n"); | |
return -1; | |
} | |
printf("success\n"); | |
printf("fd: %d\n", fd); | |
write(fd, "hello", 5); | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment