/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 | 2.15M | #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 | 144M | { |
95 | 144M | if (ds->length < ds->allocated) { |
96 | 143M | ds->string[ds->length++] = c; |
97 | 143M | ds->string[ds->length] = '\0'; |
98 | 143M | } else { |
99 | 466k | ds_put_char__(ds, c); |
100 | 466k | } |
101 | 144M | } Unexecuted instantiation: flow_extract_target.c:ds_put_char Unexecuted instantiation: dp-packet.c:ds_put_char dynamic-string.c:ds_put_char Line | Count | Source | 94 | 58.0M | { | 95 | 58.0M | if (ds->length < ds->allocated) { | 96 | 57.6M | ds->string[ds->length++] = c; | 97 | 57.6M | ds->string[ds->length] = '\0'; | 98 | 57.6M | } else { | 99 | 394k | ds_put_char__(ds, c); | 100 | 394k | } | 101 | 58.0M | } |
Line | Count | Source | 94 | 45.4k | { | 95 | 45.4k | if (ds->length < ds->allocated) { | 96 | 44.2k | ds->string[ds->length++] = c; | 97 | 44.2k | ds->string[ds->length] = '\0'; | 98 | 44.2k | } else { | 99 | 1.19k | ds_put_char__(ds, c); | 100 | 1.19k | } | 101 | 45.4k | } |
Line | Count | Source | 94 | 436k | { | 95 | 436k | if (ds->length < ds->allocated) { | 96 | 427k | ds->string[ds->length++] = c; | 97 | 427k | ds->string[ds->length] = '\0'; | 98 | 427k | } else { | 99 | 9.31k | ds_put_char__(ds, c); | 100 | 9.31k | } | 101 | 436k | } |
Line | Count | Source | 94 | 64.8k | { | 95 | 64.8k | if (ds->length < ds->allocated) { | 96 | 64.7k | ds->string[ds->length++] = c; | 97 | 64.7k | ds->string[ds->length] = '\0'; | 98 | 64.7k | } else { | 99 | 94 | ds_put_char__(ds, c); | 100 | 94 | } | 101 | 64.8k | } |
Line | Count | Source | 94 | 1.01k | { | 95 | 1.01k | if (ds->length < ds->allocated) { | 96 | 1.01k | ds->string[ds->length++] = c; | 97 | 1.01k | ds->string[ds->length] = '\0'; | 98 | 1.01k | } else { | 99 | 0 | ds_put_char__(ds, c); | 100 | 0 | } | 101 | 1.01k | } |
Unexecuted instantiation: ofp-msgs.c:ds_put_char Line | Count | Source | 94 | 109k | { | 95 | 109k | if (ds->length < ds->allocated) { | 96 | 106k | ds->string[ds->length++] = c; | 97 | 106k | ds->string[ds->length] = '\0'; | 98 | 106k | } else { | 99 | 3.11k | ds_put_char__(ds, c); | 100 | 3.11k | } | 101 | 109k | } |
Line | Count | Source | 94 | 1.14M | { | 95 | 1.14M | if (ds->length < ds->allocated) { | 96 | 1.12M | ds->string[ds->length++] = c; | 97 | 1.12M | ds->string[ds->length] = '\0'; | 98 | 1.12M | } else { | 99 | 14.1k | ds_put_char__(ds, c); | 100 | 14.1k | } | 101 | 1.14M | } |
Unexecuted instantiation: ofp-prop.c:ds_put_char ofp-protocol.c:ds_put_char Line | Count | Source | 94 | 5.22k | { | 95 | 5.22k | if (ds->length < ds->allocated) { | 96 | 4.12k | ds->string[ds->length++] = c; | 97 | 4.12k | ds->string[ds->length] = '\0'; | 98 | 4.12k | } else { | 99 | 1.10k | ds_put_char__(ds, c); | 100 | 1.10k | } | 101 | 5.22k | } |
Line | Count | Source | 94 | 38.3k | { | 95 | 38.3k | if (ds->length < ds->allocated) { | 96 | 36.5k | ds->string[ds->length++] = c; | 97 | 36.5k | ds->string[ds->length] = '\0'; | 98 | 36.5k | } else { | 99 | 1.84k | ds_put_char__(ds, c); | 100 | 1.84k | } | 101 | 38.3k | } |
Line | Count | Source | 94 | 8.90k | { | 95 | 8.90k | if (ds->length < ds->allocated) { | 96 | 8.69k | ds->string[ds->length++] = c; | 97 | 8.69k | ds->string[ds->length] = '\0'; | 98 | 8.69k | } else { | 99 | 216 | ds_put_char__(ds, c); | 100 | 216 | } | 101 | 8.90k | } |
Line | Count | Source | 94 | 636k | { | 95 | 636k | if (ds->length < ds->allocated) { | 96 | 632k | ds->string[ds->length++] = c; | 97 | 632k | ds->string[ds->length] = '\0'; | 98 | 632k | } else { | 99 | 3.64k | ds_put_char__(ds, c); | 100 | 3.64k | } | 101 | 636k | } |
Unexecuted instantiation: ofp-util.c:ds_put_char Unexecuted instantiation: ofpbuf.c:ds_put_char Unexecuted instantiation: ovs-router.c:ds_put_char Line | Count | Source | 94 | 6.42k | { | 95 | 6.42k | if (ds->length < ds->allocated) { | 96 | 6.40k | ds->string[ds->length++] = c; | 97 | 6.40k | ds->string[ds->length] = '\0'; | 98 | 6.40k | } else { | 99 | 14 | ds_put_char__(ds, c); | 100 | 14 | } | 101 | 6.42k | } |
Unexecuted instantiation: poll-loop.c:ds_put_char Unexecuted instantiation: smap.c:ds_put_char Unexecuted instantiation: socket-util.c:ds_put_char Unexecuted instantiation: sset.c:ds_put_char Unexecuted instantiation: timeval.c:ds_put_char Unexecuted instantiation: tnl-ports.c:ds_put_char tun-metadata.c:ds_put_char Line | Count | Source | 94 | 10.4k | { | 95 | 10.4k | if (ds->length < ds->allocated) { | 96 | 9.41k | ds->string[ds->length++] = c; | 97 | 9.41k | ds->string[ds->length] = '\0'; | 98 | 9.41k | } else { | 99 | 1.03k | ds_put_char__(ds, c); | 100 | 1.03k | } | 101 | 10.4k | } |
Unexecuted instantiation: unixctl.c:ds_put_char Unexecuted instantiation: vlog.c:ds_put_char Unexecuted instantiation: netdev-linux.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: backtrace.c:ds_put_char Unexecuted instantiation: classifier.c:ds_put_char Unexecuted instantiation: command-line.c:ds_put_char Unexecuted instantiation: coverage.c:ds_put_char Unexecuted instantiation: dp-packet-gso.c:ds_put_char Unexecuted instantiation: dpif-offload.c:ds_put_char Unexecuted instantiation: dpif-offload-dummy.c:ds_put_char Unexecuted instantiation: dpif.c:ds_put_char Unexecuted instantiation: fatal-signal.c:ds_put_char Line | Count | Source | 94 | 80.4M | { | 95 | 80.4M | if (ds->length < ds->allocated) { | 96 | 80.4M | ds->string[ds->length++] = c; | 97 | 80.4M | ds->string[ds->length] = '\0'; | 98 | 80.4M | } else { | 99 | 3.98k | ds_put_char__(ds, c); | 100 | 3.98k | } | 101 | 80.4M | } |
Unexecuted instantiation: jsonrpc.c:ds_put_char Line | Count | Source | 94 | 739 | { | 95 | 739 | if (ds->length < ds->allocated) { | 96 | 729 | ds->string[ds->length++] = c; | 97 | 729 | ds->string[ds->length] = '\0'; | 98 | 729 | } else { | 99 | 10 | ds_put_char__(ds, c); | 100 | 10 | } | 101 | 739 | } |
Unexecuted instantiation: namemap.c:ds_put_char Unexecuted instantiation: netdev-dummy.c:ds_put_char Unexecuted instantiation: netdev-vport.c:ds_put_char Unexecuted instantiation: netlink.c:ds_put_char Line | Count | Source | 94 | 9.64k | { | 95 | 9.64k | if (ds->length < ds->allocated) { | 96 | 9.04k | ds->string[ds->length++] = c; | 97 | 9.04k | ds->string[ds->length] = '\0'; | 98 | 9.04k | } else { | 99 | 592 | ds_put_char__(ds, c); | 100 | 592 | } | 101 | 9.64k | } |
Unexecuted instantiation: odp-execute.c:ds_put_char Unexecuted instantiation: odp-execute-private.c:ds_put_char Line | Count | Source | 94 | 2.58M | { | 95 | 2.58M | if (ds->length < ds->allocated) { | 96 | 2.57M | ds->string[ds->length++] = c; | 97 | 2.57M | ds->string[ds->length] = '\0'; | 98 | 2.57M | } else { | 99 | 9.54k | ds_put_char__(ds, c); | 100 | 9.54k | } | 101 | 2.58M | } |
ofp-actions.c:ds_put_char Line | Count | Source | 94 | 76.6k | { | 95 | 76.6k | if (ds->length < ds->allocated) { | 96 | 73.1k | ds->string[ds->length++] = c; | 97 | 73.1k | ds->string[ds->length] = '\0'; | 98 | 73.1k | } else { | 99 | 3.44k | ds_put_char__(ds, c); | 100 | 3.44k | } | 101 | 76.6k | } |
Line | Count | Source | 94 | 4.77k | { | 95 | 4.77k | if (ds->length < ds->allocated) { | 96 | 4.77k | ds->string[ds->length++] = c; | 97 | 4.77k | ds->string[ds->length] = '\0'; | 98 | 4.77k | } else { | 99 | 0 | ds_put_char__(ds, c); | 100 | 0 | } | 101 | 4.77k | } |
ofp-connection.c:ds_put_char Line | Count | Source | 94 | 102k | { | 95 | 102k | if (ds->length < ds->allocated) { | 96 | 101k | ds->string[ds->length++] = c; | 97 | 101k | ds->string[ds->length] = '\0'; | 98 | 101k | } else { | 99 | 948 | ds_put_char__(ds, c); | 100 | 948 | } | 101 | 102k | } |
Line | Count | Source | 94 | 3.14k | { | 95 | 3.14k | if (ds->length < ds->allocated) { | 96 | 2.90k | ds->string[ds->length++] = c; | 97 | 2.90k | ds->string[ds->length] = '\0'; | 98 | 2.90k | } else { | 99 | 239 | ds_put_char__(ds, c); | 100 | 239 | } | 101 | 3.14k | } |
Unexecuted instantiation: ofp-ed-props.c:ds_put_char Unexecuted instantiation: ofp-errors.c:ds_put_char Line | Count | Source | 94 | 137k | { | 95 | 137k | if (ds->length < ds->allocated) { | 96 | 130k | ds->string[ds->length++] = c; | 97 | 130k | ds->string[ds->length] = '\0'; | 98 | 130k | } else { | 99 | 6.24k | ds_put_char__(ds, c); | 100 | 6.24k | } | 101 | 137k | } |
Line | Count | Source | 94 | 58.4k | { | 95 | 58.4k | if (ds->length < ds->allocated) { | 96 | 52.6k | ds->string[ds->length++] = c; | 97 | 52.6k | ds->string[ds->length] = '\0'; | 98 | 52.6k | } else { | 99 | 5.77k | ds_put_char__(ds, c); | 100 | 5.77k | } | 101 | 58.4k | } |
Line | Count | Source | 94 | 22.7k | { | 95 | 22.7k | if (ds->length < ds->allocated) { | 96 | 22.2k | ds->string[ds->length++] = c; | 97 | 22.2k | ds->string[ds->length] = '\0'; | 98 | 22.2k | } else { | 99 | 542 | ds_put_char__(ds, c); | 100 | 542 | } | 101 | 22.7k | } |
Line | Count | Source | 94 | 8.61k | { | 95 | 8.61k | if (ds->length < ds->allocated) { | 96 | 7.28k | ds->string[ds->length++] = c; | 97 | 7.28k | ds->string[ds->length] = '\0'; | 98 | 7.28k | } else { | 99 | 1.32k | ds_put_char__(ds, c); | 100 | 1.32k | } | 101 | 8.61k | } |
ofp-monitor.c:ds_put_char Line | Count | Source | 94 | 7.32k | { | 95 | 7.32k | if (ds->length < ds->allocated) { | 96 | 6.73k | ds->string[ds->length++] = c; | 97 | 6.73k | ds->string[ds->length] = '\0'; | 98 | 6.73k | } else { | 99 | 594 | ds_put_char__(ds, c); | 100 | 594 | } | 101 | 7.32k | } |
Line | Count | Source | 94 | 71.9k | { | 95 | 71.9k | if (ds->length < ds->allocated) { | 96 | 69.1k | ds->string[ds->length++] = c; | 97 | 69.1k | ds->string[ds->length] = '\0'; | 98 | 69.1k | } else { | 99 | 2.80k | ds_put_char__(ds, c); | 100 | 2.80k | } | 101 | 71.9k | } |
Unexecuted instantiation: ofp-parse.c:ds_put_char Unexecuted instantiation: ox-stat.c:ds_put_char Unexecuted instantiation: pcap-file.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-neigh-cache.c:ds_put_char Unexecuted instantiation: netdev-native-tnl.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: dpif-netlink.c:ds_put_char Unexecuted instantiation: dpif-netlink-rtnl.c:ds_put_char Unexecuted instantiation: dpif-offload-tc.c:ds_put_char Unexecuted instantiation: dpif-offload-tc-netdev.c:ds_put_char Unexecuted instantiation: netlink-conntrack.c:ds_put_char Unexecuted instantiation: netlink-notifier.c:ds_put_char Unexecuted instantiation: stream-ssl.c:ds_put_char Line | Count | Source | 94 | 4.73k | { | 95 | 4.73k | if (ds->length < ds->allocated) { | 96 | 4.47k | ds->string[ds->length++] = c; | 97 | 4.47k | ds->string[ds->length] = '\0'; | 98 | 4.47k | } else { | 99 | 260 | ds_put_char__(ds, c); | 100 | 260 | } | 101 | 4.73k | } |
Unexecuted instantiation: conntrack.c:ds_put_char Unexecuted instantiation: cooperative-multitasking.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 Line | Count | Source | 94 | 26.4k | { | 95 | 26.4k | if (ds->length < ds->allocated) { | 96 | 26.2k | ds->string[ds->length++] = c; | 97 | 26.2k | ds->string[ds->length] = '\0'; | 98 | 26.2k | } else { | 99 | 149 | ds_put_char__(ds, c); | 100 | 149 | } | 101 | 26.4k | } |
Unexecuted instantiation: multipath.c:ds_put_char Unexecuted instantiation: process.c:ds_put_char Unexecuted instantiation: stream-tcp.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 Unexecuted instantiation: odp_target.c:ds_put_char Unexecuted instantiation: miniflow_target.c:ds_put_char Unexecuted instantiation: ofp_print_target.c:ds_put_char Unexecuted instantiation: ofctl_parse_target.c:ds_put_char |
102 | | |
103 | | #ifdef __cplusplus |
104 | | } |
105 | | #endif |
106 | | |
107 | | #endif /* dynamic-string.h */ |