/*
- * "$Id: string.c 7460 2008-04-16 02:19:54Z mike $"
+ * "$Id$"
*
- * String functions for CUPS.
+ * String functions for CUPS.
*
- * Copyright 2007-2010 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * _cupsStrAlloc() - Allocate/reference a string.
- * _cupsStrFlush() - Flush the string pool.
- * _cupsStrFormatd() - Format a floating-point number.
- * _cupsStrFree() - Free/dereference a string.
- * _cupsStrRetain() - Increment the reference count of a string.
- * _cupsStrScand() - Scan a string for a floating-point number.
- * _cupsStrStatistics() - Return allocation statistics for string pool.
- * _cups_strcpy() - Copy a string allowing for overlapping strings.
- * _cups_strdup() - Duplicate a string.
- * _cups_strcasecmp() - Do a case-insensitive comparison.
- * _cups_strncasecmp() - Do a case-insensitive comparison on up to N chars.
- * _cups_strlcat() - Safely concatenate two strings.
- * _cups_strlcpy() - Safely copy two strings.
- * compare_sp_items() - Compare two string pool items...
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
char * /* O - String pointer */
_cupsStrAlloc(const char *s) /* I - String */
{
+ size_t slen; /* Length of string */
_cups_sp_item_t *item, /* String pool item */
*key; /* Search key */
* Not found, so allocate a new one...
*/
- item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t) + strlen(s));
+ slen = strlen(s);
+ item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t) + slen);
if (!item)
{
_cupsMutexUnlock(&sp_mutex);
}
item->ref_count = 1;
- strcpy(item->str, s);
+ memcpy(item->str, s, slen + 1);
#ifdef DEBUG_GUARDS
item->guard = _CUPS_STR_GUARD;
}
else
{
- strlcpy(buf, temp, bufend - buf + 1);
+ strlcpy(buf, temp, (size_t)(bufend - buf + 1));
bufptr = buf + strlen(buf);
}
if (loc && loc->decimal_point)
{
- strlcpy(tempptr, loc->decimal_point, sizeof(temp) - (tempptr - temp));
+ strlcpy(tempptr, loc->decimal_point, sizeof(temp) - (size_t)(tempptr - temp));
tempptr += strlen(tempptr);
}
else if (tempptr < (temp + sizeof(temp) - 1))
*/
count += item->ref_count;
- len = (strlen(item->str) + 8) & ~7;
+ len = (strlen(item->str) + 8) & (size_t)~7;
abytes += sizeof(_cups_sp_item_t) + len;
tbytes += item->ref_count * len;
}
void
_cups_strcpy(char *dst, /* I - Destination string */
- const char *src) /* I - Source string */
+ const char *src) /* I - Source string */
{
while (*src)
*dst++ = *src++;
char * /* O - New string pointer */
_cups_strdup(const char *s) /* I - String to duplicate */
{
- char *t; /* New string pointer */
+ char *t; /* New string pointer */
+ size_t slen; /* Length of string */
- if (s == NULL)
+ if (!s)
return (NULL);
- if ((t = malloc(strlen(s) + 1)) == NULL)
+ slen = strlen(s);
+ if ((t = malloc(slen + 1)) == NULL)
return (NULL);
- return (strcpy(t, s));
+ return (memcpy(t, s, slen + 1));
}
#endif /* !HAVE_STRDUP */
* '_cups_strcasecmp()' - Do a case-insensitive comparison.
*/
-#ifndef HAVE_STRCASECMP
int /* O - Result of comparison (-1, 0, or 1) */
_cups_strcasecmp(const char *s, /* I - First string */
- const char *t) /* I - Second string */
+ const char *t) /* I - Second string */
{
while (*s != '\0' && *t != '\0')
{
- if (tolower(*s & 255) < tolower(*t & 255))
+ if (_cups_tolower(*s) < _cups_tolower(*t))
return (-1);
- else if (tolower(*s & 255) > tolower(*t & 255))
+ else if (_cups_tolower(*s) > _cups_tolower(*t))
return (1);
s ++;
else
return (-1);
}
-#endif /* !HAVE_STRCASECMP */
/*
* '_cups_strncasecmp()' - Do a case-insensitive comparison on up to N chars.
*/
-#ifndef HAVE_STRNCASECMP
int /* O - Result of comparison (-1, 0, or 1) */
_cups_strncasecmp(const char *s, /* I - First string */
const char *t, /* I - Second string */
{
while (*s != '\0' && *t != '\0' && n > 0)
{
- if (tolower(*s & 255) < tolower(*t & 255))
+ if (_cups_tolower(*s) < _cups_tolower(*t))
return (-1);
- else if (tolower(*s & 255) > tolower(*t & 255))
+ else if (_cups_tolower(*s) > _cups_tolower(*t))
return (1);
s ++;
else
return (-1);
}
-#endif /* !HAVE_STRNCASECMP */
#ifndef HAVE_STRLCAT
if (srclen > size)
srclen = size;
- memcpy(dst + dstlen, src, srclen);
+ memmove(dst + dstlen, src, srclen);
dst[dstlen + srclen] = '\0';
return (dstlen + srclen);
if (srclen > size)
srclen = size;
- memcpy(dst, src, srclen);
+ memmove(dst, src, srclen);
dst[srclen] = '\0';
return (srclen);
/*
- * End of "$Id: string.c 7460 2008-04-16 02:19:54Z mike $".
+ * End of "$Id$".
*/