summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2011-02-04 09:16:11 +0000
committerVincent Torri <vincent.torri@gmail.com>2011-02-04 09:16:11 +0000
commit56940cdb32a6338ed5beb1d723ca1b5d4a5944e3 (patch)
treea2293979c69deeea7d7bbce4c03e5b43c7514e2d /legacy
parent6dbbb69012c1e0eea077b547328e7746212267ae (diff)
* src/lib/evil_stdio.c:
* src/lib/evil_stdio.h: Add asprintf() function. Add documentation for vasprintf(). Use _vcprintf() instead of vsnprintf() to get the length of the string, as recommended by MSDN. SVN revision: 56705
Diffstat (limited to 'legacy')
-rw-r--r--legacy/evil/ChangeLog9
-rw-r--r--legacy/evil/src/lib/evil_stdio.c22
-rw-r--r--legacy/evil/src/lib/evil_stdio.h45
3 files changed, 68 insertions, 8 deletions
diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog
index 67470568e4..c1f9fe0143 100644
--- a/legacy/evil/ChangeLog
+++ b/legacy/evil/ChangeLog
@@ -1,3 +1,12 @@
12011-02-04 Vincent Torri <doursse at users dot sf dot net>
2
3 * src/lib/evil_stdio.c:
4 * src/lib/evil_stdio.h:
5 Add asprintf() function.
6 Add documentation for vasprintf().
7 Use _vcprintf() instead of vsnprintf() to get the length
8 of the string, as recommended by MSDN.
9
12011-01-06 Vincent Torri <doursse at users dot sf dot net> 102011-01-06 Vincent Torri <doursse at users dot sf dot net>
2 11
3 * src/lib/evil_stdio.c: 12 * src/lib/evil_stdio.c:
diff --git a/legacy/evil/src/lib/evil_stdio.c b/legacy/evil/src/lib/evil_stdio.c
index 1fa4922ed6..cf44367709 100644
--- a/legacy/evil/src/lib/evil_stdio.c
+++ b/legacy/evil/src/lib/evil_stdio.c
@@ -214,20 +214,32 @@ int evil_fclose_native(FILE *stream)
214 214
215#endif /* _WIN32_WCE */ 215#endif /* _WIN32_WCE */
216 216
217#ifdef _WIN32
218
219int 217int
220vasprintf(char **strp, const char *fmt, va_list ap) 218vasprintf(char **strp, const char *fmt, va_list ap)
221{ 219{
222 char *res; 220 char *res;
223 int len; 221 int len;
224 222
225 len = _vsnprintf(NULL, 0, fmt, ap) + 1; 223 len = _vscprintf(fmt, ap) + 1;
226 res = (char *)malloc(len); 224 res = (char *)malloc(len);
227 if (!res) return -1; 225 if (!res) return -1;
228 226
229 *strp = res; 227 *strp = res;
230 return vsprintf(res, fmt, ap); 228 len = vsprintf(res, fmt, ap);
229 if (len < 0) len = -1;
230
231 return len;
231} 232}
232 233
233#endif /* _WIN32 */ 234int
235asprintf(char **strp, const char *fmt, ...)
236{
237 va_list ap;
238 int res;
239
240 va_start(ap, fmt);
241 res = vasprintf(strp, fmt, ap);
242 va_end(ap);
243
244 return res;
245}
diff --git a/legacy/evil/src/lib/evil_stdio.h b/legacy/evil/src/lib/evil_stdio.h
index 7d40c1047c..fa6846fed1 100644
--- a/legacy/evil/src/lib/evil_stdio.h
+++ b/legacy/evil/src/lib/evil_stdio.h
@@ -54,11 +54,50 @@ EAPI int evil_fclose_native(FILE *stream);
54 54
55#endif /* _WIN32_WCE */ 55#endif /* _WIN32_WCE */
56 56
57#ifdef _WIN32 57/**
58 58 * @brief Print allocated string using a va_list.
59 *
60 * @param strp The returned pointer of the allocated string.
61 * @param fmt The format string.
62 * @param ap The variable argument list.
63 * @return -1 on failure, the length of the printed string.
64 *
65 * This function allocates a buffer large enough to hold the output
66 * including the terminating null byte, and return a pointer to it
67 * into @p strp. The format @p fmt is the same than the one used with
68 * printf(). When not needed anymore, the pointer returned in @p strp
69 * must be freed. On error (memory allocation failure or other error),
70 * this function returns -1 and the content of @p strp is undefined,
71 * otherwise it returns the length of the string (not including the
72 * terminating null byte).
73 *
74 * Conformity: GNU extension.
75 *
76 * Supported OS: Windows XP, CE.
77 */
59EAPI int vasprintf(char **strp, const char *fmt, va_list ap); 78EAPI int vasprintf(char **strp, const char *fmt, va_list ap);
60 79
61#endif /* _WIN32 */ 80/**
81 * @brief Print allocated string using a variable number of arguments.
82 *
83 * @param strp The returned pointer of the allocated string.
84 * @param fmt The format string.
85 * @return -1 on failure, the length of the printed string.
86 *
87 * This function allocates a buffer large enough to hold the output
88 * including the terminating null byte, and return a pointer to it
89 * into @p strp. The format @p fmt is the same than the one used with
90 * printf(). When not needed anymore, the pointer returned in @p strp
91 * must be freed. On error (memory allocation failure or other error),
92 * this function returns -1 and the content of @p strp is undefined,
93 * otherwise it returns the length of the string (not including the
94 * terminating null byte).
95 *
96 * Conformity: GNU extension.
97 *
98 * Supported OS: Windows XP, CE.
99 */
100EAPI int asprintf(char **strp, const char *fmt, ...);
62 101
63 102
64/** 103/**