Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- int main(int argc, char** argv)
- {
- if(argc == 1)
- {
- puts("No valid argument!");
- printf("You are in %s", get_current_dir_name());
- exit(0);
- }
- int file = open(argv[1], O_RDONLY);
- int errornumber = errno;
- if(file == -1)
- {
- if(errornumber == 2)
- {
- puts("No such file in directory!");
- exit(0);
- }
- printf("errno %4d \n", errornumber);
- }
- else
- {
- struct stat fileCheck;
- stat(argv[1], &fileCheck);
- if(S_ISREG(fileCheck.st_mode))
- {
- printFile(argv[1]);
- }
- if(S_ISDIR(fileCheck.st_mode))
- {
- }
- }
- return 0;
- }
- void printFile(char* filename)
- {
- char output[1024];
- FILE* file;
- size_t nread;
- file = fopen(filename, "rb");
- int counter = 0;
- if(file)
- {
- fwrite(output, 1, 1024, stdout);
- fclose(file);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement