Skip to content

Instantly share code, notes, and snippets.

@mutsune
Last active May 17, 2018 13:46
Show Gist options
  • Save mutsune/75bf9d54eae97d7e945d0d9742707147 to your computer and use it in GitHub Desktop.
Save mutsune/75bf9d54eae97d7e945d0d9742707147 to your computer and use it in GitHub Desktop.
はじめてのOSコードリーディング リスト10.1 ファイル操作のサンプルコード
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int fd;
char buf[2];
fd = open("filename.txt", 2);
read(fd, buf, 2);
buf[0] = 'a';
buf[1] = 'b';
lseek(fd, 0, 0);
write(fd, buf, 2);
close(fd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment