more readable cat.c

This commit is contained in:
qorg11 2020-06-17 04:24:31 +02:00
parent c037341909
commit e1e3f9fa52
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
1 changed files with 5 additions and 2 deletions

View File

@ -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