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>
This commit is contained in:
parent
c94ee1386e
commit
390497ea11
23 changed files with 220 additions and 216 deletions
|
@ -231,7 +231,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;
|
||||
|
||||
|
@ -239,10 +239,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
|
||||
|
@ -254,8 +252,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);
|
||||
|
@ -271,30 +269,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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue