diff options
author | Steve Huston <shuston@riverace.com> | 2002-04-10 22:19:46 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2002-04-10 22:19:46 +0000 |
commit | d7e27b10827ae3be5c96dae717078bcadd247bbb (patch) | |
tree | 459f2a974e7fbdeadb1a1fdea51a09563c6e3c21 /ace | |
parent | e9482da7874b9c1e894995db9a10cacc0a4952aa (diff) | |
download | ATCD-d7e27b10827ae3be5c96dae717078bcadd247bbb.tar.gz |
ChangeLogTag:Wed Apr 10 17:38:31 2002 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/OS_String.h | 22 | ||||
-rw-r--r-- | ace/OS_String.inl | 28 | ||||
-rw-r--r-- | ace/README | 2 | ||||
-rw-r--r-- | ace/config-linux-common.h | 6 |
4 files changed, 58 insertions, 0 deletions
diff --git a/ace/OS_String.h b/ace/OS_String.h index 4a6e671c566..14da8b81b42 100644 --- a/ace/OS_String.h +++ b/ace/OS_String.h @@ -129,6 +129,28 @@ public: /// Finds the length of a string (ACE_WCHAR_T version). static size_t strlen (const ACE_WCHAR_T *s); + /// Finds the length of a limited-length string (char version). + /** + * @param s The character string to find the length of. + * @param maxlen The maximum number of characters that will be + * scanned for the terminating nul character. + * + * @return The length of @arg s, if the terminating nul character + * is located, else @arg maxlen. + */ + static size_t strnlen (const char *s, size_t maxlen); + + /// Finds the length of a limited-length string (ACE_WCHAR_T version). + /** + * @param s The character string to find the length of. + * @param maxlen The maximum number of characters that will be + * scanned for the terminating nul character. + * + * @return The length of @arg s, if the terminating nul character + * is located, else @arg maxlen. + */ + static size_t strnlen (const ACE_WCHAR_T *s, size_t maxlen); + /// Appends part of a string to another string (char version). static char *strncat (char *s, const char *t, size_t len); diff --git a/ace/OS_String.inl b/ace/OS_String.inl index bd01298edb5..e67dba97448 100644 --- a/ace/OS_String.inl +++ b/ace/OS_String.inl @@ -262,6 +262,34 @@ ACE_OS_String::strlen (const ACE_WCHAR_T *s) # endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */ } +ACE_INLINE size_t +ACE_OS_String::strnlen (const char *s, size_t maxlen) +{ +#if defined (ACE_HAS_STRNLEN) + return ::strnlen (s, maxlen); +#else /* ACE_HAS_STRNLEN */ + size_t i; + for (i = 0; i < maxlen; ++i) + if (s[i] == '\0') + break; + return i; +#endif /* ACE_HAS_STRNLEN */ +} + +ACE_INLINE size_t +ACE_OS_String::strnlen (const ACE_WCHAR_T *s, size_t maxlen) +{ +#if defined (ACE_HAS_WCSNLEN) + return wcsnlen (s, maxlen); +#else /* ACE_HAS_WCSNLEN */ + size_t i; + for (i = 0; i < maxlen; ++i) + if (s[i] == '\0') + break; + return i; +#endif /* ACE_HAS_WCSNLEN */ +} + ACE_INLINE char * ACE_OS_String::strncat (char *s, const char *t, size_t len) { diff --git a/ace/README b/ace/README index 30efa905aae..9f0bed0d2ed 100644 --- a/ace/README +++ b/ace/README @@ -527,6 +527,7 @@ ACE_HAS_STRBUF_T Compiler/platform supports ACE_HAS_STRDUP_EMULATION Platform/compiler lacks strdup() (e.g., VxWorks, Chorus, WinCE) +ACE_HAS_STRNLEN Platform supports strnlen(3). ACE_HAS_STREAMS Platform supports STREAMS ACE_HAS_STREAM_PIPES Platform supports STREAM pipes ACE_HAS_STRERROR Compiler/platform supports strerror () @@ -636,6 +637,7 @@ ACE_HAS_VOIDPTR_MMAP Platform requires void * for ACE_HAS_VOIDPTR_SOCKOPT OS/compiler uses void * arg 4 setsockopt() rather than const char * +ACE_HAS_WCSNLEN Platform supports wcsnlen(3). ACE_HAS_WIN32_TRYLOCK The Win32 platform support TryEnterCriticalSection() (WinNT 4.0 and beyond) diff --git a/ace/config-linux-common.h b/ace/config-linux-common.h index 341bf3f7fa5..448191af928 100644 --- a/ace/config-linux-common.h +++ b/ace/config-linux-common.h @@ -52,6 +52,12 @@ # define ACE_HAS_SOCKLEN_T # define ACE_HAS_4_4BSD_SENDMSG_RECVMSG + // glibc defines both of these, used in OS_String. +# if defined (_GNU_SOURCE) +# define ACE_HAS_STRNLEN +# define ACE_HAS_WCSNLEN +# endif + // To avoid the strangeness with Linux's ::select (), which modifies // its timeout argument, use ::poll () instead. # define ACE_HAS_POLL |