You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.0KB

  1. /*
  2. * Copyright (c) 2002 Fabrice Bellard
  3. * Copyright (c) 2013 Michael Niedermayer
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "config.h"
  22. #include "libavutil/adler32.h"
  23. #include <errno.h>
  24. #include <fcntl.h>
  25. #include <stdio.h>
  26. #include <sys/stat.h>
  27. #if HAVE_IO_H
  28. #include <io.h>
  29. #endif
  30. #if HAVE_UNISTD_H
  31. #include <unistd.h>
  32. #endif
  33. #define SIZE 65536
  34. static int check(char *file)
  35. {
  36. uint8_t buffer[SIZE];
  37. uint32_t checksum = 1;
  38. int fd;
  39. int ret = 0;
  40. if (file) fd = open(file, O_RDONLY);
  41. else fd = 0;
  42. if (fd == -1) {
  43. printf("A32=OPEN-FAILED-%d", errno);
  44. ret = 1;
  45. goto end;
  46. }
  47. for (;;) {
  48. ssize_t size = read(fd, buffer, SIZE);
  49. if (size < 0) {
  50. printf("A32=0x%08x+READ-FAILED-%d", checksum, errno);
  51. ret = 2;
  52. goto end;
  53. } else if(!size)
  54. break;
  55. checksum = av_adler32_update(checksum, buffer, size);
  56. }
  57. close(fd);
  58. printf("A32=0x%08x", checksum);
  59. end:
  60. if (file)
  61. printf(" *%s", file);
  62. printf("\n");
  63. return ret;
  64. }
  65. int main(int argc, char **argv)
  66. {
  67. int i;
  68. int ret = 0;
  69. for (i = 1; i<argc; i++)
  70. ret |= check(argv[i]);
  71. if (argc == 1)
  72. ret |= check(NULL);
  73. return ret;
  74. }