1 /* 2 Copyright (C) 2015-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: dk4membs.ctr 12 */ 13 14 /** @file dk4membs.c The dk4membs module. 15 */ 16 17 18 #include "dk4conf.h" 19 #include <libdk4c/dk4membs.h> 20 21 #if DK4_HAVE_ASSERT_H 22 #ifndef ASSERT_H_INCLUDED 23 #include <assert.h> 24 #define ASSERT_H_INCLUDED 1 25 #endif 26 #endif 27 28 29 int dk4membuf_to_stream(dk4_stream_t * strm,dk4_membuf_t const * mbptr,dk4_er_t * erp)30dk4membuf_to_stream( 31 dk4_stream_t *strm, 32 dk4_membuf_t const *mbptr, 33 dk4_er_t *erp 34 ) 35 { 36 dk4_membuf_cell_t *pc = NULL; 37 dk4_membuf_cell_t *pn = NULL; 38 int back = 0; 39 40 #if DK4_USE_ASSERT 41 assert(NULL != strm); 42 assert(NULL != mbptr); 43 #endif 44 if ((NULL != strm) && (NULL != mbptr)) { 45 back = 1; 46 pc = mbptr->first; 47 while (NULL != pc) { 48 pn = pc->next; 49 if (0 < pc->used) { 50 if (0 == dk4stream_write(strm, pc->buf, pc->used, erp)) { 51 back = 0; 52 } 53 } 54 pc = pn; 55 } 56 } else { 57 dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); 58 } 59 return back; 60 } 61 62 63