diff options
author | pommicket <pommicket@gmail.com> | 2022-12-10 12:32:37 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-10 12:32:37 -0500 |
commit | 10ceae41707d6a7aa43d5b8615a47b4f279fbf05 (patch) | |
tree | 55ae446197dfcd2d510e1bd185ba9e06a4ddab8e | |
parent | b7cbc84f296024d3a89e4604c1b114e79b4e752e (diff) | |
parent | 17e12d6cd6dc769d714991da97db153e7225180e (diff) |
Merge branch 'trunk' into lsp
-rw-r--r-- | util.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -69,9 +69,17 @@ static bool streq(char const *a, char const *b) { return strcmp(a, b) == 0; } +static size_t strn_len(const char *src, size_t n) { + const char *p = memchr(src, '\0', n); + if (p) + return (size_t)(p - src); + else + return n; +} + // duplicates at most n characters from src static char *strn_dup(char const *src, size_t n) { - size_t len = strlen(src); + size_t len = strn_len(src, n); if (n > len) n = len; char *ret = malloc(n + 1); |