int main(int argc, char **argv) { FILE *fp; int size; if(argc < 2) { fprintf(stderr,"Usage: %s <filename>\n", argv[0]); return 1; } // Open for binary reading fp = fopen(argv[1], "rb"); if( fp == NULL ) { fprintf(stderr,"Unable to open file %s for reading\n", argv[1]); return 1; } // Get the file size fseek(fp, 0, SEEK_END); size = ftell(fp); fseek(fp, 0, SEEK_SET); // Try and read the whole file hexdump_file(fp, size, 0); fclose(fp); return 0; }
int main(int argc, char *argv[]) { if (argc != 5) { printf("Usage: hexdump <infile> <start> <end> <width>\n"); return 0; } FILE *infile=fopen(argv[1],"rb"); if (infile==(FILE *)NULL) { printf("Error opening input file %s\n",argv[1]); return 0; } printf("Filename: \"%s\"\n", argv[1]); printf("Start : %lu\n", atoi(argv[2])); printf("End : %lu\n", atoi(argv[3])); printf("Bytes per Line: %lu\n",atoi(argv[4])); int result = hexdump_file(infile,atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); return 0; }
static void extra_header_test (const char *filename, int filetype) { SNDFILE *outfile ; SF_INFO sfinfo ; sf_count_t frames ; short buffer [8] ; int k = 0 ; print_test_name ("extra_header_test", filename) ; sfinfo.samplerate = 44100 ; sfinfo.format = (filetype | SF_FORMAT_PCM_16) ; sfinfo.channels = 1 ; memset (buffer, 0xA0, sizeof (buffer)) ; /* Now write some frames. */ frames = ARRAY_LEN (buffer) / sfinfo.channels ; /* Test the file with extra header data. */ outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, 464) ; sf_set_string (outfile, SF_STR_TITLE, filename) ; test_writef_short_or_die (outfile, k, buffer, frames, 466) ; sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ; sf_close (outfile) ; #if 1 /* ** Erik de Castro Lopo <*****@*****.**> May 23 2004. ** ** This file has extra string data in the header and therefore cannot ** currently be opened in SFM_RDWR mode. This is fixable, but its in ** a part of the code I don't want to fiddle with until the Ogg/Vorbis ** integration is done. */ if (sf_open (filename, SFM_RDWR, &sfinfo) != NULL) { printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ; exit (1) ; } ; unlink (filename) ; puts ("ok") ; return ; #else hexdump_file (filename, 0, 100000) ; /* Open again for read/write. */ outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, 493) ; /* ** In auto header update mode, seeking to the end of the file with ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END ** will seek to 0 anyway */ if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0) { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ; exit (1) ; } ; /* Now write some frames. */ frames = ARRAY_LEN (buffer) / sfinfo.channels ; for (k = 1 ; k < 6 ; k++) { printf ("\n*** pass %d\n", k) ; memset (buffer, 0xA0 + k, sizeof (buffer)) ; test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, 514) ; test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, 515) ; /* Open file again and make sure no errors in log buffer. */ if (0) { infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, 519) ; check_log_buffer_or_die (infile, 520) ; sf_close (infile) ; } ; if (sfinfo.frames != k * frames) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", 525, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ; dump_log_buffer (infile) ; exit (1) ; } ; if ((k & 1) == 0) test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, 531) ; else test_writef_short_or_die (outfile, k, buffer, frames, 533) ; hexdump_file (filename, 0, 100000) ; } ; sf_close (outfile) ; unlink (filename) ; puts ("ok") ; return ; #endif } /* extra_header_test */