path: root/src/ptr.h
diff options
authorSteve Slaven <bpk@hoopajoo.net>2019-11-05 06:26:14 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2019-11-05 06:26:14 (GMT)
commit9c4c0a1e366b9d932e4ab2ce03a0e80126d93d9b (patch)
tree928e4c6f49ac50f7e69777b00073df37d7d11e3f /src/ptr.h
parenteb9898c7fcc017a35c240c1bd83c8a8ff451431a (diff)
reorganizing files
Diffstat (limited to 'src/ptr.h')
1 files changed, 75 insertions, 0 deletions
diff --git a/src/ptr.h b/src/ptr.h
new file mode 100644
index 0000000..2a19843
--- /dev/null
+++ b/src/ptr.h
@@ -0,0 +1,75 @@
+ * ptr.h -- type definitions for ptr (aka "pointer"), a char* replacement
+ * which allows for '\0' inside a string.
+ */
+#ifndef _PTR_H_
+#define _PTR_H_
+typedef struct s_ptr {
+ int len;
+ int max;
+ int signature;
+} _ptr;
+typedef _ptr * ptr;
+#define sizeofptr ((int)(1 + sizeof(_ptr)))
+/* the + 0 below is to prohibit using the macros for altering the ptr */
+#define ptrlen(p) ((p)->len + 0)
+#define ptrmax(p) ((p)->max + 0)
+#define ptrdata(p) ((char *)((ptr)(p) + 1))
+/* if p is a valid (ptr), ptrdata(p) is guaranteed to be a valid (char *) */
+ptr ptrnew(int max);
+ptr ptrdup2(ptr src, int newmax);
+ptr ptrdup(ptr src);
+#define PTR_SIG 91887
+#define ptrdel(x) _ptrdel(x);x=(ptr)0;
+void _ptrdel(ptr p);
+void ptrzero(ptr p);
+void ptrshrink(ptr p, int len);
+void ptrtrunc(ptr p, int len);
+ptr ptrpad(ptr p, int len);
+ptr ptrsetlen(ptr p, int len);
+ptr ptrcpy(ptr dst, ptr src);
+ptr ptrmcpy(ptr dst, char *src, int len);
+ptr ptrcat(ptr dst, ptr src);
+ptr ptrmcat(ptr dst, char *src, int len);
+ptr __ptrcat(ptr dst, char *src, int len, int shrink);
+ptr __ptrmcpy(ptr dst, char *src, int len, int shrink);
+int ptrcmp(ptr p, ptr q);
+int ptrmcmp(ptr p, char *q, int lenq);
+char *ptrchr(ptr p, char c);
+char *ptrrchr(ptr p, char c);
+char *ptrfind(ptr p, ptr q);
+char *ptrmfind(ptr p, char *q, int lenq);
+char *ptrchrs(ptr p, ptr q);
+char *ptrmchrs(ptr p, char *q, int lenq);
+char *ptrrchrs(ptr p, ptr q);
+char *ptrmrchrs(ptr p, char *q, int lenq);
+char *memchrs(char *p, int lenp, char *q, int lenq);
+char *memrchrs(char *p, int lenp, char *q, int lenq);
+#ifdef _GNU_SOURCE
+# define memfind memmem
+char *memfind(char *hay, int haylen, char *needle, int needlelen);
+/* TODO: watch memrchr, it is defined differently here than under _GNU_SOURCE,
+ * so it could cause bizarre results if a module makes use of a library that
+ * uses it */
+char *memrchr(char *p, int lenp, char c);
+#endif /* _PTR_H_ */