summaryrefslogtreecommitdiff
path: root/support/dktools/dk4mbstrm.ctr
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
committerNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
commit1f457376b478257b88d4a857f5ec1b6155442dd7 (patch)
tree2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk4mbstrm.ctr
parentac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff)
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk4mbstrm.ctr')
-rw-r--r--support/dktools/dk4mbstrm.ctr56
1 files changed, 50 insertions, 6 deletions
diff --git a/support/dktools/dk4mbstrm.ctr b/support/dktools/dk4mbstrm.ctr
index e295336389..74a78b4f35 100644
--- a/support/dktools/dk4mbstrm.ctr
+++ b/support/dktools/dk4mbstrm.ctr
@@ -2,21 +2,42 @@
copyright owner = Dirk Krause
copyright year = 2016-xxxx
-license = bsd
+SPDX-License-Identifier: BSD-3-Clause
%% header
+
+#ifndef DK4CONF_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
+#include "dk4conf.h"
+#else
+#include <dktools-4/dk4conf.h>
+#endif
+#endif
+
#ifndef DK4STRM_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
#include "dk4strm.h"
+#else
+#include <dktools-4/dk4strm.h>
+#endif
#endif
#ifndef DK4MEMBUF_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
#include "dk4membuf.h"
+#else
+#include <dktools-4/dk4membuf.h>
+#endif
#endif
#ifndef DK4ERROR_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
#include "dk4error.h"
+#else
+#include <dktools-4/dk4error.h>
+#endif
#endif
@@ -30,6 +51,10 @@ extern "C" {
@param mb Destination memory buffer.
@param erp Error report, may be NULL.
@return Valid pointer on success, NULL on error.
+
+ Error codes:
+ - DK4_E_INVALID_ARGUMENTS<br>
+ if mb is NULL.
*/
dk4_stream_t *
@@ -43,8 +68,15 @@ dk4stream_open_membuf_writer(dk4_membuf_t *mb, dk4_er_t *erp);
/* vim: set ai sw=4 ts=4 : */
%% module
+#include "dk4conf.h"
#include "dk4mbstrm.h"
+#if DK4_HAVE_ASSERT_H
+#ifndef ASSERT_H_INCLUDED
+#include <assert.h>
+#define ASSERT_H_INCLUDED 1
+#endif
+#endif
static
@@ -53,6 +85,9 @@ dk4stream_membuf_function(dk4_stream_api_t *api)
{
dk4_membuf_t *mb;
+#if DK4_USE_ASSERT
+ assert(NULL != api);
+#endif
if (NULL != api) {
api->res = 0;
api->sz_out = 0;
@@ -60,11 +95,16 @@ dk4stream_membuf_function(dk4_stream_api_t *api)
if (NULL != mb) {
switch (api->cmd) {
case DK4_STREAM_API_WRITE: {
- api->res = dk4membuf_store(
- mb, (const void *)(api->b), api->sz_in, NULL
- );
- if (0 != api->res) {
- api->sz_out = api->sz_in;
+ if (0 < api->sz_in) {
+ api->res = dk4membuf_store(
+ mb, (const void *)(api->b), api->sz_in, NULL
+ );
+ if (0 != api->res) {
+ api->sz_out = api->sz_in;
+ }
+ }
+ else {
+ api->res = 1;
}
} break;
case DK4_STREAM_API_FLUSH: {
@@ -89,6 +129,10 @@ dk4_stream_t *
dk4stream_open_membuf_writer(dk4_membuf_t *mb, dk4_er_t *erp)
{
dk4_stream_t *back = NULL;
+
+#if DK4_USE_ASSERT
+ assert(NULL != mb);
+#endif
if (NULL != mb) {
back = dk4stream_open(
mb, dk4stream_membuf_function,