aboutsummaryrefslogtreecommitdiffstats
path: root/ptr.h
blob: 06a0271fb4f820dd3b8cfc0eac6b4ebb3fd62cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 *  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;
} _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    __P ((int max));
ptr   ptrdup2   __P ((ptr src, int newmax));
ptr   ptrdup    __P ((ptr src));
void  ptrdel    __P ((ptr p));

void  ptrzero   __P ((ptr p));
void  ptrshrink __P ((ptr p, int len));
void  ptrtrunc  __P ((ptr p, int len));
ptr   ptrpad    __P ((ptr p, int len));
ptr   ptrsetlen __P ((ptr p, int len));

ptr   ptrcpy    __P ((ptr dst, ptr src));
ptr   ptrmcpy   __P ((ptr dst, char *src, int len));

ptr   ptrcat    __P ((ptr dst, ptr src));
ptr   ptrmcat   __P ((ptr dst, char *src, int len));


ptr __ptrcat    __P ((ptr dst, char *src, int len, int shrink));
ptr __ptrmcpy   __P ((ptr dst, char *src, int len, int shrink));

int   ptrcmp    __P ((ptr p, ptr q));
int   ptrmcmp   __P ((ptr p, char *q, int lenq));

char *ptrchr    __P ((ptr p, char c));
char *ptrrchr   __P ((ptr p, char c));

char *ptrfind    __P ((ptr p, ptr q));
char *ptrmfind   __P ((ptr p, char *q, int lenq));

char *ptrchrs   __P ((ptr p, ptr q));
char *ptrmchrs  __P ((ptr p, char *q, int lenq));
char *ptrrchrs  __P ((ptr p, ptr q));
char *ptrmrchrs __P ((ptr p, char *q, int lenq));

char *memchrs   __P ((char *p, int lenp, char *q, int lenq));
char *memrchrs  __P ((char *p, int lenp, char *q, int lenq));
#ifdef _GNU_SOURCE
# define memfind memmem
#else
char *memfind   __P ((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   __P ((char *p, int lenp, char c));
#endif

#endif /* _PTR_H_ */