repo.or.cz
/
xv6-db.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
added base src
[xv6-db.git]
/
cat.c
blob
2b2dcc7a5642d72c5bd358636940ca1d4fdd20a6
1
#include
"types.h"
2
#include
"stat.h"
3
#include
"user.h"
4
5
char
buf
[
512
];
6
7
void
8
cat
(
int
fd
)
9
{
10
int
n
;
11
12
while
((
n
=
read
(
fd
,
buf
,
sizeof
(
buf
))) >
0
)
13
write
(
1
,
buf
,
n
);
14
if
(
n
<
0
){
15
printf
(
1
,
"cat: read error
\n
"
);
16
exit
();
17
}
18
}
19
20
int
21
main
(
int
argc
,
char
*
argv
[])
22
{
23
int
fd
,
i
;
24
25
if
(
argc
<=
1
){
26
cat
(
0
);
27
exit
();
28
}
29
30
for
(
i
=
1
;
i
<
argc
;
i
++){
31
if
((
fd
=
open
(
argv
[
i
],
0
)) <
0
){
32
printf
(
1
,
"cat: cannot open %s
\n
"
,
argv
[
i
]);
33
exit
();
34
}
35
cat
(
fd
);
36
close
(
fd
);
37
}
38
exit
();
39
}