Add ICU message format support
[chromium-blink-merge.git] / third_party / sqlite / src / tool / extract.c
blob5bf5caa31c9d1950b4e4eaa04ed68ab609429765
1 /*
2 ** Extract a range of bytes from a file.
3 **
4 ** Usage:
5 **
6 ** extract FILENAME OFFSET AMOUNT
7 **
8 ** The bytes are written to standard output.
9 */
10 #include <stdio.h>
11 #include <stdlib.h>
13 int main(int argc, char **argv){
14 FILE *f;
15 char *zBuf;
16 int ofst;
17 int n;
18 size_t got;
20 if( argc!=4 ){
21 fprintf(stderr, "Usage: %s FILENAME OFFSET AMOUNT\n", *argv);
22 return 1;
24 f = fopen(argv[1], "rb");
25 if( f==0 ){
26 fprintf(stderr, "cannot open \"%s\"\n", argv[1]);
27 return 1;
29 ofst = atoi(argv[2]);
30 n = atoi(argv[3]);
31 zBuf = malloc( n );
32 if( zBuf==0 ){
33 fprintf(stderr, "out of memory\n");
34 return 1;
36 fseek(f, ofst, SEEK_SET);
37 got = fread(zBuf, 1, n, f);
38 fclose(f);
39 if( got<n ){
40 fprintf(stderr, "got only %d of %d bytes\n", got, n);
41 return 1;
42 }else{
43 fwrite(zBuf, 1, n, stdout);
45 return 0;