diff options
| author | David M. Syzdek <david@syzdek.net> | 2010-01-07 11:44:32 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2010-01-07 11:48:25 -0900 |
| commit | f47c2341e09142c28da6ddb0bb799bf5302f87e1 (patch) | |
| tree | 0fd37b6b93f68a6aca822e46f8c6a5a9b716f86d /src/bindump.c | |
| parent | 55169fd31cf41d021bd31f4efdbec5a114efab6f (diff) | |
| download | dmstools-f47c2341e09142c28da6ddb0bb799bf5302f87e1.tar.gz dmstools-f47c2341e09142c28da6ddb0bb799bf5302f87e1.tar.bz2 dmstools-f47c2341e09142c28da6ddb0bb799bf5302f87e1.tar.xz dmstools-f47c2341e09142c28da6ddb0bb799bf5302f87e1.zip | |
Creating custom lseek function for bindump
Diffstat (limited to 'src/bindump.c')
| -rw-r--r-- | src/bindump.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/bindump.c b/src/bindump.c index 248920d..0e17c40 100644 --- a/src/bindump.c +++ b/src/bindump.c | |||
| @@ -145,6 +145,9 @@ int main PARAMS((int argc, char * argv[])); | |||
| 145 | // closes a file | 145 | // closes a file |
| 146 | int my_close PARAMS((BinDumpFile * file, uint32_t verbose)); | 146 | int my_close PARAMS((BinDumpFile * file, uint32_t verbose)); |
| 147 | 147 | ||
| 148 | // preforms lseek on file | ||
| 149 | int my_lseek PARAMS((BinDumpFile * file, size_t offset, uint32_t verbose)); | ||
| 150 | |||
| 148 | //displays usage information | 151 | //displays usage information |
| 149 | void my_usage PARAMS((void)); | 152 | void my_usage PARAMS((void)); |
| 150 | 153 | ||
| @@ -281,13 +284,8 @@ int main(int argc, char * argv[]) | |||
| 281 | { | 284 | { |
| 282 | if (verbose > 2) | 285 | if (verbose > 2) |
| 283 | printf("offsetting by %zi bytes...\n", offset); | 286 | printf("offsetting by %zi bytes...\n", offset); |
| 284 | if ((lseek(file1.fd, (off_t)offset, SEEK_SET) == -1)) | 287 | if ((my_lseek(&file1, offset, verbose) == -1)) |
| 285 | { | ||
| 286 | perror(PROGRAM_NAME ": lseek()"); | ||
| 287 | my_close(&file1, verbose); | ||
| 288 | return(1); | 288 | return(1); |
| 289 | }; | ||
| 290 | file1.pos += offset; | ||
| 291 | }; | 289 | }; |
| 292 | 290 | ||
| 293 | // fill in white space so the offset markings align with the position in the file | 291 | // fill in white space so the offset markings align with the position in the file |
| @@ -361,6 +359,23 @@ int my_close(BinDumpFile * file, uint32_t verbose) | |||
| 361 | } | 359 | } |
| 362 | 360 | ||
| 363 | 361 | ||
| 362 | /// preforms lseek on file | ||
| 363 | /// @param[in] file file to use for operations | ||
| 364 | /// @param[in] offset offset | ||
| 365 | /// @param[in] verbose verbose level of messages to display | ||
| 366 | int my_lseek(BinDumpFile * file, size_t offset, uint32_t verbose) | ||
| 367 | { | ||
| 368 | if ((lseek(file->fd, (off_t)offset, SEEK_SET) == -1)) | ||
| 369 | { | ||
| 370 | perror(PROGRAM_NAME ": lseek()"); | ||
| 371 | my_close(file, verbose); | ||
| 372 | return(-1); | ||
| 373 | }; | ||
| 374 | file->pos += offset; | ||
| 375 | return(0); | ||
| 376 | } | ||
| 377 | |||
| 378 | |||
| 364 | /// displays usage information | 379 | /// displays usage information |
| 365 | void my_usage() | 380 | void my_usage() |
| 366 | { | 381 | { |
