24 lines
509 B
C
24 lines
509 B
C
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc != 2) {
|
|
printf("Usage: touch <filename>\n");
|
|
return 1;
|
|
}
|
|
|
|
// O_CREAT: 없으면 생성
|
|
// O_TRUNC: 있으면 내용을 비움 (0바이트로 만듦)
|
|
// 0644: 파일 권한 (rw-r--r--)
|
|
int fd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0644);
|
|
|
|
if (fd < 0) {
|
|
perror("touch");
|
|
return 1;
|
|
}
|
|
|
|
close(fd);
|
|
return 0;
|
|
} |