Skip to content

Commit a3646ce

Browse files
Merge pull request #13 from dooooooooinggggg/master
【動くのですが!】Create tatsu-cat.c
2 parents 3e4fd43 + 2b991bb commit a3646ce

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

cat/tatsu-cat/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tatsu_cat

cat/tatsu-cat/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
all:
2+
gcc -o tatsu_cat tatsu-cat.c
3+
chmod u+x tatsu_cat

cat/tatsu-cat/tatsu-cat.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <fcntl.h>
2+
#include <unistd.h>
3+
#define N 1024
4+
5+
int main(int argc, char *argv[])
6+
{
7+
int fd, buflen;
8+
char buf[N];
9+
if (argc < 2)
10+
_exit(1);
11+
for (int i = 1; i < argc; i++)
12+
{
13+
if ((fd = open(argv[i], O_RDONLY)) < 0)
14+
{
15+
write(1, "No such file\n\n", 32); // 標準出力
16+
close(fd);
17+
continue;
18+
}
19+
20+
while ((buflen = read(fd, buf, N)) > 0)
21+
write(1, buf, buflen); // 標準出力
22+
close(fd);
23+
}
24+
return 0;
25+
}

0 commit comments

Comments
 (0)