aboutsummaryrefslogtreecommitdiffstats
path: root/common/estream.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/estream.c')
-rw-r--r--common/estream.c190
1 files changed, 95 insertions, 95 deletions
diff --git a/common/estream.c b/common/estream.c
index 416aa8376..bc820513e 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -357,7 +357,7 @@ map_w32_to_errno (DWORD w32_err)
case ERROR_NOT_ENOUGH_MEMORY:
return ENOMEM;
-
+
case ERROR_NO_DATA:
return EPIPE;
@@ -406,7 +406,7 @@ static void
do_list_remove (estream_t stream, int with_locked_list)
{
estream_list_t list_obj;
-
+
if (!with_locked_list)
ESTREAM_LIST_LOCK;
for (list_obj = estream_list; list_obj; list_obj = list_obj->cdr)
@@ -509,7 +509,7 @@ do_init (void)
#else
initialized = 1;
#endif
- atexit (do_deinit);
+ atexit (do_deinit);
}
return 0;
}
@@ -602,7 +602,7 @@ es_func_mem_read (void *cookie, void *buffer, size_t size)
memcpy (buffer, mem_cookie->memory + mem_cookie->offset, size);
mem_cookie->offset += size;
}
-
+
ret = size;
return ret;
}
@@ -627,7 +627,7 @@ es_func_mem_write (void *cookie, const void *buffer, size_t size)
assert (mem_cookie->memory_size >= mem_cookie->offset);
nleft = mem_cookie->memory_size - mem_cookie->offset;
-
+
/* If we are not allowed to grow limit the size to the left space. */
if (!mem_cookie->flags.grow && size > nleft)
size = nleft;
@@ -668,20 +668,20 @@ es_func_mem_write (void *cookie, const void *buffer, size_t size)
_set_errno (ENOSPC);
return -1;
}
-
+
newbuf = mem_cookie->func_realloc (mem_cookie->memory, newsize);
if (!newbuf)
return -1;
-
+
mem_cookie->memory = newbuf;
mem_cookie->memory_size = newsize;
assert (mem_cookie->memory_size >= mem_cookie->offset);
nleft = mem_cookie->memory_size - mem_cookie->offset;
-
+
assert (size <= nleft);
}
-
+
memcpy (mem_cookie->memory + mem_cookie->offset, buffer, size);
if (mem_cookie->offset + size > mem_cookie->data_len)
mem_cookie->data_len = mem_cookie->offset + size;
@@ -743,7 +743,7 @@ es_func_mem_seek (void *cookie, off_t *offset, int whence)
_set_errno (ENOSPC);
return -1;
}
-
+
newbuf = mem_cookie->func_realloc (mem_cookie->memory, newsize);
if (!newbuf)
return -1;
@@ -825,7 +825,7 @@ func_fd_create (void **cookie, int fd, unsigned int modeflags, int no_close)
*cookie = fd_cookie;
err = 0;
}
-
+
return err;
}
@@ -836,7 +836,7 @@ es_func_fd_read (void *cookie, void *buffer, size_t size)
{
estream_cookie_fd_t file_cookie = cookie;
ssize_t bytes_read;
-
+
if (IS_INVALID_FD (file_cookie->fd))
{
ESTREAM_SYS_YIELD ();
@@ -844,7 +844,7 @@ es_func_fd_read (void *cookie, void *buffer, size_t size)
}
else
{
- do
+ do
bytes_read = ESTREAM_SYS_READ (file_cookie->fd, buffer, size);
while (bytes_read == -1 && errno == EINTR);
}
@@ -969,7 +969,7 @@ es_func_w32_create (void **cookie, HANDLE hd,
*cookie = w32_cookie;
err = 0;
}
-
+
return err;
}
@@ -979,7 +979,7 @@ es_func_w32_read (void *cookie, void *buffer, size_t size)
{
estream_cookie_w32_t w32_cookie = cookie;
ssize_t bytes_read;
-
+
if (w32_cookie->hd == INVALID_HANDLE_VALUE)
{
ESTREAM_SYS_YIELD ();
@@ -994,7 +994,7 @@ es_func_w32_read (void *cookie, void *buffer, size_t size)
bytes_read = pth_read ((int)w32_cookie->hd, buffer, size);
#else
DWORD nread, ec;
-
+
if (!ReadFile (w32_cookie->hd, buffer, size, &nread, NULL))
{
ec = GetLastError ();
@@ -1116,7 +1116,7 @@ es_func_w32_destroy (void *cookie)
else if (w32_cookie->no_close)
err = 0;
else
- {
+ {
if (!CloseHandle (w32_cookie->hd))
{
_set_errno (map_w32_to_errno (GetLastError ()));
@@ -1158,7 +1158,7 @@ typedef struct estream_cookie_fp
/* Create function for FILE objects. */
static int
-func_fp_create (void **cookie, FILE *fp,
+func_fp_create (void **cookie, FILE *fp,
unsigned int modeflags, int no_close)
{
estream_cookie_fp_t fp_cookie;
@@ -1249,7 +1249,7 @@ es_func_fp_seek (void *cookie, off_t *offset, int whence)
if (!file_cookie->fp)
{
_set_errno (ESPIPE);
- return -1;
+ return -1;
}
if ( fseek (file_cookie->fp, (long int)*offset, whence) )
@@ -1415,7 +1415,7 @@ parse_mode (const char *modestr,
case ',':
goto keyvalue;
default: /* Ignore unknown flags. */
- break;
+ break;
}
}
@@ -1536,10 +1536,10 @@ es_flush (estream_t stream)
they were asked to write, we have to check for
"(stream->data_offset - data_flushed) > 0" instead of
"stream->data_offset - data_flushed". */
-
+
data_flushed = 0;
err = 0;
-
+
while ((((ssize_t) (stream->data_offset - data_flushed)) > 0) && (! err))
{
ret = (*func_write) (stream->intern->cookie,
@@ -1573,7 +1573,7 @@ es_flush (estream_t stream)
err = 0;
out:
-
+
if (err)
stream->intern->indicators.err = 1;
@@ -1896,7 +1896,7 @@ es_readn (estream_t ES__RESTRICT stream,
if (err)
goto out;
stream->flags.writing = 0;
- }
+ }
/* Read unread data first. */
while ((bytes_to_read - data_read_unread) && stream->unread_data_len)
@@ -1993,7 +1993,7 @@ es_seek (estream_t ES__RESTRICT stream, off_t offset, int whence,
off = off - stream->data_len + stream->data_offset;
off -= stream->unread_data_len;
}
-
+
ret = (*func_seek) (stream->intern->cookie, &off, whence);
if (ret == -1)
{
@@ -2011,7 +2011,7 @@ es_seek (estream_t ES__RESTRICT stream, off_t offset, int whence,
stream->intern->offset = off;
out:
-
+
if (err)
stream->intern->indicators.err = 1;
@@ -2035,11 +2035,11 @@ es_write_nbf (estream_t ES__RESTRICT stream,
{
err = EOPNOTSUPP;
goto out;
- }
+ }
data_written = 0;
err = 0;
-
+
while (bytes_to_write - data_written)
{
ret = (*func_write) (stream->intern->cookie,
@@ -2087,12 +2087,12 @@ es_write_fbf (estream_t ES__RESTRICT stream,
if (! err)
{
/* Flushing resulted in empty container. */
-
+
data_to_write = bytes_to_write - data_written;
space_available = stream->buffer_size - stream->data_offset;
if (data_to_write > space_available)
data_to_write = space_available;
-
+
memcpy (stream->buffer + stream->data_offset,
buffer + data_written, data_to_write);
stream->data_offset += data_to_write;
@@ -2153,7 +2153,7 @@ es_writen (estream_t ES__RESTRICT stream,
data_written = 0;
err = 0;
-
+
if (!stream->flags.writing)
{
/* Switching to writing mode -> discard input data and seek to
@@ -2188,7 +2188,7 @@ es_writen (estream_t ES__RESTRICT stream,
}
out:
-
+
if (bytes_written)
*bytes_written = data_written;
if (data_written)
@@ -2212,7 +2212,7 @@ es_peek (estream_t ES__RESTRICT stream, unsigned char **ES__RESTRICT data,
if (err)
goto out;
stream->flags.writing = 0;
- }
+ }
if (stream->data_offset == stream->data_len)
{
@@ -2221,7 +2221,7 @@ es_peek (estream_t ES__RESTRICT stream, unsigned char **ES__RESTRICT data,
if (err)
goto out;
}
-
+
if (data)
*data = stream->buffer + stream->data_offset;
if (data_len)
@@ -2277,7 +2277,7 @@ doreadline (estream_t ES__RESTRICT stream, size_t max_length,
err = func_mem_create (&line_stream_cookie, NULL, 0, 0,
BUFFER_BLOCK_SIZE, 1,
- mem_realloc, mem_free,
+ mem_realloc, mem_free,
O_RDWR,
0);
if (err)
@@ -2333,7 +2333,7 @@ doreadline (estream_t ES__RESTRICT stream, size_t max_length,
goto out;
/* Complete line has been written to line_stream. */
-
+
if ((max_length > 1) && (! line_size))
{
stream->intern->indicators.eof = 1;
@@ -2429,7 +2429,7 @@ static int
es_get_indicator (estream_t stream, int ind_err, int ind_eof)
{
int ret = 0;
-
+
if (ind_err)
ret = stream->intern->indicators.err;
else if (ind_eof)
@@ -2456,7 +2456,7 @@ es_set_buffering (estream_t ES__RESTRICT stream,
es_empty (stream);
es_set_indicators (stream, -1, 0);
-
+
/* Free old buffer in case that was allocated by this function. */
if (stream->intern->deallocate_buffer)
{
@@ -2470,7 +2470,7 @@ es_set_buffering (estream_t ES__RESTRICT stream,
else
{
void *buffer_new;
-
+
if (buffer)
buffer_new = buffer;
else
@@ -2560,11 +2560,11 @@ es_fopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode)
err = parse_mode (mode, &modeflags, &cmode);
if (err)
goto out;
-
+
err = func_file_create (&cookie, &fd, path, modeflags, cmode);
if (err)
goto out;
-
+
syshd.type = ES_SYSHD_FD;
syshd.u.fd = fd;
@@ -2577,7 +2577,7 @@ es_fopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode)
fname_set_internal (stream, path, 1);
out:
-
+
if (err && create_called)
(*estream_functions_fd.func_close) (cookie);
@@ -2602,17 +2602,17 @@ es_mopen (unsigned char *ES__RESTRICT data, size_t data_n, size_t data_len,
cookie = 0;
stream = NULL;
create_called = 0;
-
+
err = parse_mode (mode, &modeflags, NULL);
if (err)
goto out;
err = func_mem_create (&cookie, data, data_n, data_len,
- BUFFER_BLOCK_SIZE, grow,
+ BUFFER_BLOCK_SIZE, grow,
func_realloc, func_free, modeflags, 0);
if (err)
goto out;
-
+
memset (&syshd, 0, sizeof syshd);
create_called = 1;
err = es_create (&stream, cookie, &syshd,
@@ -2642,13 +2642,13 @@ es_fopenmem (size_t memlimit, const char *ES__RESTRICT mode)
return NULL;
modeflags |= O_RDWR;
-
+
if (func_mem_create (&cookie, NULL, 0, 0,
BUFFER_BLOCK_SIZE, 1,
mem_realloc, mem_free, modeflags,
memlimit))
return NULL;
-
+
memset (&syshd, 0, sizeof syshd);
if (es_create (&stream, cookie, &syshd, estream_functions_mem, modeflags, 0))
(*estream_functions_mem.func_close) (cookie);
@@ -2670,7 +2670,7 @@ es_fopencookie (void *ES__RESTRICT cookie,
stream = NULL;
modeflags = 0;
-
+
err = parse_mode (mode, &modeflags, NULL);
if (err)
goto out;
@@ -2774,7 +2774,7 @@ do_fpopen (FILE *fp, const char *mode, int no_close, int with_locked_list)
return stream;
}
-
+
/* Create an estream from the stdio stream FP. This mechanism is
useful in case the stdio streams have special properties and may
not be mixed with fd based functions. This is for example the case
@@ -2844,7 +2844,7 @@ do_sysopen (es_syshd_t *syshd, const char *mode, int no_close)
case ES_SYSHD_SOCK:
stream = do_fdopen (syshd->u.fd, mode, no_close, 0);
break;
-
+
#ifdef HAVE_W32_SYSTEM
case ES_SYSHD_HANDLE:
stream = do_w32open (syshd->u.handle, mode, no_close, 0);
@@ -2922,7 +2922,7 @@ _es_get_std_stream (int fd)
stream = do_fdopen (custom_std_fds[1], "a", 1, 1);
else if (custom_std_fds_valid[2])
stream = do_fdopen (custom_std_fds[2], "a", 1, 1);
-
+
if (!stream)
{
/* Second try is to use the standard C streams. */
@@ -2933,8 +2933,8 @@ _es_get_std_stream (int fd)
else
stream = do_fpopen (stderr, "a", 1, 1);
}
-
- if (!stream)
+
+ if (!stream)
{
/* Last try: Create a bit bucket. */
stream = do_fpopen (NULL, fd? "a":"r", 0, 1);
@@ -2950,7 +2950,7 @@ _es_get_std_stream (int fd)
stream->intern->stdstream_fd = fd;
if (fd == 2)
es_set_buffering (stream, NULL, _IOLBF, 0);
- fname_set_internal (stream,
+ fname_set_internal (stream,
fd == 0? "[stdin]" :
fd == 1? "[stdout]" : "[stderr]", 0);
}
@@ -2975,7 +2975,7 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
cookie = NULL;
create_called = 0;
-
+
ESTREAM_LOCK (stream);
es_deinitialize (stream);
@@ -2983,7 +2983,7 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
err = parse_mode (mode, &modeflags, &cmode);
if (err)
goto leave;
-
+
err = func_file_create (&cookie, &fd, path, modeflags, cmode);
if (err)
goto leave;
@@ -2999,7 +2999,7 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
{
if (create_called)
es_func_fd_destroy (cookie);
-
+
do_close (stream, 0);
stream = NULL;
}
@@ -3057,7 +3057,7 @@ es_onclose (estream_t stream, int mode,
ESTREAM_LOCK (stream);
err = do_onclose (stream, mode, fnc, fnc_value);
ESTREAM_UNLOCK (stream);
-
+
return err;
}
@@ -3073,7 +3073,7 @@ es_fileno_unlocked (estream_t stream)
{
case ES_SYSHD_FD: return syshd.u.fd;
case ES_SYSHD_SOCK: return syshd.u.sock;
- default:
+ default:
_set_errno (EINVAL);
return -1;
}
@@ -3094,7 +3094,7 @@ es_syshd_unlocked (estream_t stream, es_syshd_t *syshd)
_set_errno (EINVAL);
return -1;
}
-
+
*syshd = stream->intern->syshd;
return 0;
}
@@ -3211,7 +3211,7 @@ static int
do_fflush (estream_t stream)
{
int err;
-
+
if (stream->flags.writing)
err = es_flush (stream);
else
@@ -3228,7 +3228,7 @@ int
es_fflush (estream_t stream)
{
int err;
-
+
if (stream)
{
ESTREAM_LOCK (stream);
@@ -3259,7 +3259,7 @@ int
es_fseeko (estream_t stream, off_t offset, int whence)
{
int err;
-
+
ESTREAM_LOCK (stream);
err = es_seek (stream, offset, whence, NULL);
ESTREAM_UNLOCK (stream);
@@ -3272,7 +3272,7 @@ long int
es_ftell (estream_t stream)
{
long int ret;
-
+
ESTREAM_LOCK (stream);
ret = es_offset_calculate (stream);
ESTREAM_UNLOCK (stream);
@@ -3333,7 +3333,7 @@ int
es_fgetc (estream_t stream)
{
int ret;
-
+
ESTREAM_LOCK (stream);
ret = es_getc_unlocked (stream);
ESTREAM_UNLOCK (stream);
@@ -3346,7 +3346,7 @@ int
es_fputc (int c, estream_t stream)
{
int ret;
-
+
ESTREAM_LOCK (stream);
ret = es_putc_unlocked (c, stream);
ESTREAM_UNLOCK (stream);
@@ -3458,10 +3458,10 @@ es_fgets (char *ES__RESTRICT buffer, int length, estream_t ES__RESTRICT stream)
{
unsigned char *s = (unsigned char*)buffer;
int c;
-
+
if (!length)
return NULL;
-
+
c = EOF;
ESTREAM_LOCK (stream);
while (length > 1 && (c = es_getc_unlocked (stream)) != EOF && c != '\n')
@@ -3525,7 +3525,7 @@ es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr, size_t *ES__RESTRICT n,
if (*n)
{
/* Caller wants us to use his buffer. */
-
+
if (*n < (line_n + 1))
{
/* Provided buffer is too small -> resize. */
@@ -3569,7 +3569,7 @@ es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr, size_t *ES__RESTRICT n,
considered a byte stream ending in a LF.
If MAX_LENGTH is not NULL, it shall point to a value with the
- maximum allowed allocation.
+ maximum allowed allocation.
Returns the length of the line. EOF is indicated by a line of
length zero. A truncated line is indicated my setting the value at
@@ -3593,7 +3593,7 @@ es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr, size_t *ES__RESTRICT n,
released using es_free.
*/
ssize_t
-es_read_line (estream_t stream,
+es_read_line (estream_t stream,
char **addr_of_buffer, size_t *length_of_buffer,
size_t *max_length)
{
@@ -3605,7 +3605,7 @@ es_read_line (estream_t stream,
char *p;
if (!buffer)
- {
+ {
/* No buffer given - allocate a new one. */
length = 256;
buffer = mem_alloc (length);
@@ -3634,9 +3634,9 @@ es_read_line (estream_t stream,
while ((c = es_getc_unlocked (stream)) != EOF)
{
if (nbytes == length)
- {
+ {
/* Enlarge the buffer. */
- if (maxlen && length > maxlen)
+ if (maxlen && length > maxlen)
{
/* We are beyond our limit: Skip the rest of the line. */
while (c != '\n' && (c=es_getc_unlocked (stream)) != EOF)
@@ -3653,7 +3653,7 @@ es_read_line (estream_t stream,
if (!*addr_of_buffer)
{
int save_errno = errno;
- mem_free (buffer);
+ mem_free (buffer);
*length_of_buffer = 0;
if (max_length)
*max_length = 0;
@@ -3663,7 +3663,7 @@ es_read_line (estream_t stream,
}
buffer = *addr_of_buffer;
*length_of_buffer = length;
- length -= 3;
+ length -= 3;
p = buffer + nbytes;
}
*p++ = c;
@@ -3701,7 +3701,7 @@ es_vfprintf (estream_t ES__RESTRICT stream, const char *ES__RESTRICT format,
va_list ap)
{
int ret;
-
+
ESTREAM_LOCK (stream);
ret = es_print (stream, format, ap);
ESTREAM_UNLOCK (stream);
@@ -3715,7 +3715,7 @@ es_fprintf_unlocked (estream_t ES__RESTRICT stream,
const char *ES__RESTRICT format, ...)
{
int ret;
-
+
va_list ap;
va_start (ap, format);
ret = es_print (stream, format, ap);
@@ -3730,7 +3730,7 @@ es_fprintf (estream_t ES__RESTRICT stream,
const char *ES__RESTRICT format, ...)
{
int ret;
-
+
va_list ap;
va_start (ap, format);
ESTREAM_LOCK (stream);
@@ -3746,7 +3746,7 @@ int
es_printf_unlocked (const char *ES__RESTRICT format, ...)
{
int ret;
-
+
va_list ap;
va_start (ap, format);
ret = es_print (es_stdout, format, ap);
@@ -3761,7 +3761,7 @@ es_printf (const char *ES__RESTRICT format, ...)
{
int ret;
estream_t stream = es_stdout;
-
+
va_list ap;
va_start (ap, format);
ESTREAM_LOCK (stream);
@@ -3799,7 +3799,7 @@ es_asprintf (const char *ES__RESTRICT format, ...)
should use es_free to release the buffer. This function actually
belongs into estream-printf but we put it here as a convenience
and because es_free is required anyway. */
-char *
+char *
es_vasprintf (const char *ES__RESTRICT format, va_list ap)
{
int rc;
@@ -3830,7 +3830,7 @@ tmpfd (void)
int pid = GetCurrentProcessId ();
unsigned int value;
int i;
-
+
n = GetTempPath (MAX_PATH+1, buffer);
if (!n || n > MAX_PATH || mystrlen (buffer) > MAX_PATH)
{
@@ -3896,7 +3896,7 @@ tmpfd (void)
fp = NULL;
fd = -1;
-
+
fp = tmpfile ();
if (! fp)
goto out;
@@ -3928,7 +3928,7 @@ es_tmpfile (void)
stream = NULL;
modeflags = O_RDWR | O_TRUNC | O_CREAT;
cookie = NULL;
-
+
fd = tmpfd ();
if (fd == -1)
{
@@ -3954,7 +3954,7 @@ es_tmpfile (void)
close (fd);
stream = NULL;
}
-
+
return stream;
}
@@ -3964,7 +3964,7 @@ es_setvbuf (estream_t ES__RESTRICT stream,
char *ES__RESTRICT buf, int type, size_t size)
{
int err;
-
+
if ((type == _IOFBF || type == _IOLBF || type == _IONBF)
&& (!buf || size || type == _IONBF))
{
@@ -4036,7 +4036,7 @@ void *
es_opaque_get (estream_t stream)
{
void *opaque;
-
+
ESTREAM_LOCK (stream);
es_opaque_ctrl (stream, NULL, &opaque);
ESTREAM_UNLOCK (stream);
@@ -4111,10 +4111,10 @@ es_fname_get (estream_t stream)
Returns 0 on success or -1 on error. If BYTES_WRITTEN is not NULL
the number of bytes actually written are stored at this
address. */
-int
+int
es_write_sanitized (estream_t ES__RESTRICT stream,
const void * ES__RESTRICT buffer, size_t length,
- const char * delimiters,
+ const char * delimiters,
size_t * ES__RESTRICT bytes_written)
{
const unsigned char *p = buffer;
@@ -4124,9 +4124,9 @@ es_write_sanitized (estream_t ES__RESTRICT stream,
ESTREAM_LOCK (stream);
for (; length; length--, p++, count++)
{
- if (*p < 0x20
+ if (*p < 0x20
|| *p == 0x7f
- || (delimiters
+ || (delimiters
&& (strchr (delimiters, *p) || *p == '\\')))
{
es_putc_unlocked ('\\', stream);
@@ -4228,19 +4228,19 @@ es_write_hexstring (estream_t ES__RESTRICT stream,
#ifdef GNUPG_MAJOR_VERSION
/* Special estream function to print an UTF8 string in the native
encoding. The interface is the same as es_write_sanitized, however
- only one delimiter may be supported.
+ only one delimiter may be supported.
THIS IS NOT A STANDARD ESTREAM FUNCTION AND ONLY USED BY GNUPG!. */
int
es_write_sanitized_utf8_buffer (estream_t stream,
- const void *buffer, size_t length,
+ const void *buffer, size_t length,
const char *delimiters, size_t *bytes_written)
{
const char *p = buffer;
size_t i;
/* We can handle plain ascii simpler, so check for it first. */
- for (i=0; i < length; i++ )
+ for (i=0; i < length; i++ )
{
if ( (p[i] & 0x80) )
break;