]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/string.c
2 * "$Id: string.c 4683 2005-09-21 22:17:44Z mike $"
4 * String functions for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * _cups_strcpy() - Copy a string allowing for overlapping strings.
29 * _cups_strdup() - Duplicate a string.
30 * _cups_strcasecmp() - Do a case-insensitive comparison.
31 * _cups_strncasecmp() - Do a case-insensitive comparison on up to N chars.
32 * _cups_strlcat() - Safely concatenate two strings.
33 * _cups_strlcpy() - Safely copy two strings.
37 * Include necessary headers...
44 * '_cups_strcpy()' - Copy a string allowing for overlapping strings.
48 _cups_strcpy(char *dst
, /* I - Destination string */
49 const char *src
) /* I - Source string */
59 * '_cups_strdup()' - Duplicate a string.
63 char * /* O - New string pointer */
64 _cups_strdup(const char *s
) /* I - String to duplicate */
66 char *t
; /* New string pointer */
72 if ((t
= malloc(strlen(s
) + 1)) == NULL
)
75 return (strcpy(t
, s
));
77 #endif /* !HAVE_STRDUP */
81 * '_cups_strcasecmp()' - Do a case-insensitive comparison.
84 #ifndef HAVE_STRCASECMP
85 int /* O - Result of comparison (-1, 0, or 1) */
86 _cups_strcasecmp(const char *s
, /* I - First string */
87 const char *t
) /* I - Second string */
89 while (*s
!= '\0' && *t
!= '\0')
91 if (tolower(*s
& 255) < tolower(*t
& 255))
93 else if (tolower(*s
& 255) > tolower(*t
& 255))
100 if (*s
== '\0' && *t
== '\0')
107 #endif /* !HAVE_STRCASECMP */
110 * '_cups_strncasecmp()' - Do a case-insensitive comparison on up to N chars.
113 #ifndef HAVE_STRNCASECMP
114 int /* O - Result of comparison (-1, 0, or 1) */
115 _cups_strncasecmp(const char *s
, /* I - First string */
116 vconst
char *t
, /* I - Second string */
117 size_t n
) /* I - Maximum number of characters to compare */
119 while (*s
!= '\0' && *t
!= '\0' && n
> 0)
121 if (tolower(*s
& 255) < tolower(*t
& 255))
123 else if (tolower(*s
& 255) > tolower(*t
& 255))
133 else if (*s
== '\0' && *t
== '\0')
140 #endif /* !HAVE_STRNCASECMP */
145 * '_cups_strlcat()' - Safely concatenate two strings.
148 size_t /* O - Length of string */
149 _cups_strlcat(char *dst
, /* O - Destination string */
150 const char *src
, /* I - Source string */
151 size_t size
) /* I - Size of destination string buffer */
153 size_t srclen
; /* Length of source string */
154 size_t dstlen
; /* Length of destination string */
158 * Figure out how much room is left...
161 dstlen
= strlen(dst
);
165 return (dstlen
); /* No room, return immediately... */
168 * Figure out how much room is needed...
171 srclen
= strlen(src
);
174 * Copy the appropriate amount...
180 memcpy(dst
+ dstlen
, src
, srclen
);
181 dst
[dstlen
+ srclen
] = '\0';
183 return (dstlen
+ srclen
);
185 #endif /* !HAVE_STRLCAT */
190 * '_cups_strlcpy()' - Safely copy two strings.
193 size_t /* O - Length of string */
194 _cups_strlcpy(char *dst
, /* O - Destination string */
195 const char *src
, /* I - Source string */
196 size_t size
) /* I - Size of destination string buffer */
198 size_t srclen
; /* Length of source string */
202 * Figure out how much room is needed...
207 srclen
= strlen(src
);
210 * Copy the appropriate amount...
216 memcpy(dst
, src
, srclen
);
221 #endif /* !HAVE_STRLCPY */
225 * End of "$Id: string.c 4683 2005-09-21 22:17:44Z mike $".