summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2022-09-16 07:45:12 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2022-09-16 07:45:12 +0900
commit1d9fa478efd45c53acf357cca67d974cf8e8f699 (patch)
treefa560a259a14d23a9c10bd93e9b016e571d117ff /common
parent1e860c1f8b2b0b48617f2ca664aa9acf2fafc8d3 (diff)
downloadgpg2-upstream/2.2.39.tar.gz
gpg2-upstream/2.2.39.tar.bz2
gpg2-upstream/2.2.39.zip
Imported Upstream version 2.2.39upstream/2.2.39
Diffstat (limited to 'common')
-rw-r--r--common/gettime.c41
-rw-r--r--common/iobuf.c8
-rw-r--r--common/name-value.c13
3 files changed, 56 insertions, 6 deletions
diff --git a/common/gettime.c b/common/gettime.c
index 03c152f..3fe30ce 100644
--- a/common/gettime.c
+++ b/common/gettime.c
@@ -676,6 +676,46 @@ isotimestamp (u32 stamp)
}
+/* Windows version of strftime returning the string as utf-8. */
+#ifdef HAVE_W32_SYSTEM
+
+#define strftime(a,b,c,d) w32_strftime ((a),(b),(c),(d))
+
+static size_t
+w32_strftime (char *s, size_t max, const char *format, const struct tm *tm)
+{
+ wchar_t *wformatbuf = NULL;
+ const wchar_t *wformat = L"%c %Z";
+ wchar_t wbuf[200];
+ size_t n;
+ char *buf;
+
+ if (strcmp (format, "%c %Z"))
+ {
+ log_debug (" comverted\n");
+ wformatbuf = utf8_to_wchar (format);
+ if (wformatbuf)
+ wformat = wformatbuf;
+ }
+
+ n = wcsftime (wbuf, sizeof wbuf, wformat, tm);
+ xfree (wformatbuf);
+ if (!n)
+ {
+ /* Most likely the buffer is too short - try ISO format instead. */
+ n = wcsftime (wbuf, sizeof wbuf, L"%Y-%m-%d %H:%M:%S", tm);
+ if (!n)
+ wcscpy (wbuf, L"[????" "-??" "-??]");
+ }
+ buf = wchar_to_utf8 (wbuf);
+ mem2str (s, buf? buf : "[????" "-??" "-??]", max);
+ xfree (buf);
+ return strlen (s) + 1;
+}
+#endif /*HAVE_W32_SYSTEM*/
+
+
+
/****************
* Note: this function returns local time
*/
@@ -694,7 +734,6 @@ asctimestamp (u32 stamp)
strcpy (buffer, "????" "-??" "-??");
return buffer;
}
-
tp = localtime( &atime );
#ifdef HAVE_STRFTIME
# if defined(HAVE_NL_LANGINFO)
diff --git a/common/iobuf.c b/common/iobuf.c
index 07edbbe..6370efb 100644
--- a/common/iobuf.c
+++ b/common/iobuf.c
@@ -2201,7 +2201,7 @@ iobuf_temp_to_buffer (iobuf_t a, byte * buffer, size_t buflen)
/* Copies the data from the input iobuf SOURCE to the output iobuf
DEST until either an error is encountered or EOF is reached.
- Returns the number of bytes copies. */
+ Returns the number of bytes copies or (size_t)(-1) on error. */
size_t
iobuf_copy (iobuf_t dest, iobuf_t source)
{
@@ -2214,11 +2214,11 @@ iobuf_copy (iobuf_t dest, iobuf_t source)
size_t max_read = 0;
int err;
- assert (source->use == IOBUF_INPUT || source->use == IOBUF_INPUT_TEMP);
- assert (dest->use == IOBUF_OUTPUT || source->use == IOBUF_OUTPUT_TEMP);
+ log_assert (source->use == IOBUF_INPUT || source->use == IOBUF_INPUT_TEMP);
+ log_assert (dest->use == IOBUF_OUTPUT || source->use == IOBUF_OUTPUT_TEMP);
if (iobuf_error (dest))
- return -1;
+ return (size_t)(-1);
temp = xmalloc (temp_size);
while (1)
diff --git a/common/name-value.c b/common/name-value.c
index 0e9e49c..b9b13d1 100644
--- a/common/name-value.c
+++ b/common/name-value.c
@@ -546,21 +546,32 @@ nve_t
nvc_first (nvc_t pk)
{
nve_t entry;
+
+ if (!pk)
+ return NULL;
+
for (entry = pk->first; entry; entry = entry->next)
if (entry->name)
return entry;
+
return NULL;
}
-/* Get the first entry with the given name. */
+/* Get the first entry with the given name. Return NULL if it does
+ * not exist. */
nve_t
nvc_lookup (nvc_t pk, const char *name)
{
nve_t entry;
+
+ if (!pk)
+ return NULL;
+
for (entry = pk->first; entry; entry = entry->next)
if (entry->name && ascii_strcasecmp (entry->name, name) == 0)
return entry;
+
return NULL;
}