summaryrefslogtreecommitdiffstats
path: root/kbx
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-10-20 11:52:16 +0200
committerWerner Koch <wk@gnupg.org>2020-10-20 12:15:56 +0200
commit390497ea115e1aca93feec297a5bd6ae7b1ba6dd (patch)
tree675448ff809e3f333bba4918e4787eacda7f8190 /kbx
parentReplace all calls to access by gnupg_access (diff)
downloadgnupg2-390497ea115e1aca93feec297a5bd6ae7b1ba6dd.tar.xz
gnupg2-390497ea115e1aca93feec297a5bd6ae7b1ba6dd.zip
Replace most of the remaining stdio calls by estream calls.
-- We need to use es_fopen on Windows to cope with non-ascii file names. This is quite a large but fortunately straightforward change. At a very few places we keep using stdio (for example due to the use of popen). GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'kbx')
-rw-r--r--kbx/backend-kbx.c2
-rw-r--r--kbx/kbxutil.c8
-rw-r--r--kbx/keybox-defs.h6
-rw-r--r--kbx/keybox-dump.c28
-rw-r--r--kbx/keybox-file.c58
-rw-r--r--kbx/keybox-init.c6
-rw-r--r--kbx/keybox-search.c12
-rw-r--r--kbx/keybox-update.c124
-rw-r--r--kbx/keybox.h3
9 files changed, 124 insertions, 123 deletions
diff --git a/kbx/backend-kbx.c b/kbx/backend-kbx.c
index ca72169a0..eff64cfa3 100644
--- a/kbx/backend-kbx.c
+++ b/kbx/backend-kbx.c
@@ -126,7 +126,7 @@ create_keybox (const char *filename)
filename, gpg_strerror (err));
goto leave;
}
- err = _keybox_write_header_blob (NULL, fp, 1);
+ err = _keybox_write_header_blob (fp, 1);
es_fclose (fp);
if (err)
{
diff --git a/kbx/kbxutil.c b/kbx/kbxutil.c
index 45f23d23b..c76809bc4 100644
--- a/kbx/kbxutil.c
+++ b/kbx/kbxutil.c
@@ -423,7 +423,7 @@ import_openpgp (const char *filename, int dryrun)
}
else
{
- fflush (stdout);
+ es_fflush (es_stdout);
log_info ("%s: failed to parse OpenPGP keyblock: %s\n",
filename, gpg_strerror (err));
}
@@ -437,17 +437,17 @@ import_openpgp (const char *filename, int dryrun)
err = _keybox_create_openpgp_blob (&blob, &info, p, nparsed, 0);
if (err)
{
- fflush (stdout);
+ es_fflush (es_stdout);
log_error ("%s: failed to create OpenPGP keyblock: %s\n",
filename, gpg_strerror (err));
}
else
{
- err = _keybox_write_blob (blob, stdout);
+ err = _keybox_write_blob (blob, es_stdout, NULL);
_keybox_release_blob (blob);
if (err)
{
- fflush (stdout);
+ es_fflush (es_stdout);
log_error ("%s: failed to write OpenPGP keyblock: %s\n",
filename, gpg_strerror (err));
}
diff --git a/kbx/keybox-defs.h b/kbx/keybox-defs.h
index da23289d3..0af3aafb3 100644
--- a/kbx/keybox-defs.h
+++ b/kbx/keybox-defs.h
@@ -80,7 +80,7 @@ struct keybox_found_s
struct keybox_handle {
KB_NAME kb;
int secret; /* this is for a secret keybox */
- FILE *fp;
+ estream_t fp;
int eof;
int error;
int ephemeral;
@@ -172,8 +172,8 @@ void _keybox_destroy_openpgp_info (keybox_openpgp_info_t info);
/*-- keybox-file.c --*/
-int _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted);
-int _keybox_write_blob (KEYBOXBLOB blob, FILE *fp);
+int _keybox_read_blob (KEYBOXBLOB *r_blob, estream_t fp, int *skipped_deleted);
+int _keybox_write_blob (KEYBOXBLOB blob, estream_t fp, FILE *outfp);
/*-- keybox-search.c --*/
gpg_err_code_t _keybox_get_flag_location (const unsigned char *buffer,
diff --git a/kbx/keybox-dump.c b/kbx/keybox-dump.c
index a12d683ea..3e66b72a1 100644
--- a/kbx/keybox-dump.c
+++ b/kbx/keybox-dump.c
@@ -647,18 +647,18 @@ update_stats (KEYBOXBLOB blob, struct file_stats_s *s)
-static FILE *
+static estream_t
open_file (const char **filename, FILE *outfp)
{
- FILE *fp;
+ estream_t fp;
if (!*filename)
{
*filename = "-";
- fp = stdin;
+ fp = es_stdin;
}
else
- fp = fopen (*filename, "rb");
+ fp = es_fopen (*filename, "rb");
if (!fp)
{
int save_errno = errno;
@@ -673,7 +673,7 @@ open_file (const char **filename, FILE *outfp)
int
_keybox_dump_file (const char *filename, int stats_only, FILE *outfp)
{
- FILE *fp;
+ estream_t fp;
KEYBOXBLOB blob;
int rc;
unsigned long count = 0;
@@ -726,8 +726,8 @@ _keybox_dump_file (const char *filename, int stats_only, FILE *outfp)
if (rc)
fprintf (outfp, "# error reading '%s': %s\n", filename, gpg_strerror (rc));
- if (fp != stdin)
- fclose (fp);
+ if (fp != es_stdin)
+ es_fclose (fp);
if (stats_only)
{
@@ -787,7 +787,7 @@ cmp_dupitems (const void *arg_a, const void *arg_b)
int
_keybox_dump_find_dups (const char *filename, int print_them, FILE *outfp)
{
- FILE *fp;
+ estream_t fp;
KEYBOXBLOB blob;
int rc;
unsigned long recno = 0;
@@ -849,8 +849,8 @@ _keybox_dump_find_dups (const char *filename, int print_them, FILE *outfp)
rc = 0;
if (rc)
fprintf (outfp, "error reading '%s': %s\n", filename, gpg_strerror (rc));
- if (fp != stdin)
- fclose (fp);
+ if (fp != es_stdin)
+ es_fclose (fp);
qsort (dupitems, dupitems_count, sizeof *dupitems, cmp_dupitems);
@@ -880,7 +880,7 @@ int
_keybox_dump_cut_records (const char *filename, unsigned long from,
unsigned long to, FILE *outfp)
{
- FILE *fp;
+ estream_t fp;
KEYBOXBLOB blob;
int rc;
unsigned long recno = 0;
@@ -894,7 +894,7 @@ _keybox_dump_cut_records (const char *filename, unsigned long from,
break; /* Ready. */
if (recno >= from)
{
- if ((rc = _keybox_write_blob (blob, outfp)))
+ if ((rc = _keybox_write_blob (blob, NULL, outfp)))
{
fprintf (stderr, "error writing output: %s\n",
gpg_strerror (rc));
@@ -909,7 +909,7 @@ _keybox_dump_cut_records (const char *filename, unsigned long from,
if (rc)
fprintf (stderr, "error reading '%s': %s\n", filename, gpg_strerror (rc));
leave:
- if (fp != stdin)
- fclose (fp);
+ if (fp != es_stdin)
+ es_fclose (fp);
return rc;
}
diff --git a/kbx/keybox-file.c b/kbx/keybox-file.c
index 7a1b43aa7..f20001dc2 100644
--- a/kbx/keybox-file.c
+++ b/kbx/keybox-file.c
@@ -48,7 +48,7 @@ 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. */
int
-_keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted)
+_keybox_read_blob (KEYBOXBLOB *r_blob, estream_t fp, int *skipped_deleted)
{
unsigned char *image;
size_t imagelen = 0;
@@ -61,19 +61,19 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted)
again:
if (r_blob)
*r_blob = NULL;
- off = ftello (fp);
+ off = es_ftello (fp);
if (off == (off_t)-1)
return gpg_error_from_syserror ();
- if ((c1 = getc (fp)) == EOF
- || (c2 = getc (fp)) == EOF
- || (c3 = getc (fp)) == EOF
- || (c4 = getc (fp)) == EOF
- || (type = getc (fp)) == EOF)
+ if ((c1 = es_getc (fp)) == EOF
+ || (c2 = es_getc (fp)) == EOF
+ || (c3 = es_getc (fp)) == EOF
+ || (c4 = es_getc (fp)) == EOF
+ || (type = es_getc (fp)) == EOF)
{
- if ( c1 == EOF && !ferror (fp) )
+ if ( c1 == EOF && !es_ferror (fp) )
return -1; /* eof */
- if (!ferror (fp))
+ if (!es_ferror (fp))
return gpg_error (GPG_ERR_TOO_SHORT);
return gpg_error_from_syserror ();
}
@@ -85,7 +85,7 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted)
if (!type)
{
/* Special treatment for empty blobs. */
- if (fseek (fp, imagelen-5, SEEK_CUR))
+ if (es_fseek (fp, imagelen-5, SEEK_CUR))
return gpg_error_from_syserror ();
if (skipped_deleted)
*skipped_deleted = 1;
@@ -96,7 +96,7 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted)
{
/* Seek forward so that the caller may choose to ignore this
record. */
- if (fseek (fp, imagelen-5, SEEK_CUR))
+ if (es_fseek (fp, imagelen-5, SEEK_CUR))
return gpg_error_from_syserror ();
return gpg_error (GPG_ERR_TOO_LARGE);
}
@@ -104,7 +104,7 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted)
if (!r_blob)
{
/* This blob shall be skipped. */
- if (fseek (fp, imagelen-5, SEEK_CUR))
+ if (es_fseek (fp, imagelen-5, SEEK_CUR))
return gpg_error_from_syserror ();
return 0;
}
@@ -114,7 +114,7 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted)
return gpg_error_from_syserror ();
image[0] = c1; image[1] = c2; image[2] = c3; image[3] = c4; image[4] = type;
- if (fread (image+5, imagelen-5, 1, fp) != 1)
+ if (es_fread (image+5, imagelen-5, 1, fp) != 1)
{
gpg_error_t tmperr = gpg_error_from_syserror ();
xfree (image);
@@ -130,7 +130,7 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted)
/* Write the block to the current file position */
int
-_keybox_write_blob (KEYBOXBLOB blob, FILE *fp)
+_keybox_write_blob (KEYBOXBLOB blob, estream_t fp, FILE *outfp)
{
const unsigned char *image;
size_t length;
@@ -140,15 +140,24 @@ _keybox_write_blob (KEYBOXBLOB blob, FILE *fp)
if (length > IMAGELEN_LIMIT)
return gpg_error (GPG_ERR_TOO_LARGE);
- if (fwrite (image, length, 1, fp) != 1)
- return gpg_error_from_syserror ();
+ if (fp)
+ {
+ if (es_fwrite (image, length, 1, fp) != 1)
+ return gpg_error_from_syserror ();
+ }
+ else
+ {
+ if (fwrite (image, length, 1, outfp) != 1)
+ return gpg_error_from_syserror ();
+ }
+
return 0;
}
-/* Write a fresh header type blob. Either FP or STREAM must be used. */
+/* Write a fresh header type blob. */
gpg_error_t
-_keybox_write_header_blob (FILE *fp, estream_t stream, int for_openpgp)
+_keybox_write_header_blob (estream_t fp, int for_openpgp)
{
unsigned char image[32];
u32 val;
@@ -174,15 +183,8 @@ _keybox_write_header_blob (FILE *fp, estream_t stream, int for_openpgp)
image[20+2] = (val >> 8);
image[20+3] = (val );
- if (fp)
- {
- if (fwrite (image, 32, 1, fp) != 1)
- return gpg_error_from_syserror ();
- }
- else
- {
- if (es_fwrite (image, 32, 1, stream) != 1)
- return gpg_error_from_syserror ();
- }
+ if (es_fwrite (image, 32, 1, fp) != 1)
+ return gpg_error_from_syserror ();
+
return 0;
}
diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c
index 248a0a543..48af5c7a1 100644
--- a/kbx/keybox-init.c
+++ b/kbx/keybox-init.c
@@ -180,7 +180,7 @@ keybox_release (KEYBOX_HANDLE hd)
_keybox_release_blob (hd->saved_found.blob);
if (hd->fp)
{
- fclose (hd->fp);
+ es_fclose (hd->fp);
hd->fp = NULL;
}
xfree (hd->word_match.name);
@@ -253,11 +253,11 @@ _keybox_close_file (KEYBOX_HANDLE hd)
{
if (roverhd->fp)
{
- fclose (roverhd->fp);
+ es_fclose (roverhd->fp);
roverhd->fp = NULL;
}
}
- assert (!hd->fp);
+ log_assert (!hd->fp);
}
diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c
index c07cd48c9..5ff9111fa 100644
--- a/kbx/keybox-search.c
+++ b/kbx/keybox-search.c
@@ -880,7 +880,7 @@ static gpg_error_t
open_file (KEYBOX_HANDLE hd)
{
- hd->fp = fopen (hd->kb->fname, "rb");
+ hd->fp = es_fopen (hd->kb->fname, "rb");
if (!hd->fp)
{
hd->error = gpg_error_from_syserror ();
@@ -912,11 +912,11 @@ keybox_search_reset (KEYBOX_HANDLE hd)
if (hd->fp)
{
- if (fseeko (hd->fp, 0, SEEK_SET))
+ if (es_fseeko (hd->fp, 0, SEEK_SET))
{
/* Ooops. Seek did not work. Close so that the search will
* open the file again. */
- fclose (hd->fp);
+ es_fclose (hd->fp);
hd->fp = NULL;
}
}
@@ -1007,7 +1007,7 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc,
* returned a blob which also was not the first one. We now
* need to skip over that blob and hope that the file has
* not changed. */
- if (fseeko (hd->fp, lastfoundoff, SEEK_SET))
+ if (es_fseeko (hd->fp, lastfoundoff, SEEK_SET))
{
rc = gpg_error_from_syserror ();
log_debug ("%s: seeking to last found offset failed: %s\n",
@@ -1462,7 +1462,7 @@ keybox_offset (KEYBOX_HANDLE hd)
{
if (!hd->fp)
return 0;
- return ftello (hd->fp);
+ return es_ftello (hd->fp);
}
gpg_error_t
@@ -1487,7 +1487,7 @@ keybox_seek (KEYBOX_HANDLE hd, off_t offset)
return err;
}
- err = fseeko (hd->fp, offset, SEEK_SET);
+ err = es_fseeko (hd->fp, offset, SEEK_SET);
hd->error = gpg_error_from_errno (err);
return hd->error;
diff --git a/kbx/keybox-update.c b/kbx/keybox-update.c
index e263bc3d6..ddda52ac1 100644
--- a/kbx/keybox-update.c
+++ b/kbx/keybox-update.c
@@ -71,14 +71,14 @@ fseeko (FILE * stream, off_t newpos, int whence)
static int
create_tmp_file (const char *template,
- char **r_bakfname, char **r_tmpfname, FILE **r_fp)
+ char **r_bakfname, char **r_tmpfname, estream_t *r_fp)
{
gpg_error_t err;
err = keybox_tmp_names (template, 0, r_bakfname, r_tmpfname);
if (!err)
{
- *r_fp = fopen (*r_tmpfname, "wb");
+ *r_fp = es_fopen (*r_tmpfname, "wb");
if (!*r_fp)
{
err = gpg_error_from_syserror ();
@@ -162,8 +162,8 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
int secret, int for_openpgp, off_t start_offset)
{
gpg_err_code_t ec;
- FILE *fp, *newfp;
- int rc=0;
+ estream_t fp, newfp;
+ int rc = 0;
char *bakfname = NULL;
char *tmpfname = NULL;
char buffer[4096]; /* (Must be at least 32 bytes) */
@@ -174,30 +174,30 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
if ((ec = gnupg_access (fname, W_OK)))
return gpg_error (ec);
- fp = fopen (fname, "rb");
+ fp = es_fopen (fname, "rb");
if (mode == FILECOPY_INSERT && !fp && errno == ENOENT)
{
/* Insert mode but file does not exist:
Create a new keybox file. */
- newfp = fopen (fname, "wb");
+ newfp = es_fopen (fname, "wb");
if (!newfp )
return gpg_error_from_syserror ();
- rc = _keybox_write_header_blob (newfp, NULL, for_openpgp);
+ rc = _keybox_write_header_blob (newfp, for_openpgp);
if (rc)
{
- fclose (newfp);
+ es_fclose (newfp);
return rc;
}
- rc = _keybox_write_blob (blob, newfp);
+ rc = _keybox_write_blob (blob, newfp, NULL);
if (rc)
{
- fclose (newfp);
+ es_fclose (newfp);
return rc;
}
- if ( fclose (newfp) )
+ if ( es_fclose (newfp) )
return gpg_error_from_syserror ();
/* if (chmod( fname, S_IRUSR | S_IWUSR )) */
@@ -218,7 +218,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
rc = create_tmp_file (fname, &bakfname, &tmpfname, &newfp);
if (rc)
{
- fclose (fp);
+ es_fclose (fp);
goto leave;
}
@@ -230,7 +230,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
/* Copy everything to the new file. If this is for OpenPGP, we
make sure that the openpgp flag is set in the header. (We
failsafe the blob type.) */
- while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
+ while ( (nread = es_fread (buffer, 1, DIM(buffer), fp)) > 0 )
{
if (first_record && for_openpgp
&& buffer[4] == KEYBOX_BLOBTYPE_HEADER)
@@ -239,19 +239,19 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
buffer[7] |= 0x02; /* OpenPGP data may be available. */
}
- if (fwrite (buffer, nread, 1, newfp) != 1)
+ if (es_fwrite (buffer, nread, 1, newfp) != 1)
{
rc = gpg_error_from_syserror ();
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
goto leave;
}
}
- if (ferror (fp))
+ if (es_ferror (fp))
{
rc = gpg_error_from_syserror ();
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
goto leave;
}
}
@@ -267,24 +267,24 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
nbytes = DIM(buffer);
if (current + nbytes > start_offset)
nbytes = start_offset - current;
- nread = fread (buffer, 1, nbytes, fp);
+ nread = es_fread (buffer, 1, nbytes, fp);
if (!nread)
break;
current += nread;
- if (fwrite (buffer, nread, 1, newfp) != 1)
+ if (es_fwrite (buffer, nread, 1, newfp) != 1)
{
rc = gpg_error_from_syserror ();
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
goto leave;
}
}
- if (ferror (fp))
+ if (es_ferror (fp))
{
rc = gpg_error_from_syserror ();
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
goto leave;
}
@@ -292,8 +292,8 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
rc = _keybox_read_blob (NULL, fp, NULL);
if (rc)
{
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
return rc;
}
}
@@ -301,11 +301,11 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
/* Do an insert or update. */
if ( mode == FILECOPY_INSERT || mode == FILECOPY_UPDATE )
{
- rc = _keybox_write_blob (blob, newfp);
+ rc = _keybox_write_blob (blob, newfp, NULL);
if (rc)
{
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
return rc;
}
}
@@ -313,33 +313,33 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
/* Copy the rest of the packet for an delete or update. */
if (mode == FILECOPY_DELETE || mode == FILECOPY_UPDATE)
{
- while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
+ while ( (nread = es_fread (buffer, 1, DIM(buffer), fp)) > 0 )
{
- if (fwrite (buffer, nread, 1, newfp) != 1)
+ if (es_fwrite (buffer, nread, 1, newfp) != 1)
{
rc = gpg_error_from_syserror ();
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
goto leave;
}
}
- if (ferror (fp))
+ if (es_ferror (fp))
{
rc = gpg_error_from_syserror ();
- fclose (fp);
- fclose (newfp);
+ es_fclose (fp);
+ es_fclose (newfp);
goto leave;
}
}
/* Close both files. */
- if (fclose(fp))
+ if (es_fclose(fp))
{
rc = gpg_error_from_syserror ();
- fclose (newfp);
+ es_fclose (newfp);
goto leave;
}
- if (fclose(newfp))
+ if (es_fclose(newfp))
{
rc = gpg_error_from_syserror ();
goto leave;
@@ -504,7 +504,7 @@ keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value)
{
off_t off;
const char *fname;
- FILE *fp;
+ estream_t fp;
gpg_err_code_t ec;
size_t flag_pos, flag_size;
const unsigned char *buffer;
@@ -536,12 +536,12 @@ keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value)
off += flag_pos;
_keybox_close_file (hd);
- fp = fopen (hd->kb->fname, "r+b");
+ fp = es_fopen (hd->kb->fname, "r+b");
if (!fp)
return gpg_error_from_syserror ();
ec = 0;
- if (fseeko (fp, off, SEEK_SET))
+ if (es_fseeko (fp, off, SEEK_SET))
ec = gpg_err_code_from_syserror ();
else
{
@@ -557,7 +557,7 @@ keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value)
case 1:
case 2:
case 4:
- if (fwrite (tmp+4-flag_size, flag_size, 1, fp) != 1)
+ if (es_fwrite (tmp+4-flag_size, flag_size, 1, fp) != 1)
ec = gpg_err_code_from_syserror ();
break;
default:
@@ -566,7 +566,7 @@ keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value)
}
}
- if (fclose (fp))
+ if (es_fclose (fp))
{
if (!ec)
ec = gpg_err_code_from_syserror ();
@@ -582,7 +582,7 @@ keybox_delete (KEYBOX_HANDLE hd)
{
off_t off;
const char *fname;
- FILE *fp;
+ estream_t fp;
int rc;
if (!hd)
@@ -601,18 +601,18 @@ keybox_delete (KEYBOX_HANDLE hd)
off += 4;
_keybox_close_file (hd);
- fp = fopen (hd->kb->fname, "r+b");
+ fp = es_fopen (hd->kb->fname, "r+b");
if (!fp)
return gpg_error_from_syserror ();
- if (fseeko (fp, off, SEEK_SET))
+ if (es_fseeko (fp, off, SEEK_SET))
rc = gpg_error_from_syserror ();
- else if (putc (0, fp) == EOF)
+ else if (es_fputc (0, fp) == EOF)
rc = gpg_error_from_syserror ();
else
rc = 0;
- if (fclose (fp))
+ if (es_fclose (fp))
{
if (!rc)
rc = gpg_error_from_syserror ();
@@ -630,7 +630,7 @@ keybox_compress (KEYBOX_HANDLE hd)
gpg_err_code_t ec;
int read_rc, rc;
const char *fname;
- FILE *fp, *newfp;
+ estream_t fp, newfp;
char *bakfname = NULL;
char *tmpfname = NULL;
int first_blob;
@@ -656,7 +656,7 @@ keybox_compress (KEYBOX_HANDLE hd)
if ((ec = gnupg_access (fname, W_OK)))
return gpg_error (ec);
- fp = fopen (fname, "rb");
+ fp = es_fopen (fname, "rb");
if (!fp && errno == ENOENT)
return 0; /* Ready. File has been deleted right after the access above. */
if (!fp)
@@ -679,21 +679,21 @@ keybox_compress (KEYBOX_HANDLE hd)
if ( (last_maint + 3*3600) > make_timestamp () )
{
- fclose (fp);
+ es_fclose (fp);
_keybox_release_blob (blob);
return 0; /* Compress run not yet needed. */
}
}
_keybox_release_blob (blob);
- fseek (fp, 0, SEEK_SET);
- clearerr (fp);
+ es_fseek (fp, 0, SEEK_SET);
+ es_clearerr (fp);
}
/* Create the new file. */
rc = create_tmp_file (fname, &bakfname, &tmpfname, &newfp);
if (rc)
{
- fclose (fp);
+ es_fclose (fp);
return rc;;
}
@@ -725,14 +725,14 @@ keybox_compress (KEYBOX_HANDLE hd)
stamp and if needed (ie. used by gpg) set the openpgp
flag. */
_keybox_update_header_blob (blob, hd->for_openpgp);
- rc = _keybox_write_blob (blob, newfp);
+ rc = _keybox_write_blob (blob, newfp, NULL);
if (rc)
break;
continue;
}
/* The header blob is missing. Insert it. */
- rc = _keybox_write_header_blob (newfp, NULL, hd->for_openpgp);
+ rc = _keybox_write_header_blob (newfp, hd->for_openpgp);
if (rc)
break;
any_changes = 1;
@@ -769,7 +769,7 @@ keybox_compress (KEYBOX_HANDLE hd)
}
}
- rc = _keybox_write_blob (blob, newfp);
+ rc = _keybox_write_blob (blob, newfp, NULL);
if (rc)
break;
}
@@ -782,9 +782,9 @@ keybox_compress (KEYBOX_HANDLE hd)
rc = read_rc;
/* Close both files. */
- if (fclose(fp) && !rc)
+ if (es_fclose(fp) && !rc)
rc = gpg_error_from_syserror ();
- if (fclose(newfp) && !rc)
+ if (es_fclose(newfp) && !rc)
rc = gpg_error_from_syserror ();
/* Rename or remove the temporary file. */
diff --git a/kbx/keybox.h b/kbx/keybox.h
index 6e5a51c63..9bff271ea 100644
--- a/kbx/keybox.h
+++ b/kbx/keybox.h
@@ -81,8 +81,7 @@ gpg_error_t keybox_lock (KEYBOX_HANDLE hd, int yes, long timeout);
/*-- keybox-file.c --*/
/* Fixme: This function does not belong here: Provide a better
interface to create a new keybox file. */
-gpg_error_t _keybox_write_header_blob (FILE *fp, estream_t stream,
- int openpgp_flag);
+gpg_error_t _keybox_write_header_blob (estream_t fp, int openpgp_flag);
/*-- keybox-search.c --*/
gpg_error_t keybox_get_data (KEYBOX_HANDLE hd,