aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqorg11 <qorg@vxempire.xyz>2020-11-28 22:29:41 +0100
committerqorg11 <qorg@vxempire.xyz>2020-11-28 22:29:41 +0100
commit36f49ec40686848c079c2f01b5a7ba53d6d6e6b4 (patch)
tree7c51c2f93f82bf669b71d26ea87b9576d0c1692f
parent8627b3bf15a155263524e361fdc51f5a4738fe4d (diff)
downloadk9core-36f49ec40686848c079c2f01b5a7ba53d6d6e6b4.tar.gz
k9core-36f49ec40686848c079c2f01b5a7ba53d6d6e6b4.zip
cat: ignore -u and - can be used for stdin
-rw-r--r--src/cat.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/cat.c b/src/cat.c
index 5a1c463..a1b678e 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -6,17 +6,20 @@
#include <string.h>
int
-cat(int fd,const char *filename)
+cat(int fd, const char *filename)
{
int c;
char buf[8192];
-
+ if (filename[0] == '-')
+ fd = 0;
+
if(fd != 0)
fd = open(filename, O_RDONLY);
if (fd == -1)
fprintf(stderr,"error opening %s: %s\n",filename,strerror(errno));
+
while((c = read(fd,buf,sizeof(buf))) > 0)
write(1,buf,c);
close(fd);
@@ -25,14 +28,11 @@ cat(int fd,const char *filename)
int
main(int argc, char *argv[])
{
-
- if(argc == 1)
- cat(0,NULL);
- else for(int i = optind; i<argc;i++)
- {
- int c = getopt(argc, argv, "u");
- cat(1,argv[i]);
- }
+ int c = getopt(argc,argv,"u");
+ if (argc == optind)
+ cat(0,"-");
+ for(int i = optind; i<argc;i++)
+ cat(1,argv[i]);
return 0;
}