1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Replace most of the remaining stdio calls by estream calls.

--

We need to use es_fopen on Windows to cope with non-ascii file names.
This is quite a large but fortunately straightforward change.  At a
very few places we keep using stdio (for example due to the use of
popen).

GnuPG-bug-id: 5098
Signed-off-by: Werner Koch <wk@gnupg.org>
Backported-from-master: 390497ea11
This commit is contained in:
Werner Koch 2020-10-20 11:52:16 +02:00
parent dd5fd4a760
commit 5c6e9b44cc
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
20 changed files with 208 additions and 197 deletions

View file

@ -227,7 +227,7 @@ main (int argc, char **argv )
static char *
read_file (const char *fname, size_t *r_length)
{
FILE *fp;
estream_t fp;
char *buf;
size_t buflen;
@ -235,10 +235,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
@ -250,8 +248,8 @@ read_file (const char *fname, size_t *r_length)
else
buf = xrealloc (buf, bufsize+1);
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);
@ -267,30 +265,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);
}
buf[buflen] = 0;
*r_length = buflen;