OS_NS_string.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: OS_NS_string.inl 80826 2008-03-04 14:51:23Z wotte $
00004 
00005 // OS_NS_wchar.h is only needed to get the emulation methods.
00006 // Perhaps they should be moved.  dhinton
00007 #include "ace/OS_NS_wchar.h"
00008 #include "ace/os_include/os_string.h"
00009 
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011 
00012 ACE_INLINE const void *
00013 ACE_OS::memchr (const void *s, int c, size_t len)
00014 {
00015 #if !defined (ACE_LACKS_MEMCHR)
00016   return ::memchr (s, c, len);
00017 #else /* ACE_LACKS_MEMCHR */
00018   return ACE_OS::memchr_emulation (s, c, len);
00019 #endif /* !ACE_LACKS_MEMCHR */
00020 }
00021 
00022 ACE_INLINE void *
00023 ACE_OS::memchr (void *s, int c, size_t len)
00024 {
00025   return const_cast<void *> (ACE_OS::memchr (static_cast<const void *> (s),
00026                                              c,
00027                                              len));
00028 }
00029 
00030 ACE_INLINE int
00031 ACE_OS::memcmp (const void *t, const void *s, size_t len)
00032 {
00033   return ::memcmp (t, s, len);
00034 }
00035 
00036 ACE_INLINE void *
00037 ACE_OS::memcpy (void *t, const void *s, size_t len)
00038 {
00039 #if defined (ACE_HAS_MEMCPY_LOOP_UNROLL)
00040   return fast_memcpy (t, s, len);
00041 #else
00042   return ::memcpy (t, s, len);
00043 #endif /* ACE_HAS_MEMCPY_LOOP_UNROLL */
00044 }
00045 
00046 ACE_INLINE void *
00047 ACE_OS::memmove (void *t, const void *s, size_t len)
00048 {
00049   return ::memmove (t, s, len);
00050 }
00051 
00052 ACE_INLINE void *
00053 ACE_OS::memset (void *s, int c, size_t len)
00054 {
00055 #if defined (ACE_HAS_SLOW_MEMSET)
00056   // This section requires a high optimization level (-xO4 with SunCC)
00057   // in order to actually be inlined.
00058   char* ptr = static_cast<char*> (s);
00059   switch (len)
00060     {
00061     case 16:
00062       ptr[15] = c;
00063     case 15:
00064       ptr[14] = c;
00065     case 14:
00066       ptr[13] = c;
00067     case 13:
00068       ptr[12] = c;
00069     case 12:
00070       ptr[11] = c;
00071     case 11:
00072       ptr[10] = c;
00073     case 10:
00074       ptr[9] = c;
00075     case 9:
00076       ptr[8] = c;
00077     case 8:
00078       ptr[7] = c;
00079     case 7:
00080       ptr[6] = c;
00081     case 6:
00082       ptr[5] = c;
00083     case 5:
00084       ptr[4] = c;
00085     case 4:
00086       ptr[3] = c;
00087     case 3:
00088       ptr[2] = c;
00089     case 2:
00090       ptr[1] = c;
00091     case 1:
00092       ptr[0] = c;
00093       break;
00094     default:
00095       for (size_t i = 0; i < len; ++i)
00096         {
00097           ptr[i] = c;
00098         }
00099     }
00100 
00101   return s;
00102 #else
00103   return ::memset (s, c, len);
00104 #endif /* ACE_HAS_SLOW_MEMSET */
00105 }
00106 
00107 ACE_INLINE char *
00108 ACE_OS::strcat (char *s, const char *t)
00109 {
00110   return ::strcat (s, t);
00111 }
00112 
00113 #if defined (ACE_HAS_WCHAR)
00114 ACE_INLINE wchar_t *
00115 ACE_OS::strcat (wchar_t *s, const wchar_t *t)
00116 {
00117 #  if defined (ACE_LACKS_WCSCAT)
00118   return ACE_OS::wcscat_emulation (s, t);
00119 #  else /* ACE_LACKS_WCSCAT */
00120   return ::wcscat (s, t);
00121 #  endif /* ACE_LACKS_WCSCAT */
00122 }
00123 #endif /* ACE_HAS_WCHAR */
00124 
00125 ACE_INLINE const char *
00126 ACE_OS::strchr (const char *s, int c)
00127 {
00128   return const_cast <const char *> (::strchr (s, c));
00129 }
00130 
00131 #if defined (ACE_HAS_WCHAR)
00132 ACE_INLINE const wchar_t *
00133 ACE_OS::strchr (const wchar_t *s, wchar_t c)
00134 {
00135 #  if defined (ACE_LACKS_WCSCHR)
00136   return ACE_OS::wcschr_emulation (s, c);
00137 #  else /* ACE_LACKS_WCSCHR */
00138   return ::wcschr (s, c);
00139 #  endif /* ACE_LACKS_WCSCHR */
00140 }
00141 #endif /* ACE_HAS_WCHAR */
00142 
00143 ACE_INLINE char *
00144 ACE_OS::strchr (char *s, int c)
00145 {
00146   return ::strchr (s, c);
00147 }
00148 
00149 #if defined (ACE_HAS_WCHAR)
00150 ACE_INLINE wchar_t *
00151 ACE_OS::strchr (wchar_t *s, wchar_t c)
00152 {
00153   return
00154     const_cast<wchar_t *> (ACE_OS::strchr (const_cast<const wchar_t *> (s),
00155                                            c));
00156 }
00157 #endif /* ACE_HAS_WCHAR */
00158 
00159 ACE_INLINE int
00160 ACE_OS::strcmp (const char *s, const char *t)
00161 {
00162   return ::strcmp (s, t);
00163 }
00164 
00165 ACE_INLINE int
00166 ACE_OS::strcmp (const ACE_WCHAR_T *s, const ACE_WCHAR_T *t)
00167 {
00168 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSCMP)
00169   return ACE_OS::wcscmp_emulation (s, t);
00170 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCMP */
00171   return ::wcscmp (s, t);
00172 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCMP */
00173 }
00174 
00175 ACE_INLINE char *
00176 ACE_OS::strcpy (char *s, const char *t)
00177 {
00178   return ::strcpy (s, t);
00179 }
00180 
00181 #if defined (ACE_HAS_WCHAR)
00182 ACE_INLINE wchar_t *
00183 ACE_OS::strcpy (wchar_t *s, const wchar_t *t)
00184 {
00185 #  if defined (ACE_LACKS_WCSCPY)
00186   return ACE_OS::wcscpy_emulation (s, t);
00187 #  else /* ACE_LACKS_WCSCPY */
00188   return ::wcscpy (s, t);
00189 #  endif /* ACE_LACKS_WCSCPY */
00190 }
00191 #endif /* ACE_HAS_WCHAR */
00192 
00193 ACE_INLINE size_t
00194 ACE_OS::strcspn (const char *s, const char *reject)
00195 {
00196   return ::strcspn (s, reject);
00197 }
00198 
00199 #if defined (ACE_HAS_WCHAR)
00200 ACE_INLINE size_t
00201 ACE_OS::strcspn (const wchar_t *s, const wchar_t *reject)
00202 {
00203 #  if defined (ACE_LACKS_WCSCSPN)
00204   return ACE_OS::wcscspn_emulation (s, reject);
00205 #  else /* ACE_LACKS_WCSCSPN */
00206   return ::wcscspn (s, reject);
00207 #  endif /* ACE_LACKS_WCSCSPN */
00208 }
00209 #endif /* ACE_HAS_WCHAR */
00210 
00211 ACE_INLINE char *
00212 ACE_OS::strdup (const char *s)
00213 {
00214 #  if (defined (ACE_LACKS_STRDUP) && !defined(ACE_STRDUP_EQUIVALENT)) \
00215   || defined (ACE_HAS_STRDUP_EMULATION)
00216   return ACE_OS::strdup_emulation (s);
00217 #  elif defined (ACE_STRDUP_EQUIVALENT)
00218   return ACE_STRDUP_EQUIVALENT (s);
00219 #  elif defined (ACE_HAS_NONCONST_STRDUP)
00220   return ::strdup (const_cast<char *> (s));
00221 #else
00222   return ::strdup (s);
00223 #  endif /* (ACE_LACKS_STRDUP && !ACE_STRDUP_EQUIVALENT) || ... */
00224 }
00225 
00226 #if defined (ACE_HAS_WCHAR)
00227 ACE_INLINE wchar_t *
00228 ACE_OS::strdup (const wchar_t *s)
00229 {
00230 #  if (defined (ACE_LACKS_WCSDUP) && !defined (ACE_WCSDUP_EQUIVALENT)) \
00231   || defined (ACE_HAS_WCSDUMP_EMULATION)
00232   return ACE_OS::strdup_emulation (s);
00233 #  elif defined (ACE_WCSDUP_EQUIVALENT)
00234   return ACE_WCSDUP_EQUIVALENT (s);
00235 #  elif defined (ACE_HAS_NONCONST_WCSDUP)
00236   return ::wcsdup (const_cast<wchar_t*> (s));
00237 #  else
00238   return ::wcsdup (s);
00239 #  endif /* (ACE_LACKS_WCSDUP && !ACE_WCSDUP_EQUIVALENT) || ... */
00240 }
00241 #endif /* ACE_HAS_WCHAR */
00242 
00243 ACE_INLINE size_t
00244 ACE_OS::strlen (const char *s)
00245 {
00246   return ::strlen (s);
00247 }
00248 
00249 ACE_INLINE size_t
00250 ACE_OS::strlen (const ACE_WCHAR_T *s)
00251 {
00252 # if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSLEN)
00253   return ACE_OS::wcslen_emulation (s);
00254 # else  /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
00255   return ::wcslen (s);
00256 # endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
00257 }
00258 
00259 ACE_INLINE char *
00260 ACE_OS::strncat (char *s, const char *t, size_t len)
00261 {
00262 #if 0 /* defined (ACE_HAS_TR24731_2005_CRT) */
00263   strncat_s (s, len + 1, t, _TRUNCATE);
00264   return s;
00265 #else
00266   return ::strncat (s, t, len);
00267 #endif /* ACE_HAS_TR24731_2005_CRT */
00268 }
00269 
00270 ACE_INLINE ACE_WCHAR_T *
00271 ACE_OS::strncat (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
00272 {
00273 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCAT)
00274   return ACE_OS::wcsncat_emulation (s, t, len);
00275 #  elif 0 /* defined (ACE_HAS_TR24731_2005_CRT) */
00276   wcsncat_s (s, len + 1, t, _TRUNCATE);
00277   return s;
00278 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCAT */
00279   return ::wcsncat (s, t, len);
00280 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCAT */
00281 }
00282 
00283 ACE_INLINE char *
00284 ACE_OS::strnchr (char *s, int c, size_t len)
00285 {
00286   return const_cast<char *> (ACE_OS::strnchr (static_cast<const char *> (s),
00287                                               c,
00288                                               len));
00289 }
00290 
00291 ACE_INLINE ACE_WCHAR_T *
00292 ACE_OS::strnchr (ACE_WCHAR_T *s, ACE_WCHAR_T c, size_t len)
00293 {
00294   return
00295     const_cast<ACE_WCHAR_T *> (ACE_OS::strnchr (
00296                                  const_cast<const ACE_WCHAR_T *> (s),
00297                                  c,
00298                                  len));
00299 }
00300 
00301 ACE_INLINE int
00302 ACE_OS::strncmp (const char *s, const char *t, size_t len)
00303 {
00304   return ::strncmp (s, t, len);
00305 }
00306 
00307 ACE_INLINE int
00308 ACE_OS::strncmp (const ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
00309 {
00310 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCMP)
00311   return ACE_OS::wcsncmp_emulation (s, t, len);
00312 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
00313   return ::wcsncmp (s, t, len);
00314 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
00315 }
00316 
00317 ACE_INLINE char *
00318 ACE_OS::strncpy (char *s, const char *t, size_t len)
00319 {
00320   return ::strncpy (s, t, len);
00321 }
00322 
00323 ACE_INLINE ACE_WCHAR_T *
00324 ACE_OS::strncpy (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
00325 {
00326 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCPY)
00327   return ACE_OS::wcsncpy_emulation (s, t, len);
00328 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCPY */
00329   return ::wcsncpy (s, t, len);
00330 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCPY */
00331 }
00332 
00333 ACE_INLINE size_t
00334 ACE_OS::strnlen (const char *s, size_t maxlen)
00335 {
00336 #if defined (ACE_HAS_STRNLEN)
00337   return ::strnlen (s, maxlen);
00338 #else /* ACE_HAS_STRNLEN */
00339   size_t i;
00340   for (i = 0; i < maxlen; ++i)
00341     if (s[i] == '\0')
00342       break;
00343   return i;
00344 #endif /* ACE_HAS_STRNLEN */
00345 }
00346 
00347 ACE_INLINE size_t
00348 ACE_OS::strnlen (const ACE_WCHAR_T *s, size_t maxlen)
00349 {
00350 #if defined (ACE_HAS_WCHAR) && defined (ACE_HAS_WCSNLEN)
00351   return wcsnlen (s, maxlen);
00352 #else /* ACE_HAS_WCSNLEN */
00353   size_t i;
00354   for (i = 0; i < maxlen; ++i)
00355     if (s[i] == '\0')
00356       break;
00357   return i;
00358 #endif /* ACE_HAS_WCSNLEN */
00359 }
00360 
00361 ACE_INLINE char *
00362 ACE_OS::strnstr (char *s, const char *t, size_t len)
00363 {
00364   return
00365     const_cast <char *> (ACE_OS::strnstr (const_cast <const char *> (s), t, len));
00366 }
00367 
00368 ACE_INLINE ACE_WCHAR_T *
00369 ACE_OS::strnstr (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
00370 {
00371   return
00372     const_cast<ACE_WCHAR_T *> (ACE_OS::strnstr (
00373                                  static_cast<const ACE_WCHAR_T *> (s),
00374                                  t,
00375                                  len));
00376 }
00377 
00378 ACE_INLINE const char *
00379 ACE_OS::strpbrk (const char *s1, const char *s2)
00380 {
00381   return const_cast <const char *> (::strpbrk (s1, s2));
00382 }
00383 
00384 #if defined (ACE_HAS_WCHAR)
00385 ACE_INLINE const wchar_t *
00386 ACE_OS::strpbrk (const wchar_t *s, const wchar_t *t)
00387 {
00388 #  if defined (ACE_LACKS_WCSPBRK)
00389   return ACE_OS::wcspbrk_emulation (s, t);
00390 #  else /* ACE_LACKS_WCSPBRK */
00391   return ::wcspbrk (s, t);
00392 #  endif /* ACE_LACKS_WCSPBRK */
00393 }
00394 #endif /* ACE_HAS_WCHAR */
00395 
00396 ACE_INLINE char *
00397 ACE_OS::strpbrk (char *s1, const char *s2)
00398 {
00399   return ::strpbrk (s1, s2);
00400 }
00401 
00402 #if defined (ACE_HAS_WCHAR)
00403 ACE_INLINE wchar_t *
00404 ACE_OS::strpbrk (wchar_t *s, const wchar_t *t)
00405 {
00406   return const_cast<wchar_t *> (ACE_OS::strpbrk (
00407                                   const_cast<const wchar_t *> (s), t));
00408 }
00409 #endif /* ACE_HAS_WCHAR */
00410 
00411 ACE_INLINE const char *
00412 ACE_OS::strrchr (const char *s, int c)
00413 {
00414 #if defined (ACE_LACKS_STRRCHR)
00415   return ACE_OS::strrchr_emulation (s, c);
00416 #else  /* ! ACE_LACKS_STRRCHR */
00417   return (const char *) ::strrchr (s, c);
00418 #endif /* ! ACE_LACKS_STRRCHR */
00419 }
00420 
00421 #if defined (ACE_HAS_WCHAR)
00422 ACE_INLINE const wchar_t *
00423 ACE_OS::strrchr (const wchar_t *s, wchar_t c)
00424 {
00425 #if defined (ACE_LACKS_WCSRCHR)
00426   return ACE_OS::wcsrchr_emulation (s, c);
00427 #else /* ! ACE_LACKS_WCSRCHR */
00428   return const_cast <const wchar_t *> (::wcsrchr (s, c));
00429 #endif /* ! ACE_LACKS_WCSRCHR */
00430 }
00431 #endif /* ACE_HAS_WCHAR */
00432 
00433 ACE_INLINE char *
00434 ACE_OS::strrchr (char *s, int c)
00435 {
00436 #if defined (ACE_LACKS_STRRCHR)
00437   return ACE_OS::strrchr_emulation (s, c);
00438 #else  /* ! ACE_LACKS_STRRCHR */
00439   return ::strrchr (s, c);
00440 #endif /* ! ACE_LACKS_STRRCHR */
00441 }
00442 
00443 #if defined (ACE_HAS_WCHAR)
00444 ACE_INLINE wchar_t *
00445 ACE_OS::strrchr (wchar_t *s, wchar_t c)
00446 {
00447   return const_cast<wchar_t *> (ACE_OS::strrchr (
00448                      const_cast<const wchar_t *> (s), c));
00449 }
00450 #endif /* ACE_HAS_WCHAR */
00451 
00452 ACE_INLINE size_t
00453 ACE_OS::strspn (const char *s, const char *t)
00454 {
00455   return ::strspn (s, t);
00456 }
00457 
00458 #if defined (ACE_HAS_WCHAR)
00459 ACE_INLINE size_t
00460 ACE_OS::strspn (const wchar_t *s, const wchar_t *t)
00461 {
00462 #  if defined (ACE_LACKS_WCSSPN)
00463   return ACE_OS::wcsspn_emulation (s, t);
00464 #  else /* ACE_LACKS_WCSSPN */
00465   return ::wcsspn (s, t);
00466 #  endif /* ACE_LACKS_WCSSPN */
00467 }
00468 #endif /* ACE_HAS_WCHAR */
00469 
00470 ACE_INLINE const char *
00471 ACE_OS::strstr (const char *s, const char *t)
00472 {
00473   return (const char *) ::strstr (s, t);
00474 }
00475 
00476 #if defined (ACE_HAS_WCHAR)
00477 ACE_INLINE const wchar_t *
00478 ACE_OS::strstr (const wchar_t *s, const wchar_t *t)
00479 {
00480 #  if defined (ACE_LACKS_WCSSTR)
00481   return ACE_OS::wcsstr_emulation (s, t);
00482 #  elif defined (HPUX)
00483   return const_cast <const wchar_t *> (::wcswcs (s, t));
00484 #  else /* ACE_LACKS_WCSSTR */
00485   return const_cast <const wchar_t *> (::wcsstr (s, t));
00486 #  endif /* ACE_LACKS_WCSSTR */
00487 }
00488 #endif /* ACE_HAS_WCHAR */
00489 
00490 ACE_INLINE char *
00491 ACE_OS::strstr (char *s, const char *t)
00492 {
00493   return ::strstr (s, t);
00494 }
00495 
00496 #if defined (ACE_HAS_WCHAR)
00497 ACE_INLINE wchar_t *
00498 ACE_OS::strstr (wchar_t *s, const wchar_t *t)
00499 {
00500 #  if defined (ACE_LACKS_WCSSTR)
00501   return ACE_OS::wcsstr_emulation (s, t);
00502 #  elif defined (HPUX)
00503   return ::wcswcs (s, t);
00504 #  else /* ACE_LACKS_WCSSTR */
00505   return ::wcsstr (s, t);
00506 #  endif /* ACE_LACKS_WCSSTR */
00507 }
00508 #endif /* ACE_HAS_WCHAR */
00509 
00510 ACE_INLINE char *
00511 ACE_OS::strtok (char *s, const char *tokens)
00512 {
00513   return ::strtok (s, tokens);
00514 }
00515 
00516 #if defined (ACE_HAS_WCHAR) && !defined (ACE_LACKS_WCSTOK)
00517 ACE_INLINE wchar_t *
00518 ACE_OS::strtok (wchar_t *s, const wchar_t *tokens)
00519 {
00520 #if defined (ACE_HAS_3_PARAM_WCSTOK)
00521   static wchar_t *lasts = 0;
00522   return ::wcstok (s, tokens, &lasts);
00523 #else
00524   return ::wcstok (s, tokens);
00525 #endif /* ACE_HAS_3_PARAM_WCSTOK */
00526 }
00527 #endif /* ACE_HAS_WCHAR && !ACE_LACKS_WCSTOK */
00528 
00529 ACE_INLINE char *
00530 ACE_OS::strtok_r (char *s, const char *tokens, char **lasts)
00531 {
00532 #if defined (ACE_HAS_TR24731_2005_CRT)
00533   return strtok_s (s, tokens, lasts);
00534 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (ACE_LACKS_STRTOK_R)
00535   return ::strtok_r (s, tokens, lasts);
00536 #else
00537   return ACE_OS::strtok_r_emulation (s, tokens, lasts);
00538 #endif /* (ACE_HAS_REENTRANT_FUNCTIONS) */
00539 }
00540 
00541 #if defined (ACE_HAS_WCHAR)
00542 ACE_INLINE wchar_t*
00543 ACE_OS::strtok_r (ACE_WCHAR_T *s, const ACE_WCHAR_T *tokens, ACE_WCHAR_T **lasts)
00544 {
00545 #if defined (ACE_HAS_TR24731_2005_CRT)
00546   return wcstok_s (s, tokens, lasts);
00547 #elif defined (ACE_LACKS_WCSTOK)
00548   return ACE_OS::strtok_r_emulation (s, tokens, lasts);
00549 #else
00550 #  if defined (ACE_HAS_3_PARAM_WCSTOK)
00551   return ::wcstok (s, tokens, lasts);
00552 #  else /* ACE_HAS_3_PARAM_WCSTOK */
00553   *lasts = ::wcstok (s, tokens);
00554   return *lasts;
00555 #  endif /* ACE_HAS_3_PARAM_WCSTOK */
00556 #endif  /* ACE_LACKS_WCSTOK */
00557 }
00558 #endif  // ACE_HAS_WCHAR
00559 
00560 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:41 2010 for ACE by  doxygen 1.4.7