Mercurial > libedl
comparison src/util.c @ 8:0c98b46eaf73 v2.0
*: update API to 2.0, big changes
all APIs now use pointers to an EDL object. it is up to the
user to make sure that the pointer is valid.
additionally, many things have been separated into new files
to make it easier to digest
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 03 Mar 2024 17:56:58 -0500 |
parents | |
children | d6f8f73a0c50 |
comparison
equal
deleted
inserted
replaced
7:fee08fa622e1 | 8:0c98b46eaf73 |
---|---|
1 #include "util.h" | |
2 | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
5 | |
6 /* reimplementations of non-portable stdlib functions */ | |
7 | |
8 size_t EDL_internal_strnlen(const char* s, size_t maxlen) { | |
9 size_t len; | |
10 | |
11 for (len = 0; len < maxlen; len++, s++) { | |
12 if (!*s) | |
13 break; | |
14 } | |
15 | |
16 return len; | |
17 } | |
18 | |
19 char* EDL_internal_strnchr(const char* haystack, char needle, size_t length) { | |
20 for (; length && *haystack != needle; haystack++, length--); | |
21 | |
22 return length ? haystack : NULL; | |
23 } | |
24 | |
25 char* EDL_internal_strdup(const char* s) { | |
26 const size_t len = strlen(s); | |
27 | |
28 char* d = malloc((len + 1) * sizeof(char)); | |
29 memcpy(d, s, len * sizeof(char)); | |
30 d[len] = '\0'; | |
31 | |
32 return d; | |
33 } |