src/server/util/util.c

Sun, 23 Jun 2013 13:51:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Jun 2013 13:51:49 +0200
changeset 75
6195c92262a2
parent 69
4a10bc0ee80d
child 77
f1cff81e425a
permissions
-rw-r--r--

merge

1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * THE BSD LICENSE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * modification, are permitted provided that the following conditions are met:
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 * Redistributions of source code must retain the above copyright notice, this
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * list of conditions and the following disclaimer.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * Redistributions in binary form must reproduce the above copyright notice,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * this list of conditions and the following disclaimer in the documentation
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 * and/or other materials provided with the distribution.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * Neither the name of the nor the names of its contributors may be
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * used to endorse or promote products derived from this software without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * specific prior written permission.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 * util.c: A hodge podge of utility functions and standard functions which
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 * are unavailable on certain systems
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 * Rob McCool
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #ifdef XP_UNIX
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include <sys/types.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #include <sys/wait.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 #include <stdlib.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include <unistd.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 #include <limits.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #include "prthread.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 #endif /* XP_UNIX */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
24
1a7853a4257e removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
51 //include "nspr.h"
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
52 #include <errno.h>
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
53
24
1a7853a4257e removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
54 #include "../daemon/netsite.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
55 #include "../public/nsapi.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 #include "util.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
59
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
60
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
61 /* ------------------------------ _uudecode ------------------------------- */
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
63 static const unsigned char pr2six[256] = {
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
64 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
65 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
66 52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
67 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
68 28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
69 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
70 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
71 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
72 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
73 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
74 64,64,64,64,64,64,64,64,64,64,64,64,64
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
75 };
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
76
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
77 /** you MUST reserve at least 2 additional bytes for bufout */
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
78 size_t util_base64decode(char *bufcoded, size_t codedbytes, char *bufout) {
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
79 register char *bufin = bufcoded;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
80 register int nprbytes;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
81 size_t nbytesdecoded;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
82
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
83 /* Find the length */
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
84 nprbytes = (int) codedbytes;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
85 while(pr2six[(int)(bufin[nprbytes-1])] >= 64) {
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
86 nprbytes--;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
87 }
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
88 nbytesdecoded = ((nprbytes+3)/4) * 3;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
89
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
90 while (nprbytes > 0) {
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
91 *(bufout++) = (unsigned char)
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
92 (pr2six[(int)(*bufin)] << 2 | pr2six[(int)bufin[1]] >> 4);
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
93 *(bufout++) = (unsigned char)
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
94 (pr2six[(int)bufin[1]] << 4 | pr2six[(int)bufin[2]] >> 2);
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
95 *(bufout++) = (unsigned char)
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
96 (pr2six[(int)bufin[2]] << 6 | pr2six[(int)bufin[3]]);
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
97 bufin += 4;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
98 nprbytes -= 4;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
99 }
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
100
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
101 if(nprbytes & 03) {
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
102 if(pr2six[(int)bufin[-2]] > 63)
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
103 nbytesdecoded -= 2;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
104 else
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
105 nbytesdecoded -= 1;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
106 }
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
107
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
108 return nbytesdecoded;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
109 }
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
110
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 NSAPI_PUBLIC int util_getboolean(const char *v, int def) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 if(v[0] == 'T' || v[0] == 't') {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 return 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 if(v[0] == 'F' || v[0] == 'f') {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 return 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 return def;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 NSAPI_PUBLIC int INTutil_getboolean(const char *v, int def) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 if(v[0] == 'T' || v[0] == 't') {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 return 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 if(v[0] == 'F' || v[0] == 'f') {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 return 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 return def;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 /* ------------------------------ util_itoa ------------------------------- */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 NSAPI_PUBLIC int util_itoa(int i, char *a)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 int len = util_i64toa(i, a);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 PR_ASSERT(len < UTIL_ITOA_SIZE);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 return len;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 NSAPI_PUBLIC int INTutil_itoa(int i, char *a) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 return INTutil_i64toa(i, a);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 /* ----------------------------- util_i64toa ------------------------------ */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 * Assumption: Reversing the digits will be faster in the general case
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 * than doing a log10 or some nasty trick to find the # of digits.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156
24
1a7853a4257e removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
157 NSAPI_PUBLIC int INTutil_i64toa(int64_t i, char *a)
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 register int x, y, p;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 register char c;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 int negative;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 negative = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 if(i < 0) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 *a++ = '-';
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 negative = 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 i = -i;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 p = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 while(i > 9) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 a[p++] = (i%10) + '0';
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 i /= 10;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 a[p++] = i + '0';
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 if(p > 1) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 for(x = 0, y = p - 1; x < y; ++x, --y) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 c = a[x];
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 a[x] = a[y];
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 a[y] = c;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 a[p] = '\0';
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 //PR_ASSERT(p + negative < UTIL_I64TOA_SIZE);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 return p + negative;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
47
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
189
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
190
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
191
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
192 #ifndef XP_WIN32
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
193 NSAPI_PUBLIC struct passwd *
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
194 util_getpwnam(const char *name, struct passwd *result, char *buffer,
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
195 int buflen)
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
196 {
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
197 struct passwd *rv;
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
198
69
4a10bc0ee80d compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
199 #if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX)
47
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
200 errno = getpwnam_r(name, result, buffer, buflen, &rv);
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
201 if (errno != 0)
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
202 rv = NULL;
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
203 #else
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
204 rv = getpwnam_r(name, result, buffer, buflen);
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
205 #endif
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
206
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
207 return rv;
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
208 }
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
209 #endif
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
210
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
211
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
212 #ifndef XP_WIN32
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
213 NSAPI_PUBLIC struct passwd *
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
214 util_getpwuid(uid_t uid, struct passwd *result, char *buffer, int buflen)
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
215 {
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
216 struct passwd *rv;
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
217
69
4a10bc0ee80d compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
218 #if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX)
47
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
219 errno = getpwuid_r(uid, result, buffer, buflen, &rv);
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
220 if (errno != 0)
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
221 rv = NULL;
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
222 #else
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
223 rv = getpwuid_r(uid, result, buffer, buflen);
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
224 #endif
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
225
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
226 return rv;
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
227 }
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
228 #endif
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
229
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
230
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
231 NSAPI_PUBLIC int util_errno2status(int errno_value) {
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
232 switch(errno_value) {
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
233 case 0: {
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
234 return 200;
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
235 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
236 case EACCES: {
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
237 return 403;
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
238 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
239 case ENOENT: {
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
240 return 404;
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
241 break;
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
242 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
243 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
244 return 500;
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
245 }
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
246
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
247 NSAPI_PUBLIC int util_uri_unescape_strict(char *s)
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
248 {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
249 char *t, *u, t1, t2;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
250 int rv = 1;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
251
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
252 for(t = s, u = s; *t; ++t, ++u) {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
253 if (*t == '%') {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
254 t1 = t[1] & 0xdf; /* [a-f] -> [A-F] */
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
255 if ((t1 < 'A' || t1 > 'F') && (t[1] < '0' || t[1] > '9'))
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
256 rv = 0;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
257
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
258 t2 = t[2] & 0xdf; /* [a-f] -> [A-F] */
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
259 if ((t2 < 'A' || t2 > 'F') && (t[2] < '0' || t[2] > '9'))
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
260 rv = 0;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
261
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
262 *u = ((t[1] >= 'A' ? ((t[1] & 0xdf) - 'A')+10 : (t[1] - '0'))*16) +
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
263 (t[2] >= 'A' ? ((t[2] & 0xdf) - 'A')+10 : (t[2] - '0'));
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
264 t += 2;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
265 }
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
266 else if (u != t)
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
267 *u = *t;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
268 }
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
269 *u = *t;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
270
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
271 return rv;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
272 }
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
273
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
274 NSAPI_PUBLIC
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
275 sstr_t util_path_append(pool_handle_t *pool, char *path, char *ch) {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
276 sstr_t parent = sstr(path);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
277 sstr_t child = sstr(ch);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
278 sstr_t newstr;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
279 sstr_t s;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
280
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
281 s.length = 0;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
282 s.ptr = NULL;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
283 newstr.length = parent.length + child.length;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
284 if(parent.ptr[parent.length - 1] != '/') {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
285 s = sstrn("/", 1);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
286 newstr.length++;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
287 }
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
288
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
289 newstr.ptr = pool_malloc(pool, newstr.length + 1);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
290 if(!newstr.ptr) {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
291 // TODO: error
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
292 newstr.length = 0;
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
293 return newstr;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
294 }
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
295 if(s.length == 1) {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
296 newstr = sstrncat(3, newstr, parent, s, child);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
297 } else {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
298 newstr = sstrncat(2, newstr, parent, child);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
299 }
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
300 newstr.ptr[newstr.length] = '\0';
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
301
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
302 return newstr;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
303 }
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
304
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
305 sstr_t util_path_remove_last(sstr_t path) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
306 int i;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
307 for(i=path.length-1;i>=0;i--) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
308 char c = path.ptr[i];
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
309 if(c == '/') {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
310 path.ptr[i] = 0;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
311 path.length = i;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
312 break;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
313 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
314 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
315 if(i < 0) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
316 path.ptr = NULL;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
317 path.length = 0;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
318 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
319 return path;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
320 }

mercurial