author | zautrix <zautrix> | 2004-10-19 20:16:14 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-19 20:16:14 (UTC) |
commit | eca49bb06a71980ef61d078904573f25890fc7f2 (patch) (unidiff) | |
tree | c5338e3b12430248979a9ac2c1c7e6646ea9ecdf /pwmanager/libcrypt/crypt/missing-string.c | |
parent | 53cc32b6e7b1f672bf91b2baf2df6c1e8baf3e0a (diff) | |
download | kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.zip kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.tar.gz kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.tar.bz2 |
Initial revision
Diffstat (limited to 'pwmanager/libcrypt/crypt/missing-string.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/libcrypt/crypt/missing-string.c | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/pwmanager/libcrypt/crypt/missing-string.c b/pwmanager/libcrypt/crypt/missing-string.c new file mode 100644 index 0000000..80ff052 --- a/dev/null +++ b/pwmanager/libcrypt/crypt/missing-string.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* missing-string.c - missing string utilities | ||
2 | * Copyright (C) 1994, 1998, 1999, 2000, 2001, | ||
3 | * 2003 Free Software Foundation, Inc. | ||
4 | * | ||
5 | * This file is part of Libgcrypt. | ||
6 | * | ||
7 | * Libgcrypt is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU Lesser General Public License as | ||
9 | * published by the Free Software Foundation; either version 2.1 of | ||
10 | * the License, or (at your option) any later version. | ||
11 | * | ||
12 | * Libgcrypt is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
20 | */ | ||
21 | |||
22 | #include <config.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <ctype.h> | ||
26 | |||
27 | #include "g10lib.h" | ||
28 | |||
29 | |||
30 | #ifndef HAVE_STPCPY | ||
31 | char * | ||
32 | stpcpy(char *a,const char *b) | ||
33 | { | ||
34 | while( *b ) | ||
35 | *a++ = *b++; | ||
36 | *a = 0; | ||
37 | |||
38 | return (char*)a; | ||
39 | } | ||
40 | #endif | ||
41 | |||
42 | |||
43 | #ifndef HAVE_STRCASECMP | ||
44 | int | ||
45 | strcasecmp( const char *a, const char *b ) | ||
46 | { | ||
47 | for( ; *a && *b; a++, b++ ) { | ||
48 | if( *a != *b && toupper(*a) != toupper(*b) ) | ||
49 | break; | ||
50 | } | ||
51 | return *(const byte*)a - *(const byte*)b; | ||
52 | } | ||
53 | #endif | ||
54 | |||
55 | |||
56 | #ifdef __MINGW32__ | ||
57 | /* | ||
58 | * Like vsprintf but provides a pointer to malloc'd storage, which | ||
59 | * must be freed by the caller (gcry_free). Taken from libiberty as | ||
60 | * found in gcc-2.95.2 and a little bit modernized. | ||
61 | * FIXME: Write a new CRT for W32. | ||
62 | */ | ||
63 | int | ||
64 | vasprintf ( char **result, const char *format, va_list args) | ||
65 | { | ||
66 | const char *p = format; | ||
67 | /* Add one to make sure that it is never zero, which might cause malloc | ||
68 | to return NULL. */ | ||
69 | int total_width = strlen (format) + 1; | ||
70 | va_list ap; | ||
71 | |||
72 | /* this is not really portable but works under Windows */ | ||
73 | memcpy ( &ap, &args, sizeof (va_list)); | ||
74 | |||
75 | while (*p != '\0') | ||
76 | { | ||
77 | if (*p++ == '%') | ||
78 | { | ||
79 | while (strchr ("-+ #0", *p)) | ||
80 | ++p; | ||
81 | if (*p == '*') | ||
82 | { | ||
83 | ++p; | ||
84 | total_width += abs (va_arg (ap, int)); | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | char *endp; | ||
89 | total_width += strtoul (p, &endp, 10); | ||
90 | p = endp; | ||
91 | } | ||
92 | if (*p == '.') | ||
93 | { | ||
94 | ++p; | ||
95 | if (*p == '*') | ||
96 | { | ||
97 | ++p; | ||
98 | total_width += abs (va_arg (ap, int)); | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | char *endp; | ||
103 | total_width += strtoul (p, &endp, 10); | ||
104 | p = endp; | ||
105 | } | ||
106 | } | ||
107 | while (strchr ("hlL", *p)) | ||
108 | ++p; | ||
109 | /* Should be big enough for any format specifier except %s | ||
110 | and floats. */ | ||
111 | total_width += 30; | ||
112 | switch (*p) | ||
113 | { | ||
114 | case 'd': | ||
115 | case 'i': | ||
116 | case 'o': | ||
117 | case 'u': | ||
118 | case 'x': | ||
119 | case 'X': | ||
120 | case 'c': | ||
121 | (void) va_arg (ap, int); | ||
122 | break; | ||
123 | case 'f': | ||
124 | case 'e': | ||
125 | case 'E': | ||
126 | case 'g': | ||
127 | case 'G': | ||
128 | (void) va_arg (ap, double); | ||
129 | /* Since an ieee double can have an exponent of 307, we'll | ||
130 | make the buffer wide enough to cover the gross case. */ | ||
131 | total_width += 307; | ||
132 | |||
133 | case 's': | ||
134 | total_width += strlen (va_arg (ap, char *)); | ||
135 | break; | ||
136 | case 'p': | ||
137 | case 'n': | ||
138 | (void) va_arg (ap, char *); | ||
139 | break; | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | *result = gcry_malloc (total_width); | ||
144 | if (*result != NULL) | ||
145 | return vsprintf (*result, format, args); | ||
146 | else | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | #endif /*__MINGW32__*/ | ||
151 | |||