YAZ 5.35.1
nmem.h
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data.
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
35#ifndef NMEM_H
36#define NMEM_H
37
38#include <stddef.h>
39#include <yaz/yconfig.h>
40
42
44typedef struct nmem_control *NMEM;
45
47#ifndef NMEM_64
48#define NMEM_64 1
49#endif
50
51#if NMEM_64
52
53#ifdef _MSC_VER
54/* Visual Studio. 6.0 and later supports this */
55typedef __int64 nmem_int_t;
56#define NMEM_INT_PRINTF "%I64d"
57#else
58/* C99 */
59typedef long long int nmem_int_t;
60#define NMEM_INT_PRINTF "%lld"
61#endif
62
63#else
65typedef int nmem_int_t;
67#define NMEM_INT_PRINTF "%d"
68#endif
69
71typedef int nmem_bool_t;
72
76YAZ_EXPORT void nmem_reset(NMEM n);
77
81YAZ_EXPORT size_t nmem_total(NMEM n);
82
88YAZ_EXPORT char *nmem_strdup(NMEM mem, const char *src);
94YAZ_EXPORT char *nmem_strdup_null(NMEM mem, const char *src);
95
102YAZ_EXPORT char *nmem_strdupn(NMEM mem, const char *src, size_t n);
103
111YAZ_EXPORT void nmem_strsplit(NMEM nmem, const char *delim,
112 const char *dstr,
113 char ***darray, int *num);
114
123YAZ_EXPORT void nmem_strsplitx(NMEM nmem, const char *delim,
124 const char *dstr,
125 char ***darray, int *num,
126 int collapse);
127
134YAZ_EXPORT void nmem_strsplit_blank(NMEM nmem, const char *dstr,
135 char ***darray, int *num);
136
137
147YAZ_EXPORT void nmem_strsplit_escape(NMEM nmem, const char *delim,
148 const char *dstr,
149 char ***darray, int *num, int collapse,
150 int escape_char);
151
162YAZ_EXPORT void nmem_strsplit_escape2(NMEM nmem, const char *delim,
163 const char *dstr,
164 char ***darray, int *num, int collapse,
165 int escape_char, int subst_escape);
166
172YAZ_EXPORT nmem_int_t *nmem_intdup(NMEM nmem, nmem_int_t v);
173
179YAZ_EXPORT nmem_bool_t *nmem_booldup(NMEM nmem, nmem_bool_t v);
180
185YAZ_EXPORT void nmem_transfer(NMEM dst, NMEM src);
186
190YAZ_EXPORT NMEM nmem_create(void);
191
195YAZ_EXPORT void nmem_destroy(NMEM n);
196
202YAZ_EXPORT void *nmem_malloc(NMEM n, size_t size);
203
210YAZ_EXPORT int nmem_get_status(char *dst, size_t l);
211
213
214#endif
215/*
216 * Local variables:
217 * c-basic-offset: 4
218 * c-file-style: "Stroustrup"
219 * indent-tabs-mode: nil
220 * End:
221 * vim: shiftwidth=4 tabstop=8 expandtab
222 */
223
void nmem_strsplitx(NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num, int collapse)
allocates sub strings out of string using certain delimitors
Definition nmemsdup.c:67
void nmem_strsplit_blank(NMEM nmem, const char *dstr, char ***darray, int *num)
splits string into sub strings delimited by blanks
Definition nmemsdup.c:55
void nmem_strsplit(NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num)
allocates sub strings out of string using certain delimitors
Definition nmemsdup.c:61
void nmem_transfer(NMEM dst, NMEM src)
transfers memory from one NMEM handle to another
Definition nmem.c:216
nmem_bool_t * nmem_booldup(NMEM nmem, nmem_bool_t v)
allocates and sets boolean for NMEM
Definition nmemsdup.c:48
void nmem_strsplit_escape2(NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num, int collapse, int escape_char, int subst_escape)
allocates sub strings out of string using certain delimitors
Definition nmemsdup.c:81
nmem_int_t * nmem_intdup(NMEM nmem, nmem_int_t v)
allocates and sets integer for NMEM
Definition nmemsdup.c:41
char * nmem_strdup(NMEM mem, const char *src)
allocates string on NMEM handle (similar strdup)
Definition nmemsdup.c:18
void nmem_strsplit_escape(NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num, int collapse, int escape_char)
allocates sub strings out of string using certain delimitors
Definition nmemsdup.c:73
void nmem_reset(NMEM n)
releases memory associaged with an NMEM handle
Definition nmem.c:129
int nmem_bool_t
BER/utility boolean.
Definition nmem.h:71
struct nmem_control * NMEM
NMEM handle (an opaque pointer to memory)
Definition nmem.h:44
int nmem_get_status(char *dst, size_t l)
returns memory status for NMEM - as XML
Definition nmem.c:229
char * nmem_strdupn(NMEM mem, const char *src, size_t n)
allocates string of certain size on NMEM handle
Definition nmemsdup.c:33
char * nmem_strdup_null(NMEM mem, const char *src)
allocates string on NMEM handle - allows NULL ptr buffer
Definition nmemsdup.c:25
NMEM nmem_create(void)
returns new NMEM handle
Definition nmem.c:181
size_t nmem_total(NMEM n)
returns size in bytes of memory for NMEM handle
Definition nmem.c:169
void * nmem_malloc(NMEM n, size_t size)
allocates memory block on NMEM handle
Definition nmem.c:145
int nmem_int_t
BER/utility integer (32-bit on most platforms)
Definition nmem.h:65
void nmem_destroy(NMEM n)
destroys NMEM handle and memory associated with it
Definition nmem.c:204
Header with fundamental macros.
#define YAZ_BEGIN_CDECL
Definition yconfig.h:56
#define YAZ_END_CDECL
Definition yconfig.h:57