Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdbool.h>
- #define BLOCK_SIZE (1 << 12)
- #define AUX_SIZE 50
- int openFile(const char path[], int flags, mode_t mode) {
- int fd = open(path, flags, mode);
- if (fd < 0) {
- perror("");
- exit(-1);
- }
- return fd;
- }
- void closeFile(int fd) {
- if (close(fd) == -1) {
- perror("");
- exit(-2);
- }
- }
- int main(int argc, char *argv[]) {
- if (argc != 2) {
- fprintf(stderr, "Wrong usage!\n");
- exit(-1);
- }
- struct stat st;
- lstat(argv[1], &st);
- printf("%ld\n", st.st_size);
- if (S_ISDIR(st.st_mode)) puts("dir");
- else if (S_ISLNK(st.st_mode)) puts("link");
- else if (S_ISREG(st.st_mode)) puts("reg file");
- puts("user: ");
- printf("read: %d\n", (bool)(st.st_mode & S_IRUSR));
- printf("write: %d\n", (bool)(st.st_mode & S_IWUSR));
- printf("exec: %d\n", (bool)(st.st_mode & S_IXUSR));
- return 0;
- }
Add Comment
Please, Sign In to add comment