-/* $Id: xstd.c,v 1.3 2009/01/17 16:15:27 kristaps Exp $ */
+/* $Id: xstd.c,v 1.7 2009/03/06 14:13:47 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
#include "private.h"
+/*
+ * Contains wrappers for common functions to simplify their general
+ * usage throughout this codebase.
+ */
+
#ifdef __linux__
extern size_t strlcat(char *, const char *, size_t);
extern size_t strlcpy(char *, const char *, size_t);
#endif
+int
+xstrncmp(const char *p1, const char *p2, size_t sz)
+{
+
+ return(0 == strncmp(p1, p2, sz));
+}
+
int
xstrcmp(const char *p1, const char *p2)
{
return(0 == strcmp(p1, p2));
}
-
int
xstrlcat(char *dst, const char *src, size_t sz)
{
return(strlcat(dst, src, sz) < sz);
}
-
int
xstrlcpy(char *dst, const char *src, size_t sz)
{
return(strlcpy(dst, src, sz) < sz);
}
+void *
+xrealloc(void *ptr, size_t sz)
+{
+ void *p;
+ if (NULL == (p = realloc(ptr, sz)))
+ err(EXIT_FAILURE, "realloc");
+ return(p);
+}
void *
xcalloc(size_t num, size_t sz)
return(p);
}
-
char *
xstrdup(const char *p)
{
return(pp);
}
-
int
-xstrlcats(char *buf, const struct mdoc_node *n, size_t sz)
+xstrlcpys(char *buf, const struct mdoc_node *n, size_t sz)
{
char *p;
return(1);
}
-
-
-
#ifdef __linux__
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
return(dlen + (s - src)); /* count does not include NUL */
}
-
size_t
strlcpy(char *dst, const char *src, size_t siz)
{