commit e1e3f9fa52a35e441b89735f5c707d4d9f98b641
parent c03734190924b744f7b615121c97e349dbbd70f8
Author: qorg11 <qorg@vxempire.xyz>
Date: Wed, 17 Jun 2020 04:24:31 +0200
more readable cat.c
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/cat.c b/src/cat.c
@@ -5,18 +5,21 @@
int
cat(int fd,const char *filename)
{
-
int c;
char buf[8192];
+
if(fd != 0)
fd = open(filename, O_RDONLY);
- if ( fd == -1)
+
+ if (fd == -1)
{
fprintf(stderr,"Error opening file\n");
return 1;
}
+
while((c = read(fd,buf,sizeof(buf))) > 0)
write(1,buf,c);
+
return 0;
}
int