This function is only offered by GNU extensions and is sometimes
useful during configuration parsing.
return ((unsigned long long)a * b) >> 32;
}
+/* copies at most <n> characters from <src> and always terminates with '\0' */
+char *my_strndup(const char *src, int n);
+
#endif /* _COMMON_STANDARD_H */
return NULL;
}
+/* copies at most <n> characters from <src> and always terminates with '\0' */
+char *my_strndup(const char *src, int n)
+{
+ int len = 0;
+ char *ret;
+
+ while (len < n && src[len])
+ len++;
+
+ ret = (char *)malloc(len + 1);
+ if (!ret)
+ return ret;
+ memcpy(ret, src, len);
+ ret[len] = '\0';
+ return ret;
+}
+
/*
* Local variables:
* c-indent-level: 8