1 /*
2  * Copyright (C) 1998,1999 Uwe Ohse
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  * As a special exception this source may be used as part of the
19  * SRS project by CORE/Computer Service Langenbach
20  * regardless of the copyright they choose.
21  *
22  * Contact: uwe@ohse.de
23  */
24 #include "uostr.h"
25 
26 #ifdef __GNUC__
27 #ifndef __cplusplus
28 inline /* just too aggressive */
29 #endif
30 #endif
31   uostr_t *
uostr_add_mem(uostr_t * u,const char * v,size_t len)32 uostr_add_mem(uostr_t *u, const char *v, size_t len)
33 {
34 	char *p;
35 	int runs;
36 	if (!uostr_needmore(u,len+1)) return 0;
37 	if (!len) goto out;
38 	p=u->data+u->len;
39 	runs=(len+7)/8;
40 	switch ((int)(len%8)) {
41 		while (runs) {
42 	case 0: /* HPUX 9.00 cc barfed about "default" here: 'default' should appear at most once in 'switch' */
43 			*p++=*v++;
44 	case 7: *p++=*v++;
45 	case 6: *p++=*v++;
46 	case 5: *p++=*v++;
47 	case 4: *p++=*v++;
48 	case 3: *p++=*v++;
49 	case 2: *p++=*v++;
50 	case 1: *p++=*v++;
51 		--runs;
52 		} /* while */
53 	} /* case duff */
54   out:
55 	u->len+=len;
56 	u->data[u->len]='Z'; /* clever idea stolen from djb */
57 	return u;
58 }
59 uostr_t *
uostr_xadd_mem(uostr_t * u,const char * v,size_t bytes)60 uostr_xadd_mem(uostr_t *u, const char *v, size_t bytes)
61 { uostr_t *r=uostr_add_mem(u,v,bytes); if (!r) uostr_xallocerr("uostr_xadd_mem"); return r; }
62 
63 
64 uostr_t *
uostr_dup_mem(uostr_t * u,const char * v,size_t len)65 uostr_dup_mem(uostr_t *u,const char *v, size_t len)
66 {
67 	u->len=0;
68 	return uostr_add_mem(u,v,len);
69 }
70 uostr_t *
uostr_xdup_mem(uostr_t * u,const char * v,size_t bytes)71 uostr_xdup_mem(uostr_t *u, const char *v, size_t bytes)
72 { uostr_t *r; u->len=0;r=uostr_add_mem(u,v,bytes); if (!r) uostr_xallocerr("uostr_xdup_mem"); return r; }
73 
74 
75