/src/openvswitch/include/openvswitch/dynamic-string.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016 Nicira, Inc. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at: |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #ifndef OPENVSWITCH_DYNAMIC_STRING_H |
18 | | #define OPENVSWITCH_DYNAMIC_STRING_H 1 |
19 | | |
20 | | #include <stdarg.h> |
21 | | #include <stdbool.h> |
22 | | #include <stddef.h> |
23 | | #include <stdint.h> |
24 | | #include <stdio.h> |
25 | | #include "openvswitch/compiler.h" |
26 | | |
27 | | #ifdef __cplusplus |
28 | | extern "C" { |
29 | | #endif |
30 | | |
31 | | struct uuid; |
32 | | |
33 | | /* A "dynamic string", that is, a buffer that can be used to construct a |
34 | | * string across a series of operations that extend or modify it. |
35 | | * |
36 | | * The 'string' member does not always point to a null-terminated string. |
37 | | * Initially it is NULL, and even when it is nonnull, some operations do not |
38 | | * ensure that it is null-terminated. Use ds_cstr() to ensure that memory is |
39 | | * allocated for the string and that it is null-terminated. */ |
40 | | struct ds { |
41 | | char *string; /* Null-terminated string. */ |
42 | | size_t length; /* Bytes used, not including null terminator. */ |
43 | | size_t allocated; /* Bytes allocated, not including null terminator. */ |
44 | | }; |
45 | | |
46 | 0 | #define DS_EMPTY_INITIALIZER { NULL, 0, 0 } |
47 | | |
48 | | void ds_init(struct ds *); |
49 | | void ds_clear(struct ds *); |
50 | | void ds_truncate(struct ds *, size_t new_length); |
51 | | void ds_reserve(struct ds *, size_t min_length); |
52 | | char *ds_put_uninit(struct ds *, size_t n); |
53 | | static inline void ds_put_char(struct ds *, char); |
54 | | void ds_put_utf8(struct ds *, int uc); |
55 | | void ds_put_char_multiple(struct ds *, char, size_t n); |
56 | | void ds_put_buffer(struct ds *, const char *, size_t n); |
57 | | void ds_put_cstr(struct ds *, const char *); |
58 | | void ds_put_and_free_cstr(struct ds *, char *); |
59 | | void ds_put_format(struct ds *, const char *, ...) OVS_PRINTF_FORMAT(2, 3); |
60 | | void ds_put_format_valist(struct ds *, const char *, va_list) |
61 | | OVS_PRINTF_FORMAT(2, 0); |
62 | | void ds_put_printable(struct ds *, const char *, size_t); |
63 | | void ds_put_uuid(struct ds *, const struct uuid *); |
64 | | void ds_put_hex(struct ds *ds, const void *buf, size_t size); |
65 | | void ds_put_hex_with_delimiter(struct ds *, const void *, size_t, char *); |
66 | | void ds_put_hex_dump(struct ds *ds, const void *buf_, size_t size, |
67 | | uintptr_t ofs, bool ascii); |
68 | | void ds_put_sparse_hex_dump(struct ds *ds, const void *buf_, size_t size, |
69 | | uintptr_t ofs, bool ascii); |
70 | | int ds_get_line(struct ds *, FILE *); |
71 | | int ds_get_preprocessed_line(struct ds *, FILE *, int *line_number); |
72 | | int ds_get_test_line(struct ds *, FILE *); |
73 | | |
74 | | void ds_put_strftime_msec(struct ds *, const char *format, long long int when, |
75 | | bool utc); |
76 | | char *xastrftime_msec(const char *format, long long int when, bool utc); |
77 | | |
78 | | char *ds_cstr(struct ds *); |
79 | | const char *ds_cstr_ro(const struct ds *); |
80 | | char *ds_steal_cstr(struct ds *); |
81 | | void ds_destroy(struct ds *); |
82 | | void ds_swap(struct ds *, struct ds *); |
83 | | |
84 | | int ds_last(const struct ds *); |
85 | | bool ds_chomp(struct ds *, int c); |
86 | | void ds_clone(struct ds *, struct ds *); |
87 | | |
88 | | /* Inline functions. */ |
89 | | |
90 | | void ds_put_char__(struct ds *, char); |
91 | | |
92 | | static inline void |
93 | | ds_put_char(struct ds *ds, char c) |
94 | 2.70M | { |
95 | 2.70M | if (ds->length < ds->allocated) { |
96 | 2.69M | ds->string[ds->length++] = c; |
97 | 2.69M | ds->string[ds->length] = '\0'; |
98 | 2.69M | } else { |
99 | 10.0k | ds_put_char__(ds, c); |
100 | 10.0k | } |
101 | 2.70M | } Unexecuted instantiation: odp_target.c:ds_put_char dynamic-string.c:ds_put_char Line | Count | Source | 94 | 10.1k | { | 95 | 10.1k | if (ds->length < ds->allocated) { | 96 | 10.1k | ds->string[ds->length++] = c; | 97 | 10.1k | ds->string[ds->length] = '\0'; | 98 | 10.1k | } else { | 99 | 59 | ds_put_char__(ds, c); | 100 | 59 | } | 101 | 10.1k | } |
Line | Count | Source | 94 | 2.67M | { | 95 | 2.67M | if (ds->length < ds->allocated) { | 96 | 2.66M | ds->string[ds->length++] = c; | 97 | 2.66M | ds->string[ds->length] = '\0'; | 98 | 2.66M | } else { | 99 | 9.85k | ds_put_char__(ds, c); | 100 | 9.85k | } | 101 | 2.67M | } |
Unexecuted instantiation: ofpbuf.c:ds_put_char Line | Count | Source | 94 | 4.27k | { | 95 | 4.27k | if (ds->length < ds->allocated) { | 96 | 4.25k | ds->string[ds->length++] = c; | 97 | 4.25k | ds->string[ds->length] = '\0'; | 98 | 4.25k | } else { | 99 | 19 | ds_put_char__(ds, c); | 100 | 19 | } | 101 | 4.27k | } |
Unexecuted instantiation: poll-loop.c:ds_put_char Unexecuted instantiation: socket-util.c:ds_put_char Unexecuted instantiation: timeval.c:ds_put_char Unexecuted instantiation: tun-metadata.c:ds_put_char Unexecuted instantiation: unixctl.c:ds_put_char Unexecuted instantiation: vlog.c:ds_put_char Unexecuted instantiation: backtrace.c:ds_put_char Unexecuted instantiation: command-line.c:ds_put_char Unexecuted instantiation: coverage.c:ds_put_char Unexecuted instantiation: dp-packet.c:ds_put_char Unexecuted instantiation: fatal-signal.c:ds_put_char Line | Count | Source | 94 | 15.5k | { | 95 | 15.5k | if (ds->length < ds->allocated) { | 96 | 15.4k | ds->string[ds->length++] = c; | 97 | 15.4k | ds->string[ds->length] = '\0'; | 98 | 15.4k | } else { | 99 | 95 | ds_put_char__(ds, c); | 100 | 95 | } | 101 | 15.5k | } |
Unexecuted instantiation: json.c:ds_put_char Unexecuted instantiation: jsonrpc.c:ds_put_char Unexecuted instantiation: match.c:ds_put_char Unexecuted instantiation: meta-flow.c:ds_put_char Unexecuted instantiation: netdev.c:ds_put_char Unexecuted instantiation: netlink.c:ds_put_char Unexecuted instantiation: nx-match.c:ds_put_char Unexecuted instantiation: ofp-errors.c:ds_put_char Unexecuted instantiation: ofp-match.c:ds_put_char Unexecuted instantiation: ofp-msgs.c:ds_put_char Unexecuted instantiation: ofp-port.c:ds_put_char Unexecuted instantiation: ofp-print.c:ds_put_char Unexecuted instantiation: ofp-prop.c:ds_put_char Unexecuted instantiation: ofp-protocol.c:ds_put_char Unexecuted instantiation: ofp-queue.c:ds_put_char Unexecuted instantiation: ofp-switch.c:ds_put_char Unexecuted instantiation: ofp-table.c:ds_put_char Unexecuted instantiation: ofp-util.c:ds_put_char Unexecuted instantiation: ovs-router.c:ds_put_char Unexecuted instantiation: smap.c:ds_put_char Unexecuted instantiation: sset.c:ds_put_char Unexecuted instantiation: stream.c:ds_put_char Unexecuted instantiation: svec.c:ds_put_char Unexecuted instantiation: syslog-direct.c:ds_put_char Unexecuted instantiation: syslog-libc.c:ds_put_char Unexecuted instantiation: tnl-ports.c:ds_put_char Unexecuted instantiation: unicode.c:ds_put_char Unexecuted instantiation: daemon-unix.c:ds_put_char Unexecuted instantiation: stream-unix.c:ds_put_char Unexecuted instantiation: netdev-linux.c:ds_put_char Unexecuted instantiation: netdev-offload-tc.c:ds_put_char Unexecuted instantiation: netlink-socket.c:ds_put_char Unexecuted instantiation: rtnetlink.c:ds_put_char Unexecuted instantiation: route-table.c:ds_put_char Unexecuted instantiation: tc.c:ds_put_char Unexecuted instantiation: stream-ssl.c:ds_put_char Unexecuted instantiation: classifier.c:ds_put_char Unexecuted instantiation: cooperative-multitasking.c:ds_put_char Unexecuted instantiation: dp-packet-gso.c:ds_put_char Unexecuted instantiation: dpif.c:ds_put_char Unexecuted instantiation: namemap.c:ds_put_char Unexecuted instantiation: netdev-offload.c:ds_put_char Unexecuted instantiation: netdev-vport.c:ds_put_char Unexecuted instantiation: odp-execute.c:ds_put_char Unexecuted instantiation: odp-execute-private.c:ds_put_char Unexecuted instantiation: ofp-actions.c:ds_put_char Unexecuted instantiation: ofp-bundle.c:ds_put_char Unexecuted instantiation: ofp-connection.c:ds_put_char Unexecuted instantiation: ofp-ct.c:ds_put_char Unexecuted instantiation: ofp-ed-props.c:ds_put_char Unexecuted instantiation: ofp-flow.c:ds_put_char Unexecuted instantiation: ofp-group.c:ds_put_char Unexecuted instantiation: ofp-ipfix.c:ds_put_char Unexecuted instantiation: ofp-meter.c:ds_put_char Unexecuted instantiation: ofp-monitor.c:ds_put_char Unexecuted instantiation: ofp-packet.c:ds_put_char Unexecuted instantiation: ofp-parse.c:ds_put_char Unexecuted instantiation: ox-stat.c:ds_put_char Unexecuted instantiation: process.c:ds_put_char Unexecuted instantiation: stream-tcp.c:ds_put_char Unexecuted instantiation: tnl-neigh-cache.c:ds_put_char Unexecuted instantiation: netdev-native-tnl.c:ds_put_char Unexecuted instantiation: dpif-netlink.c:ds_put_char Unexecuted instantiation: dpif-netlink-rtnl.c:ds_put_char Unexecuted instantiation: netlink-conntrack.c:ds_put_char Unexecuted instantiation: netlink-notifier.c:ds_put_char Unexecuted instantiation: bundle.c:ds_put_char Unexecuted instantiation: conntrack.c:ds_put_char Unexecuted instantiation: ct-dpif.c:ds_put_char Unexecuted instantiation: dpctl.c:ds_put_char Unexecuted instantiation: dpif-netdev.c:ds_put_char Unexecuted instantiation: dpif-netdev-private-dfc.c:ds_put_char Unexecuted instantiation: dpif-netdev-private-dpif.c:ds_put_char Unexecuted instantiation: dpif-netdev-private-extract.c:ds_put_char Unexecuted instantiation: dpif-netdev-perf.c:ds_put_char Unexecuted instantiation: ipf.c:ds_put_char Unexecuted instantiation: learn.c:ds_put_char Unexecuted instantiation: multipath.c:ds_put_char Unexecuted instantiation: conntrack-icmp.c:ds_put_char Unexecuted instantiation: conntrack-tcp.c:ds_put_char Unexecuted instantiation: conntrack-tp.c:ds_put_char Unexecuted instantiation: conntrack-other.c:ds_put_char Unexecuted instantiation: dpif-netdev-extract-study.c:ds_put_char Unexecuted instantiation: dpif-netdev-lookup.c:ds_put_char Unexecuted instantiation: dpif-netdev-lookup-autovalidator.c:ds_put_char Unexecuted instantiation: dpif-netdev-lookup-generic.c:ds_put_char Unexecuted instantiation: ovsdb-data.c:ds_put_char Unexecuted instantiation: ovsdb-error.c:ds_put_char Unexecuted instantiation: ovsdb-idl.c:ds_put_char Unexecuted instantiation: ovsdb-types.c:ds_put_char Unexecuted instantiation: ovsdb-cs.c:ds_put_char |
102 | | |
103 | | #ifdef __cplusplus |
104 | | } |
105 | | #endif |
106 | | |
107 | | #endif /* dynamic-string.h */ |