Coverage Report

Created: 2026-03-16 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5Pstrcpl.c
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*-------------------------------------------------------------------------
14
 *
15
 * Created:   H5Pstrcpl.c
16
 *
17
 * Purpose:   String creation property list class routines
18
 *
19
 *-------------------------------------------------------------------------
20
 */
21
22
/****************/
23
/* Module Setup */
24
/****************/
25
26
#include "H5Pmodule.h" /* This source code file is part of the H5P module */
27
28
/***********/
29
/* Headers */
30
/***********/
31
#include "H5private.h"  /* Generic Functions      */
32
#include "H5Eprivate.h" /* Error handling       */
33
#include "H5Fprivate.h" /* Files */
34
#include "H5Ppkg.h"     /* Property lists       */
35
36
/****************/
37
/* Local Macros */
38
/****************/
39
40
/* ========  String creation properties ======== */
41
/* Definitions for character set encoding property */
42
1
#define H5P_STRCRT_CHAR_ENCODING_SIZE sizeof(H5T_cset_t)
43
#define H5P_STRCRT_CHAR_ENCODING_DEF  H5F_DEFAULT_CSET
44
1
#define H5P_STRCRT_CHAR_ENCODING_ENC  H5P__strcrt_char_encoding_enc
45
1
#define H5P_STRCRT_CHAR_ENCODING_DEC  H5P__strcrt_char_encoding_dec
46
47
/******************/
48
/* Local Typedefs */
49
/******************/
50
51
/********************/
52
/* Package Typedefs */
53
/********************/
54
55
/********************/
56
/* Local Prototypes */
57
/********************/
58
59
/* Property class callbacks */
60
static herr_t H5P__strcrt_reg_prop(H5P_genclass_t *pclass);
61
62
/* encode & decode callbacks */
63
static herr_t H5P__strcrt_char_encoding_enc(const void *value, void **_pp, size_t *size);
64
static herr_t H5P__strcrt_char_encoding_dec(const void **_pp, void *value);
65
66
/*********************/
67
/* Package Variables */
68
/*********************/
69
70
/* String creation property list class library initialization object */
71
const H5P_libclass_t H5P_CLS_STRCRT[1] = {{
72
    "string create",        /* Class name for debugging     */
73
    H5P_TYPE_STRING_CREATE, /* Class type                   */
74
75
    &H5P_CLS_ROOT_g,             /* Parent class                 */
76
    &H5P_CLS_STRING_CREATE_g,    /* Pointer to class             */
77
    &H5P_CLS_STRING_CREATE_ID_g, /* Pointer to class ID          */
78
    NULL,                        /* Pointer to default property list ID */
79
    H5P__strcrt_reg_prop,        /* Default property registration routine */
80
81
    NULL, /* Class creation callback      */
82
    NULL, /* Class creation callback info */
83
    NULL, /* Class copy callback          */
84
    NULL, /* Class copy callback info     */
85
    NULL, /* Class close callback         */
86
    NULL  /* Class close callback info    */
87
}};
88
89
/*****************************/
90
/* Library Private Variables */
91
/*****************************/
92
93
/*******************/
94
/* Local Variables */
95
/*******************/
96
97
/* Property value defaults */
98
static const H5T_cset_t H5P_def_char_encoding_g =
99
    H5P_STRCRT_CHAR_ENCODING_DEF; /* Default character set encoding */
100
101
/*-------------------------------------------------------------------------
102
 * Function:    H5P__strcrt_reg_prop
103
 *
104
 * Purpose:     Register the string creation property list class's properties
105
 *
106
 * Return:      Non-negative on success/Negative on failure
107
 *
108
 *-------------------------------------------------------------------------
109
 */
110
static herr_t
111
H5P__strcrt_reg_prop(H5P_genclass_t *pclass)
112
1
{
113
1
    herr_t ret_value = SUCCEED; /* Return value */
114
115
1
    FUNC_ENTER_PACKAGE
116
117
    /* Register character encoding */
118
1
    if (H5P__register_real(pclass, H5P_STRCRT_CHAR_ENCODING_NAME, H5P_STRCRT_CHAR_ENCODING_SIZE,
119
1
                           &H5P_def_char_encoding_g, NULL, NULL, NULL, H5P_STRCRT_CHAR_ENCODING_ENC,
120
1
                           H5P_STRCRT_CHAR_ENCODING_DEC, NULL, NULL, NULL, NULL) < 0)
121
0
        HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class");
122
123
1
done:
124
1
    FUNC_LEAVE_NOAPI(ret_value)
125
1
} /* end H5P__strcrt_reg_prop() */
126
127
/*-------------------------------------------------------------------------
128
 * Function:    H5Pset_char_encoding
129
 *
130
 * Purpose:     Sets the character encoding of the string.
131
 *
132
 * Return:      Non-negative on success/Negative on failure
133
 *
134
 *-------------------------------------------------------------------------
135
 */
