1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Platform independent functions for string manipulation.
32 * @author Jose Fonseca <jfonseca@vmware.com>
38 #if !defined(XF86_LIBC_H)
46 #include "util/macros.h" // PRINTFLIKE
53 #if !defined(_GNU_SOURCE) || defined(__APPLE__)
55 #define strchrnul util_strchrnul
57 util_strchrnul(const char *s
, char c
)
59 for (; *s
&& *s
!= c
; ++s
);
68 #define sprintf util_sprintf
71 util_sprintf(char *str
, const char *format
, ...)
75 vsnprintf(str
, (size_t)-1, format
, ap
);
79 #define vasprintf util_vasprintf
81 util_vasprintf(char **ret
, const char *format
, va_list ap
)
85 /* Compute length of output string first */
87 int r
= vsnprintf(NULL
, 0, format
, ap_copy
);
93 *ret
= (char *) malloc(r
+ 1);
98 return vsnprintf(*ret
, r
+ 1, format
, ap
);
101 #define asprintf util_asprintf
103 util_asprintf(char **str
, const char *fmt
, ...)
108 ret
= vasprintf(str
, fmt
, args
);
114 #define strcasecmp stricmp
117 #define strdup _strdup
119 #if defined(_WIN32) && !defined(HAVE_STRTOK_R)
120 #define strtok_r strtok_s
130 #endif /* U_STRING_H_ */