tester.c 736 B

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