Last active
February 29, 2020 04:43
-
-
Save bridgesign/959621f6829e5fcb38485f429bdd1959 to your computer and use it in GitHub Desktop.
This is wcat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
int main(int argc, char const *argv[]) | |
{ | |
int fp; | |
char buf[100]; | |
int len; | |
char error[100]="wcat: cannot open file\n"; | |
if(argc == 1){return 0;} | |
for(int i=1; i<argc; i++){ | |
fp = open(argv[i], S_IRUSR); | |
if (fp== -1){ | |
for(int i=0;i<100;i++){ | |
if (error[i]=='\0') break; | |
write(1, error+i, 1); | |
} | |
_Exit(1); | |
} | |
len = read(fp, buf, 100); | |
while(len > 0){ | |
write(1, buf, len); | |
len = read(fp, buf, 100); | |
} | |
} | |
_Exit(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment