stat-key.c 713 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Given a filename, outputs a 32bit key for use in
  3. * context keyed payload encoding. The key is derived from
  4. * XOR-ing the st_size and st_mtime fields of the
  5. * relevant struct stat for this file.
  6. *
  7. * Author: Dimitris Glynos <dimitris at census-labs.com>
  8. */
  9. #include <stdio.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <unistd.h>
  13. int main(int argc, char *argv[])
  14. {
  15. char *filename;
  16. struct stat stat_buf;
  17. if (argc != 2) {
  18. fprintf(stderr, "usage: %s <filename>\n", argv[0]);
  19. return 1;
  20. }
  21. filename = argv[1];
  22. if (stat(filename, &stat_buf) == -1) {
  23. perror("error while stat(2)-ing file");
  24. return 1;
  25. }
  26. printf("%#.8lx\n", stat_buf.st_mtime ^ stat_buf.st_size);
  27. return 0;
  28. }