Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #define NAME_MAX 101
- int getFD(const char *const fname, int flags, int perm) {
- int fd = open(fname, flags, perm);
- if (fd < 0) {
- perror("");
- exit(1);
- }
- return fd;
- }
- void closeFD(int fd) {
- if (close(fd) < 0) {
- perror("");
- exit(1);
- }
- }
- int main(int argc, char *argv[]) {
- if (argc != 2) {
- fprintf(stderr, "Wrong usage!\n");
- exit(1);
- }
- int fd = getFD(argv[1], O_RDONLY, 0);
- static char name[NAME_MAX];
- read(fd, name, NAME_MAX);
- printf("name: %s\n", name);
- int fsize;
- lseek(fd, 124, SEEK_SET);
- read(fd, &fsize, 12);
- printf("size: %d\n", 3);
- closeFD(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement