summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2025-12-23 08:17:29 +0100
committerNIIBE Yutaka <[email protected]>2025-12-23 08:26:42 +0100
commit936015d49c389a6cafc40025f7881625ded90120 (patch)
treec651447cd0e285e947c54059011ae79f0e7e0c4e /src
parentFix a regression wrt the auto-key-locate option. (diff)
downloadgpgme-936015d49c389a6cafc40025f7881625ded90120.tar.gz
gpgme-936015d49c389a6cafc40025f7881625ded90120.zip
w32: Fix spawn for 64-bit machine.
* src/priv-io.h (struct spawn_fd_item_s): Use HANDLE for peer_name field. * src/dirinfo.c (read_gpgconf_dirs): Use ASSUAN_INVALID_FD for default value for peer_name field of CFD. * src/engine-gpgconf.c (gpgconf_read, gpgconf_write) (gpgconf_query_swdb): Likewise. * src/version.c (_gpgme_get_program_version): Likewise. * src/w32-io.c (handle_to_fd): Remove. (_gpgme_io_spawn): Assign HD to the peer_name field. Use %p for printing the value of peer_name field. * src/gpgme-w32spawn.c (my_spawn): Use peer_name field with no cast. Use %p for printing the value of peer_name field. Remove wrong CloseHandle calls. (translate_get_from_file): Use HANDLE type for the TO variable. Use strtoull on 64-bit machine. Use ASSUAN_INVALID_FD. -- Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/dirinfo.c3
-rw-r--r--src/engine-gpgconf.c9
-rw-r--r--src/gpgme-w32spawn.c25
-rw-r--r--src/priv-io.h4
-rw-r--r--src/version.c3
-rw-r--r--src/w32-io.c10
6 files changed, 31 insertions, 23 deletions
diff --git a/src/dirinfo.c b/src/dirinfo.c
index a0753191..0276962f 100644
--- a/src/dirinfo.c
+++ b/src/dirinfo.c
@@ -221,7 +221,8 @@ read_gpgconf_dirs (const char *pgmname, int components)
int linelen = 0;
char * argv[3];
int rp[2];
- struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */, -1, 0},
+ struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */,
+ ASSUAN_INVALID_FD, 0},
{-1, -1} };
int status;
int nread;
diff --git a/src/engine-gpgconf.c b/src/engine-gpgconf.c
index d1b977ad..f7d1f3bb 100644
--- a/src/engine-gpgconf.c
+++ b/src/engine-gpgconf.c
@@ -230,7 +230,8 @@ gpgconf_read (void *engine, const char *arg1, char *arg2,
char *argv[6];
int argc = 0;
int rp[2];
- struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */, -1, 0},
+ struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */,
+ ASSUAN_INVALID_FD, 0},
{-1, -1} };
int status;
int nread;
@@ -717,7 +718,8 @@ gpgconf_write (void *engine, const char *arg1, char *arg2, gpgme_data_t conf)
int rp[2] = { -1, -1 };
int errp[2] = { -1, -1 };
struct spawn_fd_item_s cfd[] = { {-1, 0 /* STDIN_FILENO */},
- {-1, 2 /* STDERR_FILENO */, -1},
+ {-1, 2 /* STDERR_FILENO */,
+ ASSUAN_INVALID_FD},
{-1, -1} };
int status;
int nwrite;
@@ -1135,7 +1137,8 @@ gpgconf_query_swdb (void *engine,
char *argv[7];
int argc = 0;
int rp[2];
- struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */, -1, 0},
+ struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */,
+ ASSUAN_INVALID_FD, 0},
{-1, -1} };
int status;
int nread;
diff --git a/src/gpgme-w32spawn.c b/src/gpgme-w32spawn.c
index 56918c96..b0d8a5cd 100644
--- a/src/gpgme-w32spawn.c
+++ b/src/gpgme-w32spawn.c
@@ -159,21 +159,21 @@ my_spawn (wchar_t **argv, struct spawn_fd_item_s *fd_list, unsigned int flags)
/* The handle already is inheritable. */
if (fd_list[i].dup_to == 0)
{
- si.hStdInput = (HANDLE) fd_list[i].peer_name;
+ si.hStdInput = fd_list[i].peer_name;
duped_stdin = 1;
- fprintf (mystderr, PGM": dup 0x%x to stdin\n", fd_list[i].peer_name);
+ fprintf (mystderr, PGM": dup %p to stdin\n", fd_list[i].peer_name);
}
else if (fd_list[i].dup_to == 1)
{
- si.hStdOutput = (HANDLE) fd_list[i].peer_name;
+ si.hStdOutput = fd_list[i].peer_name;
duped_stdout = 1;
- fprintf (mystderr, PGM": dup 0x%x to stdout\n", fd_list[i].peer_name);
+ fprintf (mystderr, PGM": dup %p to stdout\n", fd_list[i].peer_name);
}
else if (fd_list[i].dup_to == 2)
{
- si.hStdError = (HANDLE) fd_list[i].peer_name;
+ si.hStdError = fd_list[i].peer_name;
duped_stderr = 1;
- fprintf (mystderr, PGM":dup 0x%x to stderr\n", fd_list[i].peer_name);
+ fprintf (mystderr, PGM":dup %p to stderr\n", fd_list[i].peer_name);
}
}
@@ -234,9 +234,6 @@ my_spawn (wchar_t **argv, struct spawn_fd_item_s *fd_list, unsigned int flags)
if (hnul != INVALID_HANDLE_VALUE)
CloseHandle (hnul);
- for (i = 0; fd_list[i].fd != -1; i++)
- CloseHandle ((HANDLE) fd_list[i].fd);
-
if (flags & IOSPAWN_FLAG_ALLOW_SET_FG)
{
static int initialized;
@@ -317,7 +314,7 @@ translate_get_from_file (const wchar_t *trans_file,
{
unsigned long from;
long dup_to;
- unsigned long to;
+ HANDLE to;
unsigned long loc;
char *tail;
@@ -359,7 +356,11 @@ translate_get_from_file (const wchar_t *trans_file,
linep++;
if (*linep == '\0')
break;
- to = strtoul (linep, &tail, 0);
+#if HAVE_W64_SYSTEM
+ to = (HANDLE)strtoull (linep, &tail, 0);
+#else
+ to = (HANDLE)strtoul (linep, &tail, 0);
+#endif
if (tail == NULL || ! (*tail == '\0' || isspace (*tail)))
break;
linep = tail;
@@ -380,7 +381,7 @@ translate_get_from_file (const wchar_t *trans_file,
}
fd_list[idx].fd = -1;
fd_list[idx].dup_to = -1;
- fd_list[idx].peer_name = -1;
+ fd_list[idx].peer_name = ASSUAN_INVALID_FD;
fd_list[idx].arg_loc = 0;
return 0;
}
diff --git a/src/priv-io.h b/src/priv-io.h
index dbfb3a47..21734b8e 100644
--- a/src/priv-io.h
+++ b/src/priv-io.h
@@ -47,7 +47,11 @@ struct spawn_fd_item_s
{
int fd;
int dup_to;
+#ifdef HAVE_W32_SYSTEM
+ HANDLE peer_name;
+#else
int peer_name;
+#endif
int arg_loc;
};
diff --git a/src/version.c b/src/version.c
index d5b171f2..588ab0c9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -315,7 +315,8 @@ _gpgme_get_program_version (const char *const file_name)
int rp[2];
int nread;
char *argv[] = {NULL /* file_name */, (char*)"--version", 0};
- struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */, -1, 0},
+ struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */,
+ ASSUAN_INVALID_FD, 0},
{-1, -1} };
int status;
diff --git a/src/w32-io.c b/src/w32-io.c
index 5fcaf78a..bd528276 100644
--- a/src/w32-io.c
+++ b/src/w32-io.c
@@ -47,8 +47,6 @@
* lower value and dynamically resize the table. */
#define MAX_SLAFD 512
-#define handle_to_fd(a) ((int)(a))
-
#define READBUF_SIZE 4096
#define WRITEBUF_SIZE 4096
#define PIPEBUF_SIZE 4096
@@ -1541,7 +1539,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
return TRACE_SYSRES (-1);
}
/* Return the child name of this handle. */
- fd_list[i].peer_name = handle_to_fd (hd);
+ fd_list[i].peer_name = hd;
}
/* Write the handle translation information to the temporary
@@ -1567,7 +1565,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
len = strlen (line) - 1;
/* Format is: Local name, stdin/stdout/stderr, peer name, argv idx. */
- snprintf (&line[len], BUFFER_MAX - len, "0x%x %d 0x%x %d \n",
+ snprintf (&line[len], BUFFER_MAX - len, "0x%x %d %p %d \n",
fd_list[i].fd, fd_list[i].dup_to,
fd_list[i].peer_name, fd_list[i].arg_loc);
/* Rather safe than sorry. */
@@ -1620,10 +1618,10 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
for (i = 0; fd_list[i].fd != -1; i++)
if (fd_list[i].dup_to == -1)
- TRACE_LOG ("fd[%i] = 0x%x -> 0x%x", i, fd_list[i].fd,
+ TRACE_LOG ("fd[%i] = 0x%x -> %p", i, fd_list[i].fd,
fd_list[i].peer_name);
else
- TRACE_LOG ("fd[%i] = 0x%x -> 0x%x (std%s)", i, fd_list[i].fd,
+ TRACE_LOG ("fd[%i] = 0x%x -> %p (std%s)", i, fd_list[i].fd,
fd_list[i].peer_name, (fd_list[i].dup_to == 0) ? "in" :
((fd_list[i].dup_to == 1) ? "out" : "err"));