Skip to content

Instantly share code, notes, and snippets.

@danielhams
Last active November 12, 2019 22:00
Show Gist options
  • Save danielhams/9d25fc18eb771f0b4aaf5bf408dc4ee9 to your computer and use it in GitHub Desktop.
Save danielhams/9d25fc18eb771f0b4aaf5bf408dc4ee9 to your computer and use it in GitHub Desktop.
quick revs
#ifndef MYUID_IRIX_H
#define MYUID_IRIX_H
#include <string.h>
#include <config.h>
inline size_t strnlen (const char *string, size_t maxlen)
{
const char *end = memchr (string, '\0', maxlen);
return end ? (size_t) (end - string) : maxlen;
}
inline char * strndup(char const *s, size_t n)
{
size_t len = strnlen (s, n);
char *new = malloc (len + 1);
if (new == NULL)
return NULL;
new[len] = '\0';
return memcpy (new, s, len);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment