| 1 |
#include <stdio.h> |
| 2 |
#include <string.h> |
| 3 |
#include <fcntl.h> |
| 4 |
#include <errno.h> |
| 5 |
|
| 6 |
#ifndef _MSC_VER |
| 7 |
#include <unistd.h> |
| 8 |
#endif |
| 9 |
|
| 10 |
int main(int argc, char **argv) { |
| 11 |
char data[10]; |
| 12 |
int fd, size; |
| 13 |
|
| 14 |
if (argc != 2) { |
| 15 |
fprintf(stderr, "Incorrect number of arguments, got %i\n", argc); |
| 16 |
return 1; |
| 17 |
} |
| 18 |
fd = open(argv[1], O_RDONLY); |
| 19 |
if (fd < 0) { |
| 20 |
fprintf(stderr, "First argument is wrong.\n"); |
| 21 |
return 1; |
| 22 |
} |
| 23 |
|
| 24 |
size = read(fd, data, 8); |
| 25 |
if (size < 0) { |
| 26 |
fprintf(stderr, "Failed to read: %s\n", strerror(errno)); |
| 27 |
return 1; |
| 28 |
} |
| 29 |
if (strncmp(data, "contents", 8) != 0) { |
| 30 |
fprintf(stderr, "Contents don't match, got %s\n", data); |
| 31 |
return 1; |
| 32 |
} |
| 33 |
return 0; |
| 34 |
} |