]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/tinycbor/cborparser_dup_string.c
1 /****************************************************************************
3 ** Copyright (C) 2016 Intel Corporation
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
12 ** The above copyright notice and this permission notice shall be included in
13 ** all copies or substantial portions of the Software.
15 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 ****************************************************************************/
28 #ifndef _DEFAULT_SOURCE
29 #define _DEFAULT_SOURCE 1
31 #ifndef __STDC_LIMIT_MACROS
32 # define __STDC_LIMIT_MACROS 1
36 #include "compilersupport_p.h"
40 * \fn CborError cbor_value_dup_text_string(const CborValue *value, char **buffer, size_t *buflen, CborValue *next)
42 * Allocates memory for the string pointed by \a value and copies it into this
43 * buffer. The pointer to the buffer is stored in \a buffer and the number of
44 * bytes copied is stored in \a buflen (those variables must not be NULL).
46 * If the iterator \a value does not point to a text string, the behaviour is
47 * undefined, so checking with \ref cbor_value_get_type or \ref
48 * cbor_value_is_text_string is recommended.
50 * If \c malloc returns a NULL pointer, this function will return error
51 * condition \ref CborErrorOutOfMemory.
53 * On success, \c{*buffer} will contain a valid pointer that must be freed by
54 * calling \c{free()}. This is the case even for zero-length strings.
56 * The \a next pointer, if not null, will be updated to point to the next item
57 * after this string. If \a value points to the last item, then \a next will be
60 * This function may not run in constant time (it will run in O(n) time on the
61 * number of chunks). It requires constant memory (O(1)) in addition to the
64 * \note This function does not perform UTF-8 validation on the incoming text
67 * \sa cbor_value_get_text_string_chunk(), cbor_value_copy_text_string(), cbor_value_dup_byte_string()
71 * \fn CborError cbor_value_dup_byte_string(const CborValue *value, uint8_t **buffer, size_t *buflen, CborValue *next)
73 * Allocates memory for the string pointed by \a value and copies it into this
74 * buffer. The pointer to the buffer is stored in \a buffer and the number of
75 * bytes copied is stored in \a buflen (those variables must not be NULL).
77 * If the iterator \a value does not point to a byte string, the behaviour is
78 * undefined, so checking with \ref cbor_value_get_type or \ref
79 * cbor_value_is_byte_string is recommended.
81 * If \c malloc returns a NULL pointer, this function will return error
82 * condition \ref CborErrorOutOfMemory.
84 * On success, \c{*buffer} will contain a valid pointer that must be freed by
85 * calling \c{free()}. This is the case even for zero-length strings.
87 * The \a next pointer, if not null, will be updated to point to the next item
88 * after this string. If \a value points to the last item, then \a next will be
91 * This function may not run in constant time (it will run in O(n) time on the
92 * number of chunks). It requires constant memory (O(1)) in addition to the
95 * \sa cbor_value_get_text_string_chunk(), cbor_value_copy_byte_string(), cbor_value_dup_text_string()
97 CborError
_cbor_value_dup_string(const CborValue
*value
, void **buffer
, size_t *buflen
, CborValue
*next
)
103 err
= _cbor_value_copy_string(value
, NULL
, buflen
, NULL
);
108 *buffer
= malloc(*buflen
);
111 return CborErrorOutOfMemory
;
113 err
= _cbor_value_copy_string(value
, *buffer
, buflen
, next
);