mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
w32: Replace some fopen by es_fopen.
* agent/protect-tool.c (read_file): Replace fopen by es_fopen. * dirmngr/dirmngr-client.c (read_pem_certificate): Ditto. (read_certificate): Ditto. * g10/keydb.c (rt_from_file): Ditto. * kbx/kbxutil.c (read_file): Ditto. * g10/plaintext.c (get_output_file) [__riscos__]: Remove code. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
dd2703096f
commit
d574213ce2
@ -237,7 +237,7 @@ make_advanced (const unsigned char *buf, size_t buflen)
|
||||
static char *
|
||||
read_file (const char *fname, size_t *r_length)
|
||||
{
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
|
||||
@ -245,10 +245,8 @@ read_file (const char *fname, size_t *r_length)
|
||||
{
|
||||
size_t nread, bufsize = 0;
|
||||
|
||||
fp = stdin;
|
||||
#ifdef HAVE_DOSISH_SYSTEM
|
||||
setmode ( fileno(fp) , O_BINARY );
|
||||
#endif
|
||||
fp = es_stdin;
|
||||
es_set_binary (fp);
|
||||
buf = NULL;
|
||||
buflen = 0;
|
||||
#define NCHUNK 8192
|
||||
@ -260,8 +258,8 @@ read_file (const char *fname, size_t *r_length)
|
||||
else
|
||||
buf = xrealloc (buf, bufsize);
|
||||
|
||||
nread = fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && ferror (fp))
|
||||
nread = es_fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && es_ferror (fp))
|
||||
{
|
||||
log_error ("error reading '[stdin]': %s\n", strerror (errno));
|
||||
xfree (buf);
|
||||
@ -277,30 +275,30 @@ read_file (const char *fname, size_t *r_length)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
fp = fopen (fname, "rb");
|
||||
fp = es_fopen (fname, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
log_error ("can't open '%s': %s\n", fname, strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fstat (fileno(fp), &st))
|
||||
if (fstat (es_fileno (fp), &st))
|
||||
{
|
||||
log_error ("can't stat '%s': %s\n", fname, strerror (errno));
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buflen = st.st_size;
|
||||
buf = xmalloc (buflen+1);
|
||||
if (fread (buf, buflen, 1, fp) != 1)
|
||||
if (es_fread (buf, buflen, 1, fp) != 1)
|
||||
{
|
||||
log_error ("error reading '%s': %s\n", fname, strerror (errno));
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
xfree (buf);
|
||||
return NULL;
|
||||
}
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
}
|
||||
|
||||
*r_length = buflen;
|
||||
|
@ -461,7 +461,7 @@ data_cb (void *opaque, const void *buffer, size_t length)
|
||||
static gpg_error_t
|
||||
read_pem_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
{
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
int c;
|
||||
int pos;
|
||||
int value;
|
||||
@ -475,16 +475,16 @@ read_pem_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
|
||||
init_asctobin ();
|
||||
|
||||
fp = fname? fopen (fname, "r") : stdin;
|
||||
fp = fname? es_fopen (fname, "r") : es_stdin;
|
||||
if (!fp)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
pos = 0;
|
||||
value = 0;
|
||||
bufsize = 8192;
|
||||
buf = xmalloc (bufsize);
|
||||
buflen = 0;
|
||||
while ((c=getc (fp)) != EOF)
|
||||
while ((c=es_getc (fp)) != EOF)
|
||||
{
|
||||
int escaped_c = 0;
|
||||
|
||||
@ -493,10 +493,10 @@ read_pem_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
if (c == '%')
|
||||
{
|
||||
char tmp[2];
|
||||
if ((c = getc(fp)) == EOF)
|
||||
if ((c = es_getc(fp)) == EOF)
|
||||
break;
|
||||
tmp[0] = c;
|
||||
if ((c = getc(fp)) == EOF)
|
||||
if ((c = es_getc(fp)) == EOF)
|
||||
break;
|
||||
tmp[1] = c;
|
||||
if (!hexdigitp (tmp) || !hexdigitp (tmp+1))
|
||||
@ -504,7 +504,7 @@ read_pem_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
log_error ("invalid percent escape sequence\n");
|
||||
state = s_idle; /* Force an error. */
|
||||
/* Skip to end of line. */
|
||||
while ( (c=getc (fp)) != EOF && c != '\n')
|
||||
while ( (c=es_getc (fp)) != EOF && c != '\n')
|
||||
;
|
||||
goto ready;
|
||||
}
|
||||
@ -593,7 +593,7 @@ read_pem_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
}
|
||||
ready:
|
||||
if (fname)
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
|
||||
if (state == s_init && c == EOF)
|
||||
{
|
||||
@ -620,7 +620,7 @@ static gpg_error_t
|
||||
read_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
{
|
||||
gpg_error_t err;
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
unsigned char *buf;
|
||||
size_t nread, bufsize, buflen;
|
||||
|
||||
@ -636,9 +636,9 @@ read_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fp = fname? fopen (fname, "rb") : stdin;
|
||||
fp = fname? es_fopen (fname, "rb") : es_stdin;
|
||||
if (!fp)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
buf = NULL;
|
||||
bufsize = buflen = 0;
|
||||
@ -651,13 +651,13 @@ read_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
else
|
||||
buf = xrealloc (buf, bufsize);
|
||||
|
||||
nread = fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && ferror (fp))
|
||||
nread = es_fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && es_ferror (fp))
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
xfree (buf);
|
||||
if (fname)
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
return err;
|
||||
}
|
||||
buflen += nread;
|
||||
@ -665,7 +665,7 @@ read_certificate (const char *fname, unsigned char **rbuf, size_t *rbuflen)
|
||||
while (nread == NCHUNK);
|
||||
#undef NCHUNK
|
||||
if (fname)
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
*rbuf = buf;
|
||||
*rbuflen = buflen;
|
||||
return 0;
|
||||
|
12
g10/keydb.c
12
g10/keydb.c
@ -418,22 +418,22 @@ rt_from_file (const char *filename, int *r_found, int *r_openpgp)
|
||||
{
|
||||
u32 magic;
|
||||
unsigned char verbuf[4];
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
KeydbResourceType rt = KEYDB_RESOURCE_TYPE_NONE;
|
||||
|
||||
*r_found = *r_openpgp = 0;
|
||||
fp = fopen (filename, "rb");
|
||||
fp = es_fopen (filename, "rb");
|
||||
if (fp)
|
||||
{
|
||||
*r_found = 1;
|
||||
|
||||
if (fread (&magic, 4, 1, fp) == 1 )
|
||||
if (es_fread (&magic, 4, 1, fp) == 1 )
|
||||
{
|
||||
if (magic == 0x13579ace || magic == 0xce9a5713)
|
||||
; /* GDBM magic - not anymore supported. */
|
||||
else if (fread (&verbuf, 4, 1, fp) == 1
|
||||
else if (es_fread (&verbuf, 4, 1, fp) == 1
|
||||
&& verbuf[0] == 1
|
||||
&& fread (&magic, 4, 1, fp) == 1
|
||||
&& es_fread (&magic, 4, 1, fp) == 1
|
||||
&& !memcmp (&magic, "KBXf", 4))
|
||||
{
|
||||
if ((verbuf[3] & 0x02))
|
||||
@ -446,7 +446,7 @@ rt_from_file (const char *filename, int *r_found, int *r_openpgp)
|
||||
else /* Maybe empty: assume keyring. */
|
||||
rt = KEYDB_RESOURCE_TYPE_KEYRING;
|
||||
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
}
|
||||
|
||||
return rt;
|
||||
|
@ -146,7 +146,6 @@ get_output_file (const byte *embedded_name, int embedded_namelen,
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __riscos__
|
||||
if (opt.outfp && is_secured_file (es_fileno (opt.outfp)))
|
||||
{
|
||||
err = gpg_error (GPG_ERR_EPERM);
|
||||
@ -168,44 +167,6 @@ get_output_file (const byte *embedded_name, int embedded_namelen,
|
||||
log_error (_("error creating '%s': %s\n"), fname, gpg_strerror (err));
|
||||
goto leave;
|
||||
}
|
||||
#else /* __riscos__ */
|
||||
/* If no output filename was given, i.e. we constructed it, convert
|
||||
all '.' in fname to '/' but not vice versa as we don't create
|
||||
directories! */
|
||||
if (!opt.outfile)
|
||||
for (c = 0; fname[c]; ++c)
|
||||
if (fname[c] == '.')
|
||||
fname[c] = '/';
|
||||
|
||||
if (fp || nooutput)
|
||||
;
|
||||
else
|
||||
{
|
||||
/* Note: riscos stuff is not expected to work anymore. If we
|
||||
want to port it again to riscos we should do most of the suff
|
||||
in estream. FIXME: Consider to remove all riscos special
|
||||
cases. */
|
||||
fp = fopen (fname, "wb");
|
||||
if (!fp)
|
||||
{
|
||||
log_error (_("error creating '%s': %s\n"), fname, gpg_strerror (err));
|
||||
err = GPG_ERR_CREATE_FILE;
|
||||
if (errno == 106)
|
||||
log_info ("Do output file and input file have the same name?\n");
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* If there's a ,xxx extension in the embedded filename,
|
||||
use that, else check whether the user input (in fname)
|
||||
has a ,xxx appended, then use that in preference */
|
||||
if ((c = riscos_get_filetype_from_string (embedded_name,
|
||||
embedded_namelen)) != -1)
|
||||
filetype = c;
|
||||
if ((c = riscos_get_filetype_from_string (fname, strlen (fname))) != -1)
|
||||
filetype = c;
|
||||
riscos_set_filetype_by_number (fname, filetype);
|
||||
}
|
||||
#endif /* __riscos__ */
|
||||
|
||||
leave:
|
||||
if (err)
|
||||
|
@ -238,7 +238,7 @@ format_keyid ( const char *s, u32 *kid )
|
||||
static char *
|
||||
read_file (const char *fname, size_t *r_length)
|
||||
{
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
|
||||
@ -246,7 +246,7 @@ read_file (const char *fname, size_t *r_length)
|
||||
{
|
||||
size_t nread, bufsize = 0;
|
||||
|
||||
fp = stdin;
|
||||
fp = es_stdin;
|
||||
buf = NULL;
|
||||
buflen = 0;
|
||||
#define NCHUNK 8192
|
||||
@ -260,8 +260,8 @@ read_file (const char *fname, size_t *r_length)
|
||||
if (!buf)
|
||||
log_fatal ("can't allocate buffer: %s\n", strerror (errno));
|
||||
|
||||
nread = fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && ferror (fp))
|
||||
nread = es_fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && es_ferror (fp))
|
||||
{
|
||||
log_error ("error reading '[stdin]': %s\n", strerror (errno));
|
||||
xfree (buf);
|
||||
@ -277,17 +277,17 @@ read_file (const char *fname, size_t *r_length)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
fp = fopen (fname, "rb");
|
||||
fp = es_fopen (fname, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
log_error ("can't open '%s': %s\n", fname, strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fstat (fileno(fp), &st))
|
||||
if (fstat (es_fileno(fp), &st))
|
||||
{
|
||||
log_error ("can't stat '%s': %s\n", fname, strerror (errno));
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -295,14 +295,14 @@ read_file (const char *fname, size_t *r_length)
|
||||
buf = xtrymalloc (buflen+1);
|
||||
if (!buf)
|
||||
log_fatal ("can't allocate buffer: %s\n", strerror (errno));
|
||||
if (fread (buf, buflen, 1, fp) != 1)
|
||||
if (es_fread (buf, buflen, 1, fp) != 1)
|
||||
{
|
||||
log_error ("error reading '%s': %s\n", fname, strerror (errno));
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
xfree (buf);
|
||||
return NULL;
|
||||
}
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
}
|
||||
|
||||
*r_length = buflen;
|
||||
|
Loading…
x
Reference in New Issue
Block a user