136
herr_t
137
H5Pset_char_encoding(hid_t plist_id, H5T_cset_t encoding)
138
0
{
139
0
    H5P_genplist_t *plist;               /* Property list pointer */
140
0
    herr_t          ret_value = SUCCEED; /* return value */
141
142
0
    FUNC_ENTER_API(FAIL)
143
144
    /* Check arguments */
145
0
    if (encoding <= H5T_CSET_ERROR || encoding >= H5T_NCSET)
146
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "character encoding is not valid");
147
148
    /* Get the plist structure */
149
0
    if (NULL == (plist = H5P_object_verify(plist_id, H5P_STRING_CREATE, false)))
150
0
        HGOTO_ERROR(H5E_ID, H5E_BADID, FAIL, "can't find object for ID");
151
152
    /* Set the character encoding */
153
0
    if (H5P_set(plist, H5P_STRCRT_CHAR_ENCODING_NAME, &encoding) < 0)
154
0
        HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set character encoding");
155
156
0
done:
157
0
    FUNC_LEAVE_API(ret_value)
158
0
} /* end H5P_set_char_encoding() */
159
160
/*-------------------------------------------------------------------------
161
 * Function:    H5Pget_char_encoding
162
 *
163
 * Purpose:     Gets the character encoding of the string.
164
 *
165
 * Return:      Non-negative on success/Negative on failure
166
 *
167
 *-------------------------------------------------------------------------
168
 */
169
herr_t
170
H5Pget_char_encoding(hid_t plist_id, H5T_cset_t *encoding /*out*/)
171
0
{
172
0
    H5P_genplist_t *plist;               /* Property list pointer */
173
0
    herr_t          ret_value = SUCCEED; /* return value */
174
175
0
    FUNC_ENTER_API(FAIL)
176
177
    /* Get the plist structure */
178
0
    if (NULL == (plist = H5P_object_verify(plist_id, H5P_STRING_CREATE, true)))
179
0
        HGOTO_ERROR(H5E_ID, H5E_BADID, FAIL, "can't find object for ID");
180
181
    /* Get value */
182
0
    if (encoding)
183
0
        if (H5P_get(plist, H5P_STRCRT_CHAR_ENCODING_NAME, encoding) < 0)
184
0
            HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get character encoding flag");
185
186
0
done:
187
0
    FUNC_LEAVE_API(ret_value)
188
0
} /* end H5Pget_char_encoding() */
189
190
/*-------------------------------------------------------------------------
191
 * Function:       H5P__strcrt_char_encoding_enc
192
 *
193
 * Purpose:        Callback routine which is called whenever the character
194
 *                 set encoding property in the string create property list
195
 *                 is encoded.
196
 *
197
 * Return:     Success: Non-negative
198
 *       Failure: Negative
199
 *
200
 *-------------------------------------------------------------------------
201
 */
202
static herr_t
203
H5P__strcrt_char_encoding_enc(const void *value, void **_pp, size_t *size)
204
0
{
205
0
    const H5T_cset_t *encoding = (const H5T_cset_t *)value; /* Create local alias for values */
206
0
    uint8_t         **pp       = (uint8_t **)_pp;
207
208
0
    FUNC_ENTER_PACKAGE_NOERR
209
210
    /* Sanity check */
211
0
    assert(encoding);
212
0
    assert(size);
213
214
0
    if (NULL != *pp)
215
        /* Encode character set encoding */
216
0
        *(*pp)++ = (uint8_t)*encoding;
217
218
    /* Size of character set encoding */
219
0
    (*size)++;
220
221
0
    FUNC_LEAVE_NOAPI(SUCCEED)
222
0
} /* end H5P__strcrt_char_encoding_enc() */
223
224
/*-------------------------------------------------------------------------
225
 * Function:       H5P__strcrt_char_encoding_dec
226
 *
227
 * Purpose:        Callback routine which is called whenever the character
228
 *                 set encoding property in the string create property list
229
 *                 is decoded.
230
 *
231
 * Return:     Success: Non-negative
232
 *       Failure: Negative
233
 *
234
 *-------------------------------------------------------------------------
235
 */
236
static herr_t
237
H5P__strcrt_char_encoding_dec(const void **_pp, void *_value)
238
0
{
239
0
    H5T_cset_t     *encoding = (H5T_cset_t *)_value; /* Character set encoding */
240
0
    const uint8_t **pp       = (const uint8_t **)_pp;
241
242
0
    FUNC_ENTER_PACKAGE_NOERR
243
244
    /* Sanity checks */
245
0
    assert(pp);
246
0
    assert(*pp);
247
0
    assert(encoding);
248
249
    /* Decode character set encoding */
250
0
    *encoding = (H5T_cset_t) * (*pp)++;
251
252
0
    FUNC_LEAVE_NOAPI(SUCCEED)
253
0
} /* end H5P__strcrt_char_encoding_dec() */