]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/string.c
Copyright update...
[thirdparty/cups.git] / cups / string.c
1 /*
2 * "$Id: string.c,v 1.6 2002/01/02 17:58:40 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 * Contents:
25 *
26 * strdup() - Duplicate a string.
27 * strcasecmp() - Do a case-insensitive comparison.
28 * strncasecmp() - Do a case-insensitive comparison on up to N chars.
29 */
30
31 /*
32 * Include necessary headers...
33 */
34
35 #include "string.h"
36
37
38 /*
39 * 'strdup()' - Duplicate a string.
40 */
41
42 # ifndef HAVE_STRDUP
43 char * /* O - New string pointer */
44 strdup(const char *s) /* I - String to duplicate */
45 {
46 char *t; /* New string pointer */
47
48
49 if (s == NULL)
50 return (NULL);
51
52 if ((t = malloc(strlen(s) + 1)) == NULL)
53 return (NULL);
54
55 return (strcpy(t, s));
56 }
57 # endif /* !HAVE_STRDUP */
58
59
60 /*
61 * 'strcasecmp()' - Do a case-insensitive comparison.
62 */
63
64 # ifndef HAVE_STRCASECMP
65 int /* O - Result of comparison (-1, 0, or 1) */
66 strcasecmp(const char *s, /* I - First string */
67 const char *t) /* I - Second string */
68 {
69 while (*s != '\0' && *t != '\0')
70 {
71 if (tolower(*s) < tolower(*t))
72 return (-1);
73 else if (tolower(*s) > tolower(*t))
74 return (1);
75
76 s ++;
77 t ++;
78 }
79
80 if (*s == '\0' && *t == '\0')
81 return (0);
82 else if (*s != '\0')
83 return (1);
84 else
85 return (-1);
86 }
87 # endif /* !HAVE_STRCASECMP */
88
89 /*
90 * 'strncasecmp()' - Do a case-insensitive comparison on up to N chars.
91 */
92
93 # ifndef HAVE_STRNCASECMP
94 int /* O - Result of comparison (-1, 0, or 1) */
95 strncasecmp(const char *s, /* I - First string */
96 const char *t, /* I - Second string */
97 size_t n) /* I - Maximum number of characters to compare */
98 {
99 while (*s != '\0' && *t != '\0' && n > 0)
100 {
101 if (tolower(*s) < tolower(*t))
102 return (-1);
103 else if (tolower(*s) > tolower(*t))
104 return (1);
105
106 s ++;
107 t ++;
108 n --;
109 }
110
111 if (n == 0)
112 return (0);
113 else if (*s == '\0' && *t == '\0')
114 return (0);
115 else if (*s != '\0')
116 return (1);
117 else
118 return (-1);
119 }
120 # endif /* !HAVE_STRNCASECMP */
121
122
123 /*
124 * End of "$Id: string.c,v 1.6 2002/01/02 17:58:40 mike Exp $".
125 */