diff options
author | Werner Koch <[email protected]> | 2017-04-01 09:10:47 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2017-04-01 09:10:47 +0000 |
commit | 0039d7107bcdfce6f3b02b46ff0495cfba07882a (patch) | |
tree | c68d3fb046ecc0a03e37a18b2ed54113bcb2b613 /kbx/keybox-file.c | |
parent | gpg: Avoid multiple open calls to the keybox file. (diff) | |
download | gnupg-0039d7107bcdfce6f3b02b46ff0495cfba07882a.tar.gz gnupg-0039d7107bcdfce6f3b02b46ff0495cfba07882a.zip |
kbx: Unify blob reading functions.
* kbx/keybox-file.c (_keybox_read_blob): Remove.
(_keybox_read_blob2): Rename to ....
(_keybox_read_blob): this. Make arg options. Change all callers.
* kbx/keybox-search.c (keybox_search): Factor fopen call out to ...
(open_file): new.
(keybox_seek): Als use open_file.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-file.c')
-rw-r--r-- | kbx/keybox-file.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/kbx/keybox-file.c b/kbx/keybox-file.c index 0485e81b4..046e32123 100644 --- a/kbx/keybox-file.c +++ b/kbx/keybox-file.c @@ -45,10 +45,10 @@ ftello (FILE *stream) -/* Read a block at the current position and return it in r_blob. - r_blob may be NULL to simply skip the current block. */ +/* Read a block at the current position and return it in R_BLOB. + R_BLOB may be NULL to simply skip the current block. */ int -_keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) +_keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) { unsigned char *image; size_t imagelen = 0; @@ -56,7 +56,8 @@ _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) int rc; off_t off; - *skipped_deleted = 0; + if (skipped_deleted) + *skipped_deleted = 0; again: if (r_blob) *r_blob = NULL; @@ -86,7 +87,8 @@ _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) /* Special treatment for empty blobs. */ if (fseek (fp, imagelen-5, SEEK_CUR)) return gpg_error_from_syserror (); - *skipped_deleted = 1; + if (skipped_deleted) + *skipped_deleted = 1; goto again; } @@ -99,6 +101,14 @@ _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) return gpg_error (GPG_ERR_TOO_LARGE); } + if (!r_blob) + { + /* This blob shall be skipped. */ + if (fseek (fp, imagelen-5, SEEK_CUR)) + return gpg_error_from_syserror (); + return 0; + } + image = xtrymalloc (imagelen); if (!image) return gpg_error_from_syserror (); @@ -111,19 +121,12 @@ _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) return tmperr; } - rc = r_blob? _keybox_new_blob (r_blob, image, imagelen, off) : 0; - if (rc || !r_blob) + rc = _keybox_new_blob (r_blob, image, imagelen, off); + if (rc) xfree (image); return rc; } -int -_keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp) -{ - int dummy; - return _keybox_read_blob2 (r_blob, fp, &dummy); -} - /* Write the block to the current file position */ int |