mkdcs932.c 782 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License,
  4. * version 2 as published by the Free Software Foundation.
  5. *
  6. * (C) John Crispin <blogic@openwrt.org>
  7. */
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <stdio.h>
  12. #include <stdint.h>
  13. #include <unistd.h>
  14. #include <errno.h>
  15. int main(int argc, char **argv)
  16. {
  17. uint32_t t = 0, sum = 0x55aa55aa;
  18. int fd;
  19. if ((argc != 2) || ((fd = open(argv[1], O_RDWR)) == -1)) {
  20. fprintf(stderr, "Usage: %s input_file\n", *argv);
  21. return -EINVAL;
  22. }
  23. lseek(fd, -4, SEEK_END);
  24. write(fd, &t, 4);
  25. lseek(fd, 0, SEEK_SET);
  26. while (read(fd, &t, 4) > 0)
  27. sum -= t;
  28. lseek(fd, -4, SEEK_END);
  29. write(fd, &sum, 4);
  30. close(fd);
  31. return 0;
  32. }