1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
11 #include <ecoli_assert.h>
12 #include <ecoli_malloc.h>
13 #include <ecoli_string.h>
15 /* count the number of identical chars at the beginning of 2 strings */
16 size_t ec_strcmp_count(const char *s1, const char *s2)
20 while (s1[i] && s2[i] && s1[i] == s2[i])
26 int ec_str_startswith(const char *s, const char *beginning)
30 len = ec_strcmp_count(s, beginning);
31 if (beginning[len] == '\0')
37 int ec_vasprintf(char **buf, const char *fmt, va_list ap)
45 ret = vsnprintf(&dummy, 1, fmt, aq);
51 *buf = ec_malloc(buflen);
56 ret = vsnprintf(*buf, buflen, fmt, aq);
59 ec_assert_print(ret < buflen, "invalid return value for vsnprintf");
69 int ec_asprintf(char **buf, const char *fmt, ...)
75 ret = ec_vasprintf(buf, fmt, ap);
81 bool ec_str_is_space(const char *s)