~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201207201942

« back to all changes in this revision

Viewing changes to modules/solaris/vmhgfs/str.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-03-20 10:19:00 UTC
  • mfrom: (1.1.4 upstream) (2.4.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090320101900-1o604camiubq2de8
Tags: 2009.03.18-154848-2
Correcting patch system depends (Closes: #520493).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 1998 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * The contents of this file are subject to the terms of the Common
 
5
 * Development and Distribution License (the "License") version 1.0
 
6
 * and no later version.  You may not use this file except in
 
7
 * compliance with the License.
 
8
 *
 
9
 * You can obtain a copy of the License at
 
10
 *         http://www.opensource.org/licenses/cddl1.php
 
11
 *
 
12
 * See the License for the specific language governing permissions
 
13
 * and limitations under the License.
 
14
 *
 
15
 *********************************************************/
 
16
 
 
17
/*
 
18
 * str.h --
 
19
 *
 
20
 *    string wrapping functions
 
21
 */
 
22
 
 
23
#ifndef _STR_H_
 
24
#define _STR_H_
 
25
 
 
26
#define INCLUDE_ALLOW_MODULE
 
27
#define INCLUDE_ALLOW_USERLEVEL
 
28
#define INCLUDE_ALLOW_VMCORE
 
29
#include "includeCheck.h"
 
30
 
 
31
#if defined(GLIBC_VERSION_22)
 
32
#include <wchar.h>
 
33
#elif defined(_WIN32)
 
34
#include <tchar.h>
 
35
#elif __APPLE__
 
36
#include <stdlib.h>
 
37
#endif
 
38
#include "compat/compat_stdarg.h" // Provides stdarg.h plus va_copy
 
39
 
 
40
#include "vm_basic_types.h"
 
41
 
 
42
 
 
43
/*
 
44
 * These platforms use bsd_vsnprintf().
 
45
 * This does not mean it has bsd_vsnwprintf().
 
46
 */
 
47
#if defined _WIN32 && !defined STR_NO_WIN32_LIBS || \
 
48
    defined __linux__ && !defined N_PLAT_NLM || defined __APPLE__
 
49
#define HAS_BSD_PRINTF 1
 
50
#endif
 
51
 
 
52
/*
 
53
 * And these platforms/setups use bsd_vsnwprintf()
 
54
 */
 
55
#if (defined _WIN32 && !defined STR_NO_WIN32_LIBS) || \
 
56
   (defined __GNUC__ && (__GNUC__ < 2                 \
 
57
                         || (__GNUC__ == 2            \
 
58
                             && __GNUC_MINOR__ < 96)))
 
59
#define HAS_BSD_WPRINTF 1
 
60
#endif
 
61
 
 
62
/*
 
63
 * ASCII/UTF-8 versions
 
64
 *
 
65
 * NOTE: All size_t arguments and integer returns values are in bytes.
 
66
 *
 
67
 * NOTE: Str_Asprintf/Str_Vasprintf return NULL on failure, while
 
68
 * Str_SafeAsprintf/Str_SafeVasprintf ASSERT_NOT_IMPLEMENTED.
 
69
 *
 
70
 * NOTE: "%s" refers to strings of "char" units, while "%S" refers to
 
71
 * strings of "wchar_t" units, regardless of platform.
 
72
 */
 
73
 
 
74
EXTERN int Str_Sprintf(char *buf, size_t max,
 
75
                       const char *fmt, ...) PRINTF_DECL(3, 4);
 
76
EXTERN int Str_Snprintf(char *buf, size_t len,
 
77
                        const char *fmt, ...) PRINTF_DECL(3, 4);
 
78
EXTERN int Str_Vsnprintf(char *buf, size_t len,
 
79
                         const char *fmt, va_list args);
 
80
EXTERN size_t Str_Strlen(const char *src, size_t maxLen);
 
81
EXTERN char *Str_Strnstr(const char *src, const char *sub, size_t n);
 
82
EXTERN char *Str_Strcpy(char *dst, const char *src, size_t maxLen);
 
83
EXTERN char *Str_Strcat(char *dst, const char *src, size_t maxLen);
 
84
EXTERN char *Str_Strncat(char *buf, size_t bufSize, const char *src, size_t n);
 
85
 
 
86
EXTERN char *Str_Asprintf(size_t *length,
 
87
                          const char *format, ...) PRINTF_DECL(2, 3);
 
88
EXTERN char *Str_Vasprintf(size_t *length, const char *format,
 
89
                           va_list arguments);
 
90
EXTERN char *Str_SafeAsprintf(size_t *length,
 
91
                              const char *format, ...) PRINTF_DECL(2, 3);
 
92
EXTERN char *Str_SafeVasprintf(size_t *length, const char *format,
 
93
                               va_list arguments);
 
94
 
 
95
#if defined(_WIN32) || defined(GLIBC_VERSION_22) // {
 
96
 
 
97
/*
 
98
 * wchar_t versions
 
99
 *
 
100
 * NOTE: All size_t arguments and integer return values are in
 
101
 * wchar_ts, not bytes.
 
102
 *
 
103
 * NOTE: Str_Aswprintf/Str_Vaswprintf return NULL on failure, while
 
104
 * Str_SafeAswprintf/Str_SafeVaswprintf ASSERT_NOT_IMPLEMENTED.
 
105
 *
 
106
 * NOTE: "%s" refers to strings of "char" units, while "%S" refers to
 
107
 * strings of "wchar_t" units, regardless of platform.
 
108
 */
 
109
 
 
110
EXTERN int Str_Swprintf(wchar_t *buf, size_t max,
 
111
                        const wchar_t *fmt, ...);
 
112
EXTERN int Str_Snwprintf(wchar_t *buf, size_t len,
 
113
                         const wchar_t *fmt, ...);
 
114
EXTERN int Str_Vsnwprintf(wchar_t *buf, size_t len,
 
115
                          const wchar_t *fmt, va_list args);
 
116
EXTERN wchar_t *Str_Wcscpy(wchar_t *dst, const wchar_t *src, size_t maxLen);
 
117
EXTERN wchar_t *Str_Wcscat(wchar_t *dst, const wchar_t *src, size_t maxLen);
 
118
EXTERN wchar_t *Str_Wcsncat(wchar_t *buf, size_t bufSize, const wchar_t *src,
 
119
                            size_t n);
 
120
 
 
121
EXTERN wchar_t *Str_Aswprintf(size_t *length,
 
122
                              const wchar_t *format, ...);
 
123
EXTERN wchar_t *Str_Vaswprintf(size_t *length, const wchar_t *format,
 
124
                               va_list arguments);
 
125
EXTERN wchar_t *Str_SafeAswprintf(size_t *length,
 
126
                                  const wchar_t *format, ...);
 
127
EXTERN wchar_t *Str_SafeVaswprintf(size_t *length, const wchar_t *format,
 
128
                                   va_list arguments);
 
129
 
 
130
unsigned char *Str_Mbscpy(char *buf, const char *src,
 
131
                          size_t maxSize);
 
132
unsigned char *Str_Mbscat(char *buf, const char *src,
 
133
                          size_t maxSize);
 
134
 
 
135
/*
 
136
 * These are handly for Windows programmers.  They are like
 
137
 * the _tcs functions, but with Str_Strcpy-style bounds checking.
 
138
 *
 
139
 * We don't have Str_Mbsncat() because it has some odd semantic
 
140
 * ambiguity (whether to truncate in the middle of a multibyte
 
141
 * sequence) that I want to stay away from.  -- edward
 
142
 */
 
143
 
 
144
#ifdef _WIN32
 
145
#ifdef UNICODE
 
146
   #define Str_Tcscpy(s1, s2, n) Str_Wcscpy(s1, s2, n)
 
147
   #define Str_Tcscat(s1, s2, n) Str_Wcscat(s1, s2, n)
 
148
#else
 
149
   #define Str_Tcscpy(s1, s2, n) Str_Mbscpy(s1, s2, n)
 
150
   #define Str_Tcscat(s1, s2, n) Str_Mbscat(s1, s2, n)
 
151
#endif
 
152
#endif
 
153
 
 
154
#endif // } defined(_WIN32) || defined(GLIBC_VERSION_22)
 
155
 
 
156
 
 
157
/*
 
158
 * Wrappers for standard string functions
 
159
 *
 
160
 * These are either for Windows-Posix compatibility,
 
161
 * or just gratuitous wrapping for consistency.
 
162
 */
 
163
 
 
164
#define Str_Strcmp(s1, s2) strcmp(s1, s2)
 
165
#define Str_Strncmp(s1, s2, n) strncmp(s1, s2, n)
 
166
 
 
167
#define Str_Strchr(s, c) strchr(s, c)
 
168
#define Str_Strrchr(s, c) strrchr(s, c)
 
169
#define Str_Strspn(s1, s2) strspn(s1, s2)
 
170
#define Str_Strcspn(s1, s2) strcspn(s1, s2)
 
171
 
 
172
#if defined(_WIN32)
 
173
   #define Str_Strcasecmp(s1, s2) _stricmp(s1, s2)
 
174
   #define Str_Strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
 
175
   #define Str_ToUpper(s) _strupr(s)
 
176
   #define Str_ToLower(s) _strlwr(s)
 
177
#elif defined(N_PLAT_NLM)
 
178
   #define Str_Strcasecmp(s1, s2) stricmp(s1, s2)
 
179
   #define Str_Strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
 
180
   char *Str_ToUpper(char *string);
 
181
   char *Str_ToLower(char *string);
 
182
#else
 
183
   #define Str_Strcasecmp(s1, s2) strcasecmp(s1, s2)
 
184
   #define Str_Strncasecmp(s1, s2, n) strncasecmp(s1, s2, n)
 
185
   char *Str_ToUpper(char *string);
 
186
   char *Str_ToLower(char *string);
 
187
#endif
 
188
 
 
189
#ifdef _WIN32
 
190
   #define Str_Tcscmp(s1, s2) _tcscmp(s1, s2)
 
191
   #define Str_Tcsncmp(s1, s2, n) _tcsncmp(s1, s2, n)
 
192
   #define Str_Tcsicmp(s1, s2) _tcsicmp(s1, s2)
 
193
   #define Str_Tcsnicmp(s1, s2, n) _tcsnicmp(s1, s2, n)
 
194
   #define Str_Tcschr(s, c) _tcschr(s, c)
 
195
   #define Str_Tcsrchr(s, c) _tcsrchr(s, c)
 
196
   #define Str_Tcsspn(s1, s2) _tcsspn(s1, s2)
 
197
   #define Str_Tcscspn(s1, s2) _tcscspn(s1, s2)
 
198
   #define Str_Tcsupr(s) _tcsupr(s)
 
199
   #define Str_Tcslwr(s) _tcslwr(s)
 
200
#endif
 
201
 
 
202
#endif /* _STR_H_ */