aboutsummaryrefslogtreecommitdiffstats
path: root/common/estream.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/estream.c')
-rw-r--r--common/estream.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/common/estream.c b/common/estream.c
index 6b7bd8b75..32602a0f7 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -85,13 +85,13 @@
# include <gpg-error.h> /* ERRNO replacement. */
#endif
-#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */
-# undef HAVE_PTH
-# undef USE_GNU_PTH
+#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
+# undef HAVE_NPTH
+# undef USE_NPTH
#endif
-#ifdef HAVE_PTH
-# include <pth.h>
+#ifdef HAVE_NPTH
+# include <npth.h>
#endif
/* This is for the special hack to use estream.c in GnuPG. */
@@ -159,7 +159,7 @@ typedef void (*func_free_t) (void *mem);
/* Locking. */
-#ifdef HAVE_PTH
+#ifdef HAVE_NPTH
typedef pth_mutex_t estream_mutex_t;
# define ESTREAM_MUTEX_INITIALIZER PTH_MUTEX_INIT
@@ -197,7 +197,7 @@ dummy_mutex_call_int (estream_mutex_t mutex)
/* Primitive system I/O. */
-#ifdef HAVE_PTH
+#ifdef HAVE_NPTH
# define ESTREAM_SYS_READ do_pth_read
# define ESTREAM_SYS_WRITE do_pth_write
# define ESTREAM_SYS_YIELD() pth_yield (NULL)
@@ -450,7 +450,7 @@ do_list_remove (estream_t stream, int with_locked_list)
* write, assuming that we do I/O on a plain file where the operation
* can't block.
*/
-#ifdef HAVE_PTH
+#ifdef HAVE_NPTH
static int
do_pth_read (int fd, void *buffer, size_t size)
{
@@ -476,7 +476,7 @@ do_pth_write (int fd, const void *buffer, size_t size)
return pth_write (fd, buffer, size);
# endif /* !HAVE_W32_SYSTEM*/
}
-#endif /*HAVE_PTH*/
+#endif /*HAVE_NPTH*/
@@ -507,7 +507,7 @@ do_init (void)
if (!initialized)
{
-#ifdef HAVE_PTH
+#ifdef HAVE_NPTH
if (!pth_init () && errno != EPERM )
return -1;
if (pth_mutex_init (&estream_list_lock))
@@ -1033,7 +1033,7 @@ es_func_w32_read (void *cookie, void *buffer, size_t size)
{
do
{
-#ifdef HAVE_PTH
+#ifdef HAVE_NPTH
/* Note: Our pth_read actually uses HANDLE! */
bytes_read = pth_read ((int)w32_cookie->hd, buffer, size);
#else
@@ -1078,7 +1078,7 @@ es_func_w32_write (void *cookie, const void *buffer, size_t size)
{
do
{
-#ifdef HAVE_PTH
+#ifdef HAVE_NPTH
/* Note: Our pth_write actually uses HANDLE! */
bytes_written = pth_write ((int)w32_cookie->hd, buffer, size);
#else
@@ -2753,6 +2753,40 @@ es_fopenmem_init (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,
const char *ES__RESTRICT mode,