Node and graph common functions */ * @internal * * Naming a cloned graph or node by appending a string to base name. * * @param new_name * Pointer to the name of the cloned object. * @param base_name * Pointer to the name of original object. * @param append_str * Pointer to the appended string. * * @return * 0 on success, negative errno value otherwise. */
| 147 | * 0 on success, negative errno value otherwise. |
| 148 | */ |
| 149 | static inline int clone_name(char *new_name, char *base_name, const char *append_str) |
| 150 | { |
| 151 | ssize_t sz, rc; |
| 152 | |
| 153 | #define SZ RTE_MIN(RTE_NODE_NAMESIZE, RTE_GRAPH_NAMESIZE) |
| 154 | rc = rte_strscpy(new_name, base_name, SZ); |
| 155 | if (rc < 0) |
| 156 | goto fail; |
| 157 | sz = rc; |
| 158 | rc = rte_strscpy(new_name + sz, "-", RTE_MAX((int16_t)(SZ - sz), 0)); |
| 159 | if (rc < 0) |
| 160 | goto fail; |
| 161 | sz += rc; |
| 162 | sz = rte_strscpy(new_name + sz, append_str, RTE_MAX((int16_t)(SZ - sz), 0)); |
| 163 | if (sz < 0) |
| 164 | goto fail; |
| 165 | |
| 166 | return 0; |
| 167 | fail: |
| 168 | rte_errno = E2BIG; |
| 169 | return -rte_errno; |
| 170 | } |
| 171 | |
| 172 | /* Node functions */ |
| 173 | STAILQ_HEAD(node_head, node); |
no test coverage detected