]>
Commit | Line | Data |
---|---|---|
3b960317 | 1 | /* |
aa7e125a | 2 | * "$Id: string.c,v 1.5.2.5 2002/05/15 01:57:01 mike Exp $" |
3b960317 | 3 | * |
4 | * String functions for the Common UNIX Printing System (CUPS). | |
5 | * | |
839c43aa | 6 | * Copyright 1997-2002 by Easy Software Products. |
3b960317 | 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 | |
8784b6a6 | 17 | * 44141 Airport View Drive, Suite 204 |
3b960317 | 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 | * | |
dab1a4d8 | 24 | * This file is subject to the Apple OS-Developed Software exception. |
25 | * | |
3b960317 | 26 | * Contents: |
27 | * | |
aa7e125a | 28 | * cups_strdup() - Duplicate a string. |
29 | * cups_strcasecmp() - Do a case-insensitive comparison. | |
30 | * cups_strncasecmp() - Do a case-insensitive comparison on up to N chars. | |
3b960317 | 31 | */ |
32 | ||
33 | /* | |
34 | * Include necessary headers... | |
35 | */ | |
36 | ||
37 | #include "string.h" | |
38 | ||
39 | ||
40 | /* | |
aa7e125a | 41 | * 'cups_strdup()' - Duplicate a string. |
3b960317 | 42 | */ |
43 | ||
44 | # ifndef HAVE_STRDUP | |
a87857fe | 45 | char * /* O - New string pointer */ |
aa7e125a | 46 | cups_strdup(const char *s) /* I - String to duplicate */ |
3b960317 | 47 | { |
a87857fe | 48 | char *t; /* New string pointer */ |
3b960317 | 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 | /* | |
aa7e125a | 63 | * 'cups_strcasecmp()' - Do a case-insensitive comparison. |
3b960317 | 64 | */ |
65 | ||
66 | # ifndef HAVE_STRCASECMP | |
67 | int /* O - Result of comparison (-1, 0, or 1) */ | |
aa7e125a | 68 | cups_strcasecmp(const char *s, /* I - First string */ |
a87857fe | 69 | const char *t) /* I - Second string */ |
3b960317 | 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 ++; | |
e8fda7b9 | 80 | } |
3b960317 | 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 | /* | |
aa7e125a | 92 | * 'cups_strncasecmp()' - Do a case-insensitive comparison on up to N chars. |
3b960317 | 93 | */ |
94 | ||
95 | # ifndef HAVE_STRNCASECMP | |
96 | int /* O - Result of comparison (-1, 0, or 1) */ | |
aa7e125a | 97 | cups_strncasecmp(const char *s, /* I - First string */ |
a87857fe | 98 | const char *t, /* I - Second string */ |
99 | size_t n) /* I - Maximum number of characters to compare */ | |
3b960317 | 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 --; | |
e8fda7b9 | 111 | } |
3b960317 | 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 | /* | |
aa7e125a | 126 | * End of "$Id: string.c,v 1.5.2.5 2002/05/15 01:57:01 mike Exp $". |
3b960317 | 127 | */ |