mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-21 14:47:03 +01:00
estream: Backport es_fopemem_init from master.
* common/estream.c (es_fopenmem_init): New. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
a1398844ad
commit
9b8518ffc9
@ -2362,6 +2362,38 @@ es_fopenmem (size_t memlimit, const char *ES__RESTRICT mode)
|
||||
}
|
||||
|
||||
|
||||
/* This is the same as es_fopenmem but intializes the memory with a
|
||||
copy of (DATA,DATALEN). The stream is initally set to the
|
||||
beginning. If MEMLIMIT is not 0 but shorter than DATALEN it
|
||||
DATALEN will be used as the value for MEMLIMIT. */
|
||||
estream_t
|
||||
es_fopenmem_init (size_t memlimit, const char *ES__RESTRICT mode,
|
||||
const void *data, size_t datalen)
|
||||
{
|
||||
estream_t stream;
|
||||
|
||||
if (memlimit && memlimit < datalen)
|
||||
memlimit = datalen;
|
||||
|
||||
stream = es_fopenmem (memlimit, mode);
|
||||
if (stream && data && datalen)
|
||||
{
|
||||
if (es_writen (stream, data, datalen, NULL))
|
||||
{
|
||||
int saveerrno = errno;
|
||||
es_fclose (stream);
|
||||
stream = NULL;
|
||||
_set_errno (saveerrno);
|
||||
}
|
||||
else
|
||||
{
|
||||
es_seek (stream, 0L, SEEK_SET, NULL);
|
||||
es_set_indicators (stream, 0, 0);
|
||||
}
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
estream_t
|
||||
es_fopencookie (void *ES__RESTRICT cookie,
|
||||
|
@ -76,6 +76,7 @@
|
||||
#define es_fopen _ESTREAM_PREFIX(es_fopen)
|
||||
#define es_mopen _ESTREAM_PREFIX(es_mopen)
|
||||
#define es_fopenmem _ESTREAM_PREFIX(es_fopenmem)
|
||||
#define es_fopenmem_init _ESTREAM_PREFIX(es_fopenmem_init)
|
||||
#define es_fdopen _ESTREAM_PREFIX(es_fdopen)
|
||||
#define es_fdopen_nc _ESTREAM_PREFIX(es_fdopen_nc)
|
||||
#define es_fpopen _ESTREAM_PREFIX(es_fpopen)
|
||||
@ -243,6 +244,8 @@ estream_t es_mopen (unsigned char *ES__RESTRICT data,
|
||||
void (*func_free) (void *mem),
|
||||
const char *ES__RESTRICT mode);
|
||||
estream_t es_fopenmem (size_t memlimit, const char *ES__RESTRICT mode);
|
||||
estream_t es_fopenmem_init (size_t memlimit, const char *ES__RESTRICT mode,
|
||||
const void *data, size_t datalen);
|
||||
estream_t es_fdopen (int filedes, const char *mode);
|
||||
estream_t es_fdopen_nc (int filedes, const char *mode);
|
||||
estream_t es_fpopen (FILE *fp, const char *mode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user