* information regarding copyright ownership.
*/
-/* $Id: string.h,v 1.23 2007/09/13 04:48:16 each Exp $ */
-
-#ifndef ISC_STRING_H
-#define ISC_STRING_H 1
+#pragma once
/*! \file isc/string.h */
-#include <isc/formatcheck.h>
-#include <isc/int.h>
-#include <isc/lang.h>
-#include <isc/platform.h>
-#include <isc/types.h>
-
#include <string.h>
-#ifdef ISC_PLATFORM_HAVESTRINGSH
-#include <strings.h>
-#endif
-
-#define ISC_STRING_MAGIC 0x5e
+#include "isc/platform.h"
+#include "isc/lang.h"
ISC_LANG_BEGINDECLS
-#ifdef ISC_PLATFORM_NEEDMEMMOVE
-#define memmove(a,b,c) bcopy(b,a,c)
-#endif
-
size_t
isc_string_strlcpy(char *dst, const char *src, size_t size);
-
#ifdef ISC_PLATFORM_NEEDSTRLCPY
#define strlcpy isc_string_strlcpy
#endif
-
size_t
isc_string_strlcat(char *dst, const char *src, size_t size);
#define strlcat isc_string_strlcat
#endif
-char *
-isc_string_strcasestr(const char *big, const char *little);
-
-#ifdef ISC_PLATFORM_NEEDSTRCASESTR
-#define strcasestr isc_string_strcasestr
-#endif
-
ISC_LANG_ENDDECLS
-
-#endif /* ISC_STRING_H */
/*! \file */
-#include <config.h>
+#include <config.h> // IWYU pragma: keep
-#include <ctype.h>
+#include <string.h>
-#include <isc/mem.h>
-#include <isc/print.h>
-#include <isc/region.h>
-#include <isc/string.h>
-#include <isc/util.h>
+#include "isc/string.h" // IWYU pragma: keep
size_t
isc_string_strlcpy(char *dst, const char *src, size_t size)
/* Copy as many bytes as will fit */
if (n != 0U && --n != 0U) {
do {
- if ((*d++ = *s++) == 0)
+ if ((*d++ = *s++) == 0) {
break;
+ }
} while (--n != 0U);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0U) {
- if (size != 0U)
+ if (size != 0U) {
*d = '\0'; /* NUL-terminate dst */
+ }
while (*s++)
;
}
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
- while (n-- != 0U && *d != '\0')
+ while (n-- != 0U && *d != '\0') {
d++;
+ }
dlen = d - dst;
n = size - dlen;
- if (n == 0U)
+ if (n == 0U) {
return(dlen + strlen(s));
+ }
while (*s != '\0') {
if (n != 1U) {
*d++ = *s;
return(dlen + (s - src)); /* count does not include NUL */
}
-
-char *
-isc_string_strcasestr(const char *str, const char *search) {
- char c, sc, *s;
- size_t len;
-
- if ((c = *search++) != 0) {
- c = tolower((unsigned char) c);
- len = strlen(search);
- do {
- do {
- if ((sc = *str++) == 0)
- return (NULL);
- } while ((char) tolower((unsigned char) sc) != c);
- } while (strncasecmp(str, search, len) != 0);
- str--;
- }
- DE_CONST(str, s);
- return (s);
-
-}