1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
10 #include <ecoli_assert.h>
11 #include <ecoli_malloc.h>
12 #include <ecoli_string.h>
14 /* count the number of identical chars at the beginning of 2 strings */
15 size_t ec_strcmp_count(const char *s1, const char *s2)
19 while (s1[i] && s2[i] && s1[i] == s2[i])
25 int ec_str_startswith(const char *s, const char *beginning)
29 len = ec_strcmp_count(s, beginning);
30 if (beginning[len] == '\0')
36 int ec_vasprintf(char **buf, const char *fmt, va_list ap)
44 ret = vsnprintf(&dummy, 1, fmt, aq);
50 *buf = ec_malloc(buflen);
55 ret = vsnprintf(*buf, buflen, fmt, aq);
58 ec_assert_print(ret < buflen, "invalid return value for vsnprintf");
68 int ec_asprintf(char **buf, const char *fmt, ...)
74 ret = ec_vasprintf(buf, fmt, ap);