xref: /illumos-gate/usr/src/lib/libsqlite/tool/diffdb.c (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate ** A utility for printing the differences between two SQLite database files.
37c478bd9Sstevel@tonic-gate */
47c478bd9Sstevel@tonic-gate #include <stdio.h>
57c478bd9Sstevel@tonic-gate #include <ctype.h>
67c478bd9Sstevel@tonic-gate #include <sys/types.h>
77c478bd9Sstevel@tonic-gate #include <sys/stat.h>
87c478bd9Sstevel@tonic-gate #include <fcntl.h>
97c478bd9Sstevel@tonic-gate #include <unistd.h>
107c478bd9Sstevel@tonic-gate #include <stdlib.h>
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate 
137c478bd9Sstevel@tonic-gate #define PAGESIZE 1024
147c478bd9Sstevel@tonic-gate static int db1 = -1;
157c478bd9Sstevel@tonic-gate static int db2 = -1;
167c478bd9Sstevel@tonic-gate 
main(int argc,char ** argv)177c478bd9Sstevel@tonic-gate int main(int argc, char **argv){
187c478bd9Sstevel@tonic-gate   int iPg;
197c478bd9Sstevel@tonic-gate   unsigned char a1[PAGESIZE], a2[PAGESIZE];
207c478bd9Sstevel@tonic-gate   if( argc!=3 ){
217c478bd9Sstevel@tonic-gate     fprintf(stderr,"Usage: %s FILENAME FILENAME\n", argv[0]);
227c478bd9Sstevel@tonic-gate     exit(1);
237c478bd9Sstevel@tonic-gate   }
247c478bd9Sstevel@tonic-gate   db1 = open(argv[1], O_RDONLY);
257c478bd9Sstevel@tonic-gate   if( db1<0 ){
267c478bd9Sstevel@tonic-gate     fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]);
277c478bd9Sstevel@tonic-gate     exit(1);
287c478bd9Sstevel@tonic-gate   }
297c478bd9Sstevel@tonic-gate   db2 = open(argv[2], O_RDONLY);
307c478bd9Sstevel@tonic-gate   if( db2<0 ){
317c478bd9Sstevel@tonic-gate     fprintf(stderr,"%s: can't open %s\n", argv[0], argv[2]);
327c478bd9Sstevel@tonic-gate     exit(1);
337c478bd9Sstevel@tonic-gate   }
347c478bd9Sstevel@tonic-gate   iPg = 1;
357c478bd9Sstevel@tonic-gate   while( read(db1, a1, PAGESIZE)==PAGESIZE && read(db2,a2,PAGESIZE)==PAGESIZE ){
367c478bd9Sstevel@tonic-gate     if( memcmp(a1,a2,PAGESIZE) ){
377c478bd9Sstevel@tonic-gate       printf("Page %d\n", iPg);
387c478bd9Sstevel@tonic-gate     }
397c478bd9Sstevel@tonic-gate     iPg++;
407c478bd9Sstevel@tonic-gate   }
417c478bd9Sstevel@tonic-gate   printf("%d pages checked\n", iPg-1);
427c478bd9Sstevel@tonic-gate   close(db1);
437c478bd9Sstevel@tonic-gate   close(db2);
447c478bd9Sstevel@tonic-gate }
45