mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
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 <wk@gnupg.org>
This commit is contained in:
parent
5556eca5ac
commit
0039d7107b
5 changed files with 54 additions and 37 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue