mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
tools:gpgtar: Clean up the use of --status-fd.
* common/sysutils.c (gnupg_parse_fdstr): Rename from gnupg_sys2libc_fdstr, as there is no translation any more. * common/sysutils.h (gnupg_parse_fdstr): Rename from gnupg_sys2libc_fdstr. * tools/gpgtar.c (main): Use gnupg_parse_fdstr, in cleaner way. -- GnuPG-bug-id: 6562 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
7cfbf0dd72
commit
cacb018992
@ -584,20 +584,11 @@ translate_sys2libc_fd_int (int fd, int for_write)
|
|||||||
* (2) Integer representation (by %d of printf).
|
* (2) Integer representation (by %d of printf).
|
||||||
* (3) Hex representation which starts as "0x".
|
* (3) Hex representation which starts as "0x".
|
||||||
*
|
*
|
||||||
* FOR_WRITE is 1 for a file for writing, 0 otherwise.
|
* Then, fill R_SYSHD, according to the value of a file reference.
|
||||||
*
|
|
||||||
* There are two use cases for the function:
|
|
||||||
*
|
|
||||||
* - R_HD != NULL, R_FD == NULL:
|
|
||||||
* Return the value in *R_HD.
|
|
||||||
*
|
|
||||||
* - R_HD == NULL, R_FD != NULL:
|
|
||||||
* Return the value in *R_FD, after translating to a file descriptor.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
gnupg_sys2libc_fdstr (const char *fdstr, int for_write,
|
gnupg_parse_fdstr (const char *fdstr, es_syshd_t *r_syshd)
|
||||||
gnupg_fd_t *r_hd, int *r_fd)
|
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
#ifdef HAVE_W32_SYSTEM
|
#ifdef HAVE_W32_SYSTEM
|
||||||
@ -614,10 +605,8 @@ gnupg_sys2libc_fdstr (const char *fdstr, int for_write,
|
|||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
if (r_hd)
|
r_syshd->type = ES_SYSHD_FD;
|
||||||
*r_hd = (gnupg_fd_t)(uintptr_t)fd;
|
r_syshd->u.fd = fd;
|
||||||
else if (r_fd)
|
|
||||||
*r_fd = fd;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,18 +627,13 @@ gnupg_sys2libc_fdstr (const char *fdstr, int for_write,
|
|||||||
if (errno != 0 || endptr == fdstr || *endptr != '\0')
|
if (errno != 0 || endptr == fdstr || *endptr != '\0')
|
||||||
return gpg_error (GPG_ERR_INV_ARG);
|
return gpg_error (GPG_ERR_INV_ARG);
|
||||||
|
|
||||||
if (r_hd)
|
r_syshd->type = ES_SYSHD_HANDLE;
|
||||||
*r_hd = hd;
|
r_syshd->u.handle = hd;
|
||||||
else if (r_fd)
|
|
||||||
*r_fd = translate_sys2libc_fd (hd, for_write);
|
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
(void)for_write;
|
|
||||||
fd = atoi (fdstr);
|
fd = atoi (fdstr);
|
||||||
if (r_hd)
|
r_syshd->type = ES_SYSHD_FD;
|
||||||
*r_hd = fd;
|
r_syshd->u.fd = fd;
|
||||||
else if (r_fd)
|
|
||||||
*r_fd = fd;
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,7 @@ void gnupg_sleep (unsigned int seconds);
|
|||||||
void gnupg_usleep (unsigned int usecs);
|
void gnupg_usleep (unsigned int usecs);
|
||||||
int translate_sys2libc_fd (gnupg_fd_t fd, int for_write);
|
int translate_sys2libc_fd (gnupg_fd_t fd, int for_write);
|
||||||
int translate_sys2libc_fd_int (int fd, int for_write);
|
int translate_sys2libc_fd_int (int fd, int for_write);
|
||||||
gpg_error_t gnupg_sys2libc_fdstr (const char *fdstr, int for_write,
|
gpg_error_t gnupg_parse_fdstr (const char *fdstr, es_syshd_t *r_syshd);
|
||||||
gnupg_fd_t *r_hd, int *r_fd);
|
|
||||||
int check_special_filename (const char *fname, int for_write, int notranslate);
|
int check_special_filename (const char *fname, int for_write, int notranslate);
|
||||||
FILE *gnupg_tmpfile (void);
|
FILE *gnupg_tmpfile (void);
|
||||||
void gnupg_reopen_std (const char *pgmname);
|
void gnupg_reopen_std (const char *pgmname);
|
||||||
|
@ -511,49 +511,30 @@ main (int argc, char **argv)
|
|||||||
* status fd is passed verbatim to gpg. */
|
* status fd is passed verbatim to gpg. */
|
||||||
if (opt.status_fd)
|
if (opt.status_fd)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
es_syshd_t syshd;
|
||||||
|
|
||||||
#ifdef HAVE_W32_SYSTEM
|
err = gnupg_parse_fdstr (opt.status_fd, &syshd);
|
||||||
gnupg_fd_t hd;
|
|
||||||
|
|
||||||
err = gnupg_sys2libc_fdstr (opt.status_fd, 1, &hd, NULL);
|
|
||||||
if ((uintptr_t)hd == 1)
|
|
||||||
fd = 1;
|
|
||||||
else if ((uintptr_t)hd == 2)
|
|
||||||
fd = 2;
|
|
||||||
#else
|
|
||||||
err = gnupg_sys2libc_fdstr (opt.status_fd, 1, NULL, &fd);
|
|
||||||
#endif
|
|
||||||
if (err)
|
if (err)
|
||||||
log_fatal ("status-fd is invalid: %s\n", gpg_strerror (err));
|
log_fatal ("status-fd is invalid: %s\n", gpg_strerror (err));
|
||||||
|
|
||||||
if (fd == 1)
|
if (syshd.type == ES_SYSHD_FD && syshd.u.fd == 1)
|
||||||
{
|
{
|
||||||
opt.status_stream = es_stdout;
|
opt.status_stream = es_stdout;
|
||||||
if (!skip_crypto)
|
if (!skip_crypto)
|
||||||
log_fatal ("using stdout for the status-fd is not possible\n");
|
log_fatal ("using stdout for the status-fd is not possible\n");
|
||||||
}
|
}
|
||||||
else if (fd == 2)
|
else if (syshd.type == ES_SYSHD_FD && syshd.u.fd == 2)
|
||||||
opt.status_stream = es_stderr;
|
opt.status_stream = es_stderr;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
es_syshd_t syshd;
|
|
||||||
|
|
||||||
#ifdef HAVE_W32_SYSTEM
|
|
||||||
syshd.type = ES_SYSHD_HANDLE;
|
|
||||||
syshd.u.handle = hd;
|
|
||||||
#else
|
|
||||||
syshd.type = ES_SYSHD_FD;
|
|
||||||
syshd.u.fd = fd;
|
|
||||||
#endif
|
|
||||||
opt.status_stream = es_sysopen (&syshd, "w");
|
opt.status_stream = es_sysopen (&syshd, "w");
|
||||||
if (opt.status_stream)
|
if (opt.status_stream)
|
||||||
es_setvbuf (opt.status_stream, NULL, _IOLBF, 0);
|
es_setvbuf (opt.status_stream, NULL, _IOLBF, 0);
|
||||||
}
|
}
|
||||||
if (!opt.status_stream)
|
if (!opt.status_stream)
|
||||||
{
|
{
|
||||||
log_fatal ("can't open fd %d for status output: %s\n",
|
log_fatal ("can't open fd %s for status output: %s\n",
|
||||||
fd, strerror (errno));
|
opt.status_fd, strerror (errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user