1 /* 2 * ptr.h -- type definitions for ptr (aka "pointer"), a char* replacement 3 * which allows for '\0' inside a string. 4 */ 5 6 #ifndef _PTR_H_ 7 #define _PTR_H_ 8 9 typedef struct s_ptr { 10 int len; 11 int max; 12 int signature; 13 } _ptr; 14 15 typedef _ptr * ptr; 16 17 #define sizeofptr ((int)(1 + sizeof(_ptr))) 18 19 /* the + 0 below is to prohibit using the macros for altering the ptr */ 20 #define ptrlen(p) ((p)->len + 0) 21 #define ptrmax(p) ((p)->max + 0) 22 #define ptrdata(p) ((char *)((ptr)(p) + 1)) 23 /* if p is a valid (ptr), ptrdata(p) is guaranteed to be a valid (char *) */ 24 25 ptr ptrnew __P ((int max)); 26 ptr ptrdup2 __P ((ptr src, int newmax)); 27 ptr ptrdup __P ((ptr src)); 28 29 #define PTR_SIG 91887 30 #define ptrdel(x) _ptrdel(x);x=(ptr)0; 31 void _ptrdel __P ((ptr p)); 32 33 void ptrzero __P ((ptr p)); 34 void ptrshrink __P ((ptr p, int len)); 35 void ptrtrunc __P ((ptr p, int len)); 36 ptr ptrpad __P ((ptr p, int len)); 37 ptr ptrsetlen __P ((ptr p, int len)); 38 39 ptr ptrcpy __P ((ptr dst, ptr src)); 40 ptr ptrmcpy __P ((ptr dst, char *src, int len)); 41 42 ptr ptrcat __P ((ptr dst, ptr src)); 43 ptr ptrmcat __P ((ptr dst, char *src, int len)); 44 45 46 ptr __ptrcat __P ((ptr dst, char *src, int len, int shrink)); 47 ptr __ptrmcpy __P ((ptr dst, char *src, int len, int shrink)); 48 49 int ptrcmp __P ((ptr p, ptr q)); 50 int ptrmcmp __P ((ptr p, char *q, int lenq)); 51 52 char *ptrchr __P ((ptr p, char c)); 53 char *ptrrchr __P ((ptr p, char c)); 54 55 char *ptrfind __P ((ptr p, ptr q)); 56 char *ptrmfind __P ((ptr p, char *q, int lenq)); 57 58 char *ptrchrs __P ((ptr p, ptr q)); 59 char *ptrmchrs __P ((ptr p, char *q, int lenq)); 60 char *ptrrchrs __P ((ptr p, ptr q)); 61 char *ptrmrchrs __P ((ptr p, char *q, int lenq)); 62 63 char *memchrs __P ((char *p, int lenp, char *q, int lenq)); 64 char *memrchrs __P ((char *p, int lenp, char *q, int lenq)); 65 #ifdef _GNU_SOURCE 66 # define memfind memmem 67 #else 68 char *memfind __P ((char *hay, int haylen, char *needle, int needlelen)); 69 /* TODO: watch memrchr, it is defined differently here than under _GNU_SOURCE, 70 * so it could cause bizarre results if a module makes use of a library that 71 * uses it */ 72 //char *memrchr __P ((char *p, int lenp, char c)); 73 #endif 74 75 #endif /* _PTR_H_ */ 76