From a7dbf11954873c6c58a36b57028ced4ecd45bdc6 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 4 May 2023 11:55:26 +0200 Subject: kbx: Add extra flags to fopen for use by Windows. * kbx/keybox-search.c (open_file): Use sysopen and sequential. * kbx/keybox-update.c (create_tmp_file): Ditto. (blob_filecopy): Ditto. (keybox_set_flags): Ditto. (keybox_delete): Ditto. (keybox_compress): Ditto. -- Under Windows "sysopen" requests that direct API calls (CreateFile et al.) are used instead of the libc wrappers. This may or may not improve the performance. Using "sequential" is a hint to Windows to assume that a file is in general access in a sequential manner. This will have an affect only with a future libgpg-error. --- kbx/keybox-search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kbx/keybox-search.c') diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c index 8dea7cb8e..7645fba4f 100644 --- a/kbx/keybox-search.c +++ b/kbx/keybox-search.c @@ -878,7 +878,7 @@ static gpg_error_t open_file (KEYBOX_HANDLE hd) { - hd->fp = es_fopen (hd->kb->fname, "rb"); + hd->fp = es_fopen (hd->kb->fname, "rb,sysopen,sequential"); if (!hd->fp) { hd->error = gpg_error_from_syserror (); -- cgit v1.2.3 From a6c4d6413ae0af3b3ed0d697618699233c8607cc Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 5 May 2023 11:37:44 +0200 Subject: kbx: Use wrapper functions for es_fclose and es_fopen. * kbx/keybox-defs.h (KEYBOX_LL_OPEN_READ) (KEYBOX_LL_OPEN_UPDATE, KEYBOX_LL_OPEN_CREATE): New. * kbx/keybox-init.c (_keybox_ll_open): New. Replace all keybox use of es_fopen by this function. (_keybox_ll_close): New. Replace all keybox use of es_fclose by this function. -- Note that this has not been done for the utilities and the backend-kbx of keyboxd. --- kbx/keybox-search.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'kbx/keybox-search.c') diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c index 7645fba4f..31ea0ba60 100644 --- a/kbx/keybox-search.c +++ b/kbx/keybox-search.c @@ -873,28 +873,12 @@ release_sn_array (struct sn_array_s *array, size_t size) } -/* Helper to open the file. */ -static gpg_error_t -open_file (KEYBOX_HANDLE hd) -{ - - hd->fp = es_fopen (hd->kb->fname, "rb,sysopen,sequential"); - if (!hd->fp) - { - hd->error = gpg_error_from_syserror (); - return hd->error; - } - - return 0; -} - - /* - - The search API - -*/ + * + * The search API + * + */ gpg_error_t keybox_search_reset (KEYBOX_HANDLE hd) @@ -914,7 +898,7 @@ keybox_search_reset (KEYBOX_HANDLE hd) { /* Ooops. Seek did not work. Close so that the search will * open the file again. */ - es_fclose (hd->fp); + _keybox_ll_close (hd->fp); hd->fp = NULL; } } @@ -992,7 +976,7 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc, if (!hd->fp) { - rc = open_file (hd); + rc = _keybox_ll_open (&hd->fp, hd->kb->fname, 0); if (rc) { xfree (sn_array); @@ -1480,7 +1464,7 @@ keybox_seek (KEYBOX_HANDLE hd, off_t offset) return 0; } - err = open_file (hd); + err = _keybox_ll_open (&hd->fp, hd->kb->fname, 0); if (err) return err; } -- cgit v1.2.3