aboutsummaryrefslogtreecommitdiffstats
path: root/kbx/keybox-update.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2013-08-29 15:39:35 +0000
committerWerner Koch <[email protected]>2013-08-29 15:39:35 +0000
commit3adfaa9beee4502479b5673c7dfd386680a920c5 (patch)
tree94ed92d57deecfb252542a1fde18258aca2fa7e5 /kbx/keybox-update.c
parentFix commit 04e2c83f. (diff)
downloadgnupg-3adfaa9beee4502479b5673c7dfd386680a920c5.tar.gz
gnupg-3adfaa9beee4502479b5673c7dfd386680a920c5.zip
kbx: Add a few macros for easier readability.
* kbx/keybox-update.c (FILECOPY_INSERT) (FILECOPY_DELETE, FILECOPY_UPDATE): New macros. Replace numbers by them. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-update.c')
-rw-r--r--kbx/keybox-update.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/kbx/keybox-update.c b/kbx/keybox-update.c
index 6428bb20a..1fdf4351c 100644
--- a/kbx/keybox-update.c
+++ b/kbx/keybox-update.c
@@ -31,6 +31,10 @@
#define EXTSEP_S "."
+#define FILECOPY_INSERT 1
+#define FILECOPY_DELETE 2
+#define FILECOPY_UPDATE 3
+
#if !defined(HAVE_FSEEKO) && !defined(fseeko)
@@ -208,9 +212,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
/* Perform insert/delete/update operation.
- mode 1 = insert
- 2 = delete
- 3 = update
+ MODE is one of FILECOPY_INSERT, FILECOPY_DELETE, FILECOPY_UPDATE.
*/
static int
blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
@@ -229,7 +231,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
return gpg_error_from_syserror ();
fp = fopen (fname, "rb");
- if (mode == 1 && !fp && errno == ENOENT)
+ if (mode == FILECOPY_INSERT && !fp && errno == ENOENT)
{
/* Insert mode but file does not exist:
Create a new keybox file. */
@@ -271,7 +273,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
}
/* prepare for insert */
- if (mode == 1)
+ if (mode == FILECOPY_INSERT)
{
/* Copy everything to the new file. */
while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
@@ -290,7 +292,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
}
/* Prepare for delete or update. */
- if ( mode == 2 || mode == 3 )
+ if ( mode == FILECOPY_DELETE || mode == FILECOPY_UPDATE )
{
off_t current = 0;
@@ -324,7 +326,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
}
/* Do an insert or update. */
- if ( mode == 1 || mode == 3 )
+ if ( mode == FILECOPY_INSERT || mode == FILECOPY_UPDATE )
{
rc = _keybox_write_blob (blob, newfp);
if (rc)
@@ -332,7 +334,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
}
/* Copy the rest of the packet for an delete or update. */
- if (mode == 2 || mode == 3)
+ if (mode == FILECOPY_DELETE || mode == FILECOPY_UPDATE)
{
while ( (nread = fread (buffer, 1, DIM(buffer), fp)) > 0 )
{
@@ -407,7 +409,7 @@ keybox_insert_keyblock (KEYBOX_HANDLE hd, const void *image, size_t imagelen,
_keybox_destroy_openpgp_info (&info);
if (!err)
{
- err = blob_filecopy (1, fname, blob, hd->secret, 0);
+ err = blob_filecopy (FILECOPY_INSERT, fname, blob, hd->secret, 0);
_keybox_release_blob (blob);
/* if (!rc && !hd->secret && kb_offtbl) */
/* { */
@@ -456,7 +458,7 @@ keybox_insert_cert (KEYBOX_HANDLE hd, ksba_cert_t cert,
rc = _keybox_create_x509_blob (&blob, cert, sha1_digest, hd->ephemeral);
if (!rc)
{
- rc = blob_filecopy (1, fname, blob, hd->secret, 0);
+ rc = blob_filecopy (FILECOPY_INSERT, fname, blob, hd->secret, 0);
_keybox_release_blob (blob);
/* if (!rc && !hd->secret && kb_offtbl) */
/* { */