Permalink
Browse files

Add strndup() compat function for SunOS

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
  • Loading branch information...
1 parent 081408e commit 6bc3299038a14ec1e8dae365593c40f17a4095ae Pekka Enberg committed Nov 12, 2009
Showing with 43 additions and 0 deletions.
  1. +10 −0 Makefile
  2. +24 −0 compat/strndup.c
  3. +1 −0 csv.c
  4. +8 −0 include/pstore/compat.h
View
@@ -1,3 +1,5 @@
+uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
+
# External programs
CC := gcc
@@ -47,6 +49,12 @@ endif
export E Q
# Project files
+COMPAT_OBJS =
+
+ifeq ($(uname_S),SunOS)
+ COMPAT_OBJS += compat/strndup.o
+endif
+
PROGRAM := pstore
OBJS := block.o \
builtin-cat.o \
@@ -60,6 +68,8 @@ OBJS := block.o \
string.o \
table.o
+OBJS += $(COMPAT_OBJS)
+
DEPS := $(patsubst %.o,%.d,$(OBJS))
TEST_PROGRAM := test-pstore
View
@@ -0,0 +1,24 @@
+#include "pstore/compat.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+char *strndup(const char *s, size_t n)
+{
+ size_t size;
+ char *p;
+
+ if (!s)
+ return NULL;
+
+ size = strlen(s);
+ if (size > n)
+ size = n;
+ size++;
+
+ p = malloc(size);
+ memcpy(p, s, size);
+ p[size - 1] = '\0';
+
+ return p;
+}
View
1 csv.c
@@ -1,4 +1,5 @@
#include "pstore/string.h"
+#include "pstore/compat.h"
#include "pstore/csv.h"
#define _GNU_SOURCE
View
@@ -0,0 +1,8 @@
+#ifndef PSTORE_COMPAT_H
+#define PSTORE_COMPAT_H
+
+#include <stddef.h>
+
+char *strndup(const char *s, size_t n);
+
+#endif /* PSTORE_COMPAT_H */

0 comments on commit 6bc3299

Please sign in to comment.