]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/tinycbor/cborpretty_stdio.c
fix hf search (#908)
[proxmark3-svn] / client / tinycbor / cborpretty_stdio.c
... / ...
CommitLineData
1/****************************************************************************
2**
3** Copyright (C) 2017 Intel Corporation
4**
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:
11**
12** The above copyright notice and this permission notice shall be included in
13** all copies or substantial portions of the Software.
14**
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
21** THE SOFTWARE.
22**
23****************************************************************************/
24
25#include "cbor.h"
26#include <stdarg.h>
27#include <stdio.h>
28
29static CborError cbor_fprintf(void *out, const char *fmt, ...)
30{
31 int n;
32
33 va_list list;
34 va_start(list, fmt);
35 n = vfprintf((FILE *)out, fmt, list);
36 va_end(list);
37
38 return n < 0 ? CborErrorIO : CborNoError;
39}
40
41/**
42 * \fn CborError cbor_value_to_pretty(FILE *out, const CborValue *value)
43 *
44 * Converts the current CBOR type pointed to by \a value to its textual
45 * representation and writes it to the \a out stream. If an error occurs, this
46 * function returns an error code similar to CborParsing.
47 *
48 * \sa cbor_value_to_pretty_advance(), cbor_value_to_json_advance()
49 */
50
51/**
52 * Converts the current CBOR type pointed to by \a value to its textual
53 * representation and writes it to the \a out stream. If an error occurs, this
54 * function returns an error code similar to CborParsing.
55 *
56 * If no error ocurred, this function advances \a value to the next element.
57 * Often, concatenating the text representation of multiple elements can be
58 * done by appending a comma to the output stream in between calls to this
59 * function.
60 *
61 * \sa cbor_value_to_pretty(), cbor_value_to_pretty_stream(), cbor_value_to_json_advance()
62 */
63CborError cbor_value_to_pretty_advance(FILE *out, CborValue *value)
64{
65 return cbor_value_to_pretty_stream(cbor_fprintf, out, value, CborPrettyDefaultFlags);
66}
67
68/**
69 * Converts the current CBOR type pointed to by \a value to its textual
70 * representation and writes it to the \a out stream. If an error occurs, this
71 * function returns an error code similar to CborParsing.
72 *
73 * The textual representation can be controlled by the \a flags parameter (see
74 * CborPrettyFlags for more information).
75 *
76 * If no error ocurred, this function advances \a value to the next element.
77 * Often, concatenating the text representation of multiple elements can be
78 * done by appending a comma to the output stream in between calls to this
79 * function.
80 *
81 * \sa cbor_value_to_pretty_stream(), cbor_value_to_pretty(), cbor_value_to_json_advance()
82 */
83CborError cbor_value_to_pretty_advance_flags(FILE *out, CborValue *value, int flags)
84{
85 return cbor_value_to_pretty_stream(cbor_fprintf, out, value, flags);
86}
87
Impressum, Datenschutz