commit c904af6c61abe43298c9cbc71af38d0b904c1135
parent 268a888d8815286a3622f25c52fa775a57594d72
Author: qorg11 <qorg@vxempire.xyz>
Date: Wed, 17 Jun 2020 01:00:57 +0200
Someone make this read binary shit
Diffstat:
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/src/cat.c b/src/cat.c
@@ -1,30 +1,33 @@
#include <stdio.h>
-
+#include <fcntl.h>
+#include <unistd.h>
int
-cat(FILE *file)
+cat(int fd,const char *filename)
{
-
+
char c;
- if (file == NULL)
+ char buf[8192];
+ if(fd != 0)
+ fd = open(filename, O_RDONLY);
+ if ( fd == -1)
{
fprintf(stderr,"Error opening file\n");
return 1;
}
- while((c = fgetc(file)) > 0)
- putchar(c);
+ while((c = read(fd,buf,sizeof(buf)) > 0))
+ printf("%s",buf);
return 0;
}
int
main(int argc, char *argv[])
{
if(argc == 1)
- cat(stdin);
- else {
- for(int i = 1; i<argc;i++)
- {
- cat(fopen(argv[i],"r"));
- }
- }
+ cat(0,NULL);
+ else for(int i = 1; i<argc;i++)
+ {
+ cat(1,argv[i]);
+ }
+
return 0;
}