]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/string.c
f60f83008b96c089d5ef5e7928af888573ffba66
[thirdparty/cups.git] / cups / string.c
1 /*
2 * "$Id: string.c,v 1.5.2.4 2002/05/09 02:22:09 mike Exp $"
3 *
4 * String functions for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2002 by Easy Software Products.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This file is subject to the Apple OS-Developed Software exception.
25 *
26 * Contents:
27 *
28 * ipp_strdup() - Duplicate a string.
29 * ipp_strcasecmp() - Do a case-insensitive comparison.
30 * ipp_strncasecmp() - Do a case-insensitive comparison on up to N chars.
31 */
32
33 /*
34 * Include necessary headers...
35 */
36
37 #include "string.h"
38
39
40 /*
41 * 'ipp_strdup()' - Duplicate a string.
42 */
43
44 # ifndef HAVE_STRDUP
45 char * /* O - New string pointer */
46 ipp_strdup(const char *s) /* I - String to duplicate */
47 {
48 char *t; /* New string pointer */
49
50
51 if (s == NULL)
52 return (NULL);
53
54 if ((t = malloc(strlen(s) + 1)) == NULL)
55 return (NULL);
56
57 return (strcpy(t, s));
58 }
59 # endif /* !HAVE_STRDUP */
60
61
62 /*
63 * 'ipp_strcasecmp()' - Do a case-insensitive comparison.
64 */
65
66 # ifndef HAVE_STRCASECMP
67 int /* O - Result of comparison (-1, 0, or 1) */
68 ipp_strcasecmp(const char *s, /* I - First string */
69 const char *t) /* I - Second string */
70 {
71 while (*s != '\0' && *t != '\0')
72 {
73 if (tolower(*s) < tolower(*t))
74 return (-1);
75 else if (tolower(*s) > tolower(*t))
76 return (1);
77
78 s ++;
79 t ++;
80 }
81
82 if (*s == '\0' && *t == '\0')
83 return (0);
84 else if (*s != '\0')
85 return (1);
86 else
87 return (-1);
88 }
89 # endif /* !HAVE_STRCASECMP */
90
91 /*
92 * 'ipp_strncasecmp()' - Do a case-insensitive comparison on up to N chars.
93 */
94
95 # ifndef HAVE_STRNCASECMP
96 int /* O - Result of comparison (-1, 0, or 1) */
97 ipp_strncasecmp(const char *s, /* I - First string */
98 const char *t, /* I - Second string */
99 size_t n) /* I - Maximum number of characters to compare */
100 {
101 while (*s != '\0' && *t != '\0' && n > 0)
102 {
103 if (tolower(*s) < tolower(*t))
104 return (-1);
105 else if (tolower(*s) > tolower(*t))
106 return (1);
107
108 s ++;
109 t ++;
110 n --;
111 }
112
113 if (n == 0)
114 return (0);
115 else if (*s == '\0' && *t == '\0')
116 return (0);
117 else if (*s != '\0')
118 return (1);
119 else
120 return (-1);
121 }
122 # endif /* !HAVE_STRNCASECMP */
123
124
125 /*
126 * End of "$Id: string.c,v 1.5.2.4 2002/05/09 02:22:09 mike Exp $".
127 */