OS_NS_string.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_NS_string.h
00006  *
00007  *  $Id: OS_NS_string.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  *  @author Jesper S. M|ller<stophph@diku.dk>
00011  *  @author and a cast of thousands...
00012  *
00013  *  Originally in OS.h.
00014  */
00015 //=============================================================================
00016 
00017 #ifndef ACE_OS_NS_STRING_H
00018 #define ACE_OS_NS_STRING_H
00019 
00020 # include /**/ "ace/pre.h"
00021 
00022 # include "ace/config-lite.h"
00023 
00024 # if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 #  pragma once
00026 # endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 #include "ace/Basic_Types.h" // to get ACE_WCHAR_T,
00029                             // should be in os_stddef.h or not used like this.
00030 #include /**/ "ace/ACE_export.h"
00031 
00032 #if defined (ACE_EXPORT_MACRO)
00033 #  undef ACE_EXPORT_MACRO
00034 #endif
00035 #define ACE_EXPORT_MACRO ACE_Export
00036 
00037 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00038 
00039 namespace ACE_OS {
00040 
00041   /** @name Functions from <cstring>
00042    *
00043    *  Included are the functions defined in <cstring> and their <cwchar>
00044    *  equivalents.
00045    *
00046    *  @todo To be complete, we should add strcoll, and strxfrm.
00047    */
00048   //@{
00049 
00050   /// Finds characters in a buffer (const void version).
00051   ACE_NAMESPACE_INLINE_FUNCTION
00052   const void *memchr (const void *s, int c, size_t len);
00053 
00054   /// Finds characters in a buffer (void version).
00055   ACE_NAMESPACE_INLINE_FUNCTION
00056   void *memchr (void *s, int c, size_t len);
00057 
00058 #if defined (ACE_LACKS_MEMCHR)
00059   /// Emulated memchr - Finds a character in a buffer.
00060   extern ACE_Export
00061   const void *memchr_emulation (const void *s, int c, size_t len);
00062 #endif /* ACE_LACKS_MEMCHR */
00063 
00064   /// Compares two buffers.
00065   ACE_NAMESPACE_INLINE_FUNCTION
00066   int memcmp (const void *t, const void *s, size_t len);
00067 
00068   /// Copies one buffer to another.
00069   ACE_NAMESPACE_INLINE_FUNCTION
00070   void *memcpy (void *t, const void *s, size_t len);
00071 
00072 #if defined (ACE_HAS_MEMCPY_LOOP_UNROLL)
00073 /*
00074  * Version of memcpy where the copy loop is unrolled.
00075  * On certain platforms this results in better performance.
00076  * This is determined and set via autoconf.
00077  */
00078   extern ACE_Export
00079   void *fast_memcpy (void *t, const void *s, size_t len);
00080 #endif
00081 
00082   /// Moves one buffer to another.
00083   ACE_NAMESPACE_INLINE_FUNCTION
00084   void *memmove (void *t, const void *s, size_t len);
00085 
00086   /// Fills a buffer with a character value.
00087   ACE_NAMESPACE_INLINE_FUNCTION
00088   void *memset (void *s, int c, size_t len);
00089 
00090   /// Appends a string to another string (char version).
00091   ACE_NAMESPACE_INLINE_FUNCTION
00092   char *strcat (char *s, const char *t);
00093 
00094 #if defined (ACE_HAS_WCHAR)
00095   /// Appends a string to another string (wchar_t version).
00096   ACE_NAMESPACE_INLINE_FUNCTION
00097   wchar_t *strcat (wchar_t *s, const wchar_t *t);
00098 #endif /* ACE_HAS_WCHAR */
00099 
00100   /// Finds the first occurance of a character in a string (const char
00101   /// version).
00102   ACE_NAMESPACE_INLINE_FUNCTION
00103   const char *strchr (const char *s, int c);
00104 
00105 #if defined (ACE_HAS_WCHAR)
00106   /// Finds the first occurance of a character in a string (const wchar_t
00107   /// version).
00108   ACE_NAMESPACE_INLINE_FUNCTION
00109   const wchar_t *strchr (const wchar_t *s, wchar_t c);
00110 #endif /* ACE_HAS_WCHAR */
00111 
00112   /// Finds the first occurance of a character in a string (char version).
00113   ACE_NAMESPACE_INLINE_FUNCTION
00114   char *strchr (char *s, int c);
00115 
00116 #if defined (ACE_HAS_WCHAR)
00117   /// Finds the first occurance of a character in a string (wchar_t version).
00118   ACE_NAMESPACE_INLINE_FUNCTION
00119   wchar_t *strchr (wchar_t *s, wchar_t c);
00120 #endif /* ACE_HAS_WCHAR */
00121 
00122   /// Compares two strings (char version).
00123   ACE_NAMESPACE_INLINE_FUNCTION
00124   int strcmp (const char *s, const char *t);
00125 
00126   /// Compares two strings (wchar_t version).
00127   ACE_NAMESPACE_INLINE_FUNCTION
00128   int strcmp (const ACE_WCHAR_T *s, const ACE_WCHAR_T *t);
00129 
00130   /// Copies a string (char version).
00131   ACE_NAMESPACE_INLINE_FUNCTION
00132   char *strcpy (char *s, const char *t);
00133 
00134 #if defined (ACE_HAS_WCHAR)
00135   /// Copies a string (wchar_t version).
00136   ACE_NAMESPACE_INLINE_FUNCTION
00137   wchar_t *strcpy (wchar_t *s, const wchar_t *t);
00138 #endif /* ACE_HAS_WCHAR */
00139 
00140   /// Searches for the first substring without any of the specified
00141   /// characters and returns the size of the substring (char version).
00142   ACE_NAMESPACE_INLINE_FUNCTION
00143   size_t strcspn (const char *s, const char *reject);
00144 
00145 #if defined (ACE_HAS_WCHAR)
00146   /// Searches for the first substring without any of the specified
00147   /// characters and returns the size of the substring (wchar_t version).
00148   ACE_NAMESPACE_INLINE_FUNCTION
00149   size_t strcspn (const wchar_t *s, const wchar_t *reject);
00150 #endif /* ACE_HAS_WCHAR */
00151 
00152   /// Returns a malloced duplicated string (char version).
00153   ACE_NAMESPACE_INLINE_FUNCTION
00154   char *strdup (const char *s);
00155 
00156 #if (defined (ACE_LACKS_STRDUP) && !defined(ACE_STRDUP_EQUIVALENT)) \
00157   || defined (ACE_HAS_STRDUP_EMULATION)
00158   extern ACE_Export
00159   char *strdup_emulation (const char *s);
00160 #endif
00161 
00162 #if defined (ACE_HAS_WCHAR)
00163   /// Returns a malloced duplicated string (wchar_t version).
00164   ACE_NAMESPACE_INLINE_FUNCTION
00165   wchar_t *strdup (const wchar_t *s);
00166 
00167 #if (defined (ACE_LACKS_WCSDUP) && !defined(ACE_WCSDUP_EQUIVALENT)) \
00168   || defined (ACE_HAS_WCSDUP_EMULATION)
00169   extern ACE_Export
00170   wchar_t *strdup_emulation (const wchar_t *s);
00171 #endif
00172 #endif /* ACE_HAS_WCHAR */
00173 
00174   /// Copies a string, but returns a pointer to the end of the
00175   /// copied region (char version).
00176   extern ACE_Export
00177   char *strecpy (char *des, const char *src);
00178 
00179 #if defined (ACE_HAS_WCHAR)
00180   /// Copies a string, but returns a pointer to the end of the
00181   /// copied region (wchar_t version).
00182   extern ACE_Export
00183   wchar_t *strecpy (wchar_t *s, const wchar_t *t);
00184 #endif /* ACE_HAS_WCHAR */
00185 
00186   /*
00187   ** Returns a system error message. If the supplied errnum is out of range,
00188   ** a string of the form "Unknown error %d" is used to format the string
00189   ** whose pointer is returned and errno is set to EINVAL.
00190   */
00191   extern ACE_Export
00192   char *strerror (int errnum);
00193 
00194 #if defined (ACE_LACKS_STRERROR)
00195   /// Emulated strerror - Returns a system error message.
00196   extern ACE_Export
00197   char *strerror_emulation (int errnum);
00198 #endif /* ACE_LACKS_STRERROR */
00199 
00200   /// Finds the length of a string (char version).
00201   ACE_NAMESPACE_INLINE_FUNCTION
00202   size_t strlen (const char *s);
00203 
00204   /// Finds the length of a string (ACE_WCHAR_T version).
00205   ACE_NAMESPACE_INLINE_FUNCTION
00206   size_t strlen (const ACE_WCHAR_T *s);
00207 
00208   /// Appends part of a string to another string (char version).
00209   ACE_NAMESPACE_INLINE_FUNCTION
00210   char *strncat (char *s, const char *t, size_t len);
00211 
00212   /// Appends part of a string to another string (wchar_t version).
00213   ACE_NAMESPACE_INLINE_FUNCTION
00214   ACE_WCHAR_T *strncat (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len);
00215 
00216   /// Finds the first occurance of a character in an array (const char
00217   /// version).
00218   extern ACE_Export
00219   const char *strnchr (const char *s, int c, size_t len);
00220 
00221   /// Finds the first occurance of a character in an array (const ACE_WCHAR_T
00222   /// version).
00223   extern ACE_Export
00224   const ACE_WCHAR_T *strnchr (const ACE_WCHAR_T *s, ACE_WCHAR_T c, size_t len);
00225 
00226   /// Finds the first occurance of a character in an array (char version).
00227   ACE_NAMESPACE_INLINE_FUNCTION
00228   char *strnchr (char *s, int c, size_t len);
00229 
00230   /// Finds the first occurance of a character in an array (ACE_WCHAR_T version).
00231   ACE_NAMESPACE_INLINE_FUNCTION
00232   ACE_WCHAR_T *strnchr (ACE_WCHAR_T *s, ACE_WCHAR_T c, size_t len);
00233 
00234   /// Compares two arrays (char version).
00235   ACE_NAMESPACE_INLINE_FUNCTION
00236   int strncmp (const char *s, const char *t, size_t len);
00237 
00238   /// Compares two arrays (wchar_t version).
00239   ACE_NAMESPACE_INLINE_FUNCTION
00240   int strncmp (const ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len);
00241 
00242   /// Copies an array (char version)
00243   ACE_NAMESPACE_INLINE_FUNCTION
00244   char *strncpy (char *s, const char *t, size_t len);
00245 
00246   /// Copies an array (ACE_WCHAR_T version)
00247   ACE_NAMESPACE_INLINE_FUNCTION
00248   ACE_WCHAR_T *strncpy (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len);
00249 
00250   /// Finds the length of a limited-length string (char version).
00251   /**
00252    * @param s       The character string to find the length of.
00253    * @param maxlen  The maximum number of characters that will be
00254    *                scanned for the terminating nul character.
00255    *
00256    * @return The length of @arg s, if the terminating nul character
00257    *         is located, else @arg maxlen.
00258    */
00259   ACE_NAMESPACE_INLINE_FUNCTION
00260   size_t strnlen (const char *s, size_t maxlen);
00261 
00262   /// Finds the length of a limited-length string (ACE_WCHAR_T version).
00263   /**
00264    * @param s       The character string to find the length of.
00265    * @param maxlen  The maximum number of characters that will be
00266    *                scanned for the terminating nul character.
00267    *
00268    * @return The length of @arg s, if the terminating nul character
00269    *         is located, else @arg maxlen.
00270    */
00271   ACE_NAMESPACE_INLINE_FUNCTION
00272   size_t strnlen (const ACE_WCHAR_T *s, size_t maxlen);
00273 
00274   /// Finds the first occurance of a substring in an array (const char
00275   /// version).
00276   extern ACE_Export
00277   const char *strnstr (const char *s, const char *t, size_t len);
00278 
00279   /// Finds the first occurance of a substring in an array (const wchar_t
00280   /// version).
00281   extern ACE_Export
00282   const ACE_WCHAR_T *strnstr (const ACE_WCHAR_T *s,
00283                               const ACE_WCHAR_T *t,
00284                               size_t len);
00285 
00286   /// Finds the first occurance of a substring in an array (char version).
00287   ACE_NAMESPACE_INLINE_FUNCTION
00288   char *strnstr (char *s, const char *t, size_t len);
00289 
00290   /// Finds the first occurance of a substring in an array (wchar_t version).
00291   ACE_NAMESPACE_INLINE_FUNCTION
00292   ACE_WCHAR_T *strnstr (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len);
00293 
00294   /// Searches for characters in a string (const char version).
00295   ACE_NAMESPACE_INLINE_FUNCTION
00296   const char *strpbrk (const char *s1, const char *s2);
00297 
00298 #if defined (ACE_HAS_WCHAR)
00299   /// Searches for characters in a string (const wchar_t version).
00300   ACE_NAMESPACE_INLINE_FUNCTION
00301   const wchar_t *strpbrk (const wchar_t *s1, const wchar_t *s2);
00302 #endif /* ACE_HAS_WCHAR */
00303 
00304   /// Searches for characters in a string (char version).
00305   ACE_NAMESPACE_INLINE_FUNCTION
00306   char *strpbrk (char *s1, const char *s2);
00307 
00308 #if defined (ACE_HAS_WCHAR)
00309   /// Searches for characters in a string (wchar_t version).
00310   ACE_NAMESPACE_INLINE_FUNCTION
00311   wchar_t *strpbrk (wchar_t *s1, const wchar_t *s2);
00312 #endif /* ACE_HAS_WCHAR */
00313 
00314   /// Finds the last occurance of a character in a string (const char
00315   /// version).
00316   ACE_NAMESPACE_INLINE_FUNCTION
00317   const char *strrchr (const char *s, int c);
00318 
00319 #if defined (ACE_HAS_WCHAR)
00320   /// Finds the last occurance of a character in a string (const wchar_t
00321   /// version).
00322   ACE_NAMESPACE_INLINE_FUNCTION
00323   const wchar_t *strrchr (const wchar_t *s, wchar_t c);
00324 #endif /* ACE_HAS_WCHAR */
00325 
00326   /// Finds the last occurance of a character in a string (char version).
00327   ACE_NAMESPACE_INLINE_FUNCTION
00328   char *strrchr (char *s, int c);
00329 
00330 #if defined (ACE_HAS_WCHAR)
00331   /// Finds the last occurance of a character in a string (wchar_t version).
00332   ACE_NAMESPACE_INLINE_FUNCTION
00333   wchar_t *strrchr (wchar_t *s, wchar_t c);
00334 #endif /* ACE_HAS_WCHAR */
00335 
00336 #if defined (ACE_LACKS_STRRCHR)
00337   /// Emulated strrchr (char version) - Finds the last occurance of a
00338   /// character in a string.
00339   extern ACE_Export
00340   char *strrchr_emulation (char *s, int c);
00341 
00342   /// Emulated strrchr (const char version) - Finds the last occurance of a
00343   /// character in a string.
00344   extern ACE_Export
00345   const char *strrchr_emulation (const char *s, int c);
00346 #endif /* ACE_LACKS_STRRCHR */
00347 
00348   /// This is a "safe" c string copy function (char version).
00349   /**
00350    * Unlike strncpy() this function will always add a terminating '\0'
00351    * char if maxlen > 0.  So the user doesn't has to provide an extra
00352    * '\0' if the user wants a '\0' terminated dst.  The function
00353    * doesn't check for a 0 @a dst, because this will give problems
00354    * anyway.  When @a src is 0 an empty string is made.  We do not
00355    * "touch" * @a dst if maxlen is 0.  Returns @a dst.  Care should be
00356    * taken when replacing strncpy() calls, because in some cases a
00357    * strncpy() user is using the "not '\0' terminating" feature from
00358    * strncpy().  This happens most when the call to strncpy() was
00359    * optimized by using a maxlen which is 1 smaller than the size
00360    * because there's always written a '\0' inside this last position.
00361    * Very seldom it's possible that the '\0' padding feature from
00362    * strncpy() is needed.
00363    */
00364   extern ACE_Export
00365   char *strsncpy (char *dst,
00366                   const char *src,
00367                   size_t maxlen);
00368 
00369   /// This is a "safe" c string copy function (wchar_t version).
00370   /**
00371    * Unlike strncpy() this function will always add a terminating '\0'
00372    * char if maxlen > 0.  So the user doesn't has to provide an extra
00373    * '\0' if the user wants a '\0' terminated dst.  The function
00374    * doesn't check for a 0 @a dst, because this will give problems
00375    * anyway.  When @a src is 0 an empty string is made.  We do not
00376    * "touch" * @a dst if maxlen is 0.  Returns @a dst.  Care should be
00377    * taken when replacing strncpy() calls, because in some cases a
00378    * strncpy() user is using the "not '\0' terminating" feature from
00379    * strncpy().  This happens most when the call to strncpy() was
00380    * optimized by using a maxlen which is 1 smaller than the size
00381    * because there's always written a '\0' inside this last position.
00382    * Very seldom it's possible that the '\0' padding feature from
00383    * strncpy() is needed.
00384    */
00385   extern ACE_Export
00386   ACE_WCHAR_T *strsncpy (ACE_WCHAR_T *dst,
00387                          const ACE_WCHAR_T *src,
00388                          size_t maxlen);
00389 
00390   /// Searches for the first substring containing only the specified
00391   /// characters and returns the size of the substring (char version).
00392   ACE_NAMESPACE_INLINE_FUNCTION
00393   size_t strspn (const char *s1, const char *s2);
00394 
00395 #if defined (ACE_HAS_WCHAR)
00396   /// Searches for the first substring containing only the specified
00397   /// characters and returns the size of the substring (wchar_t version).
00398   ACE_NAMESPACE_INLINE_FUNCTION
00399   size_t strspn (const wchar_t *s1, const wchar_t *s2);
00400 #endif /* ACE_HAS_WCHAR */
00401 
00402   /// Finds the first occurance of a substring in a string (const char
00403   /// version).
00404   ACE_NAMESPACE_INLINE_FUNCTION
00405   const char *strstr (const char *s, const char *t);
00406 
00407 #if defined (ACE_HAS_WCHAR)
00408   /// Finds the first occurance of a substring in a string (const wchar_t
00409   /// version).
00410   ACE_NAMESPACE_INLINE_FUNCTION
00411   const wchar_t *strstr (const wchar_t *s, const wchar_t *t);
00412 #endif /* ACE_HAS_WCHAR */
00413 
00414   /// Finds the first occurance of a substring in a string (char version).
00415   ACE_NAMESPACE_INLINE_FUNCTION
00416   char *strstr (char *s, const char *t);
00417 
00418 #if defined (ACE_HAS_WCHAR)
00419   /// Finds the first occurance of a substring in a string (wchar_t version).
00420   ACE_NAMESPACE_INLINE_FUNCTION
00421   wchar_t *strstr (wchar_t *s, const wchar_t *t);
00422 #endif /* ACE_HAS_WCHAR */
00423 
00424   /// Finds the next token in a string (char version).
00425   ACE_NAMESPACE_INLINE_FUNCTION
00426   char *strtok (char *s, const char *tokens);
00427 
00428 #if defined (ACE_HAS_WCHAR) && !defined (ACE_LACKS_WCSTOK)
00429   /// Finds the next token in a string (wchar_t version).
00430   ACE_NAMESPACE_INLINE_FUNCTION
00431   wchar_t *strtok (wchar_t *s, const wchar_t *tokens);
00432 #endif /* ACE_HAS_WCHAR && !ACE_LACKS_WCSTOK */
00433 
00434   //@}
00435 
00436   /// Finds the next token in a string (safe char version).
00437   ACE_NAMESPACE_INLINE_FUNCTION
00438   char *strtok_r (char *s, const char *tokens, char **lasts);
00439 
00440 #if defined (ACE_HAS_WCHAR)
00441   /// Finds the next token in a string (wchar_t version).
00442   ACE_NAMESPACE_INLINE_FUNCTION
00443   wchar_t *strtok_r (ACE_WCHAR_T *s, const ACE_WCHAR_T *tokens, ACE_WCHAR_T **lasts);
00444 #endif  // ACE_HAS_WCHAR
00445 
00446 #if !defined (ACE_HAS_REENTRANT_FUNCTIONS) || defined (ACE_LACKS_STRTOK_R)
00447   /// Emulated strtok_r.
00448   extern ACE_Export
00449   char *strtok_r_emulation (char *s, const char *tokens, char **lasts);
00450 #endif /* !ACE_HAS_REENTRANT_FUNCTIONS */
00451 
00452 # if defined (ACE_HAS_WCHAR) && defined(ACE_LACKS_WCSTOK)
00453   /// Emulated strtok_r (wchar_t version).
00454   extern ACE_Export
00455   wchar_t *strtok_r_emulation (ACE_WCHAR_T *s, const ACE_WCHAR_T *tokens, ACE_WCHAR_T **lasts);
00456 # endif  // ACE_HAS_WCHAR && ACE_LACKS_WCSTOK
00457 
00458 } /* namespace ACE_OS */
00459 
00460 ACE_END_VERSIONED_NAMESPACE_DECL
00461 
00462 # if defined (ACE_HAS_INLINED_OSCALLS)
00463 #   if defined (ACE_INLINE)
00464 #     undef ACE_INLINE
00465 #   endif /* ACE_INLINE */
00466 #   define ACE_INLINE inline
00467 #   include "ace/OS_NS_string.inl"
00468 # endif /* ACE_HAS_INLINED_OSCALLS */
00469 
00470 # include /**/ "ace/post.h"
00471 #endif /* ACE_OS_NS_STRING_H */

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