summaryrefslogtreecommitdiff
path: root/c_src/pstring.h
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2016-02-18 14:49:44 +0100
committerMagnus Ahltorp <map@kth.se>2016-02-18 14:49:44 +0100
commit3e98e566955d0ab63b8d16b30ca5a5045d00bf4c (patch)
treeb8d5caa9949da999e5de80ff285f37ecbd569114 /c_src/pstring.h
parent3dcd4866661c81cb186106f0c1691f5f5105274a (diff)
Remove Heimdal hash implementation
Add missing files from previous commits
Diffstat (limited to 'c_src/pstring.h')
-rw-r--r--c_src/pstring.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/c_src/pstring.h b/c_src/pstring.h
new file mode 100644
index 0000000..3a8b602
--- /dev/null
+++ b/c_src/pstring.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, NORDUnet A/S.
+ * See LICENSE for licensing information.
+ */
+
+#ifndef PSTRING_H
+#define PSTRING_H
+
+typedef struct ps_string {
+ unsigned char length;
+ char value[255];
+} ps_string;
+
+#define PS_STRING(s) (&(ps_string){strlen(s), s})
+#define PS_PRINTF(s) s->length, s->value
+
+static inline ps_string *
+ps_strdup(const ps_string *s)
+{
+ size_t size = s->length + 1;
+ ps_string *copy = malloc(size);
+ memcpy(copy, s, size);
+ return copy;
+}
+
+static inline ps_string *
+ps_resize(const ps_string *s, size_t length)
+{
+ assert(length <= s->length);
+ size_t newsize = length + 1;
+ ps_string *copy = malloc(newsize);
+ memcpy(copy->value, s->value, length);
+ copy->length = length;
+ return copy;
+}
+
+#endif