aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/bindump.c
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2010-01-07 11:42:03 -0900
committerDavid M. Syzdek <david@syzdek.net>2010-01-07 11:42:03 -0900
commit55169fd31cf41d021bd31f4efdbec5a114efab6f (patch)
treea677a127284ef3264c2747db5b573066a5683489 /src/bindump.c
parent327699f2d3d6eb766ae1628f1dbd6a769e890b1b (diff)
downloaddmstools-55169fd31cf41d021bd31f4efdbec5a114efab6f.tar.gz
dmstools-55169fd31cf41d021bd31f4efdbec5a114efab6f.tar.bz2
dmstools-55169fd31cf41d021bd31f4efdbec5a114efab6f.tar.xz
dmstools-55169fd31cf41d021bd31f4efdbec5a114efab6f.zip
Creating function for closing files in bindump
Diffstat (limited to 'src/bindump.c')
-rw-r--r--src/bindump.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/bindump.c b/src/bindump.c
index f91e9c4..248920d 100644
--- a/src/bindump.c
+++ b/src/bindump.c
@@ -142,6 +142,9 @@ struct bindump_file
142// main statement 142// main statement
143int main PARAMS((int argc, char * argv[])); 143int main PARAMS((int argc, char * argv[]));
144 144
145// closes a file
146int my_close PARAMS((BinDumpFile * file, uint32_t verbose));
147
145//displays usage information 148//displays usage information
146void my_usage PARAMS((void)); 149void my_usage PARAMS((void));
147 150
@@ -281,9 +284,7 @@ int main(int argc, char * argv[])
281 if ((lseek(file1.fd, (off_t)offset, SEEK_SET) == -1)) 284 if ((lseek(file1.fd, (off_t)offset, SEEK_SET) == -1))
282 { 285 {
283 perror(PROGRAM_NAME ": lseek()"); 286 perror(PROGRAM_NAME ": lseek()");
284 if (verbose) 287 my_close(&file1, verbose);
285 printf("closing file...\n");
286 close(file1.fd);
287 return(1); 288 return(1);
288 }; 289 };
289 file1.pos += offset; 290 file1.pos += offset;
@@ -301,11 +302,9 @@ int main(int argc, char * argv[])
301 if ((file1.code = read(file1.fd, file1.data, 8)) == -1) 302 if ((file1.code = read(file1.fd, file1.data, 8)) == -1)
302 { 303 {
303 perror(PROGRAM_NAME ": read()"); 304 perror(PROGRAM_NAME ": read()");
304 if (verbose > 2) 305 my_close(&file1, verbose);
305 printf("closing file...\n");
306 if (verbose > 0) 306 if (verbose > 0)
307 printf("read %zu bytes\n", (file1.pos-offset)); 307 printf("read %zu bytes\n", (file1.pos-offset));
308 close(file1.fd);
309 return(1); 308 return(1);
310 }; 309 };
311 for(s = offset_mod; ((s < 8) && ((s-offset_mod) < ((size_t)file1.code))); s++) 310 for(s = offset_mod; ((s < 8) && ((s-offset_mod) < ((size_t)file1.code))); s++)
@@ -333,21 +332,14 @@ int main(int argc, char * argv[])
333 if (file1.code == -1) 332 if (file1.code == -1)
334 { 333 {
335 perror(PROGRAM_NAME ": read()"); 334 perror(PROGRAM_NAME ": read()");
336 if (verbose > 2) 335 my_close(&file1, verbose);
337 printf("closing file...\n");
338 if (verbose > 0) 336 if (verbose > 0)
339 printf("read %zu bytes\n", (file1.pos-offset)); 337 printf("read %zu bytes\n", (file1.pos-offset));
340 close(file1.fd);
341 return(1); 338 return(1);
342 }; 339 };
343 340
344 // close file and finish up 341 // close file and finish up
345 if (file1.fd != STDIN_FILENO) 342 my_close(&file1, verbose);
346 {
347 if (verbose > 2)
348 printf("closing file...\n");
349 close(file1.fd);
350 };
351 if (verbose > 0) 343 if (verbose > 0)
352 printf("read %zu bytes\n", (file1.pos-offset)); 344 printf("read %zu bytes\n", (file1.pos-offset));
353 printf("\n"); 345 printf("\n");
@@ -356,6 +348,19 @@ int main(int argc, char * argv[])
356} 348}
357 349
358 350
351/// closes a file
352/// @param[in] file file to use for operations
353/// @param[in] verbose verbose level of messages to display
354int my_close(BinDumpFile * file, uint32_t verbose)
355{
356 if (file->fd == STDIN_FILENO)
357 return(0);
358 if (verbose > 2)
359 printf("closing file %s...\n", file->filename);
360 return(close(file->fd));
361}
362
363
359/// displays usage information 364/// displays usage information
360void my_usage() 365void my_usage()
361{ 366{