]> git.sesse.net Git - vlc/blobdiff - include/vlc_fixups.h
Inline strdup, strndup, lldiv and getenv
[vlc] / include / vlc_fixups.h
index 15d9d637de4f4617866845cbd80c88360511c452..8045ed56b71549b68720113af67510256fe48798 100644 (file)
 #ifndef LIBVLC_FIXUPS_H
 # define LIBVLC_FIXUPS_H 1
 
+# include <string.h>
+# include <stdlib.h>
+
 #ifndef HAVE_STRDUP
-# define strdup vlc_strdup
+static inline char *strdup (const char *str)
+{
+    size_t len = strlen (str) + 1;
+    char *res = malloc (len);
+    if (res) memcpy (res, str, len);
+    return res;
+}
 #endif
 
 #ifndef HAVE_VASPRINTF
 #endif
 
 #ifndef HAVE_STRNDUP
-# define strndup vlc_strndup
+static inline char *strndup (const char *str, size_t max)
+{
+    const char *end = memchr (str, '\0', max);
+    size_t len = end ? (size_t)(end - str) : max;
+    char *res = malloc (len + 1);
+    if (res)
+    {
+        memcpy (res, str, len);
+        res[len] = '\0';
+    }
+    return res;
+}
 #endif
 
 #ifndef HAVE_STRNLEN
 #endif
 
 #ifndef HAVE_LLDIV
-# define lldiv vlc_lldiv
+typedef struct {
+    long long quot; /* Quotient. */
+    long long rem;  /* Remainder. */
+} lldiv_t;
+
+static inline lldiv_t lldiv (long long numer, long long denom)
+{
+    lldiv_t d = { .quot = numer / denom, .rem = numer % denom };
+    return d;
+}
 #endif
 
 #ifndef HAVE_SCANDIR
 #endif
 
 #ifndef HAVE_GETENV
-# define getenv vlc_getenv
+static inline getenv (const char *name)
+{
+    (void)name;
+    return NULL;
+}
 #endif
 
 #ifndef HAVE_STRCASECMP