diffdb.c 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. ** A utility for printing the differences between two SQLite database files.
  3. */
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #define PAGESIZE 1024
  12. static int db1 = -1;
  13. static int db2 = -1;
  14. int main(int argc, char **argv){
  15. int iPg;
  16. unsigned char a1[PAGESIZE], a2[PAGESIZE];
  17. if( argc!=3 ){
  18. fprintf(stderr,"Usage: %s FILENAME FILENAME\n", argv[0]);
  19. exit(1);
  20. }
  21. db1 = open(argv[1], O_RDONLY);
  22. if( db1<0 ){
  23. fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]);
  24. exit(1);
  25. }
  26. db2 = open(argv[2], O_RDONLY);
  27. if( db2<0 ){
  28. fprintf(stderr,"%s: can't open %s\n", argv[0], argv[2]);
  29. exit(1);
  30. }
  31. iPg = 1;
  32. while( read(db1, a1, PAGESIZE)==PAGESIZE && read(db2,a2,PAGESIZE)==PAGESIZE ){
  33. if( memcmp(a1,a2,PAGESIZE) ){
  34. printf("Page %d\n", iPg);
  35. }
  36. iPg++;
  37. }
  38. printf("%d pages checked\n", iPg-1);
  39. close(db1);
  40. close(db2);
  41. }