Back to index

lightning-sunbird  0.9+nobinonly
strings.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code, released
00015  * March 31, 1998.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 /*
00038  * Copyright (c) 1987 Regents of the University of California.
00039  * All rights reserved.  The Berkeley software License Agreement
00040  * specifies the terms and conditions for redistribution.
00041  */
00042 /*
00043  * This array is designed for mapping upper and lower case letter
00044  * together for a case independent comparison.  The mappings are
00045  * based upon ascii character sequences.
00046  */
00047 /*
00048  * strings.c
00049  */
00050 #include <string.h>
00051 #include <stdlib.h>
00052 #include "ldap-macos.h"
00053 
00054 
00055 #ifndef NO_GLOBALS
00056 static char charmap[] = {
00057        '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
00058        '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
00059        '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
00060        '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
00061        '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
00062        '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
00063        '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
00064        '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
00065        '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
00066        '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
00067        '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
00068        '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
00069        '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
00070        '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
00071        '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
00072        '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
00073        '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
00074        '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
00075        '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
00076        '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
00077        '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
00078        '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
00079        '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
00080        '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
00081        '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
00082        '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
00083        '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
00084        '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
00085        '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
00086        '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
00087        '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
00088        '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
00089 };
00090 
00091 #ifndef MOZILLA_CLIENT
00092 /* This is a duplicate of one we already have */
00093 int
00094 strcasecmp(const char *s1, const char *s2)
00095 {
00096        register char *cm = charmap;
00097 
00098        while (cm[*s1] == cm[*s2++])
00099               if (*s1++ == '\0')
00100                      return(0);
00101        return cm[*s1] - cm[*--s2];
00102 }
00103 #endif
00104 
00105 int
00106 strncasecmp(const char *s1, const char *s2, const long n)
00107 {
00108        register char *cm = charmap;
00109        register long remain = n;
00110        
00111        while (--remain >= 0 && cm[*s1] == cm[*s2++])
00112               if (*s1++ == '\0')
00113                      return(0);
00114        return remain < 0 ? 0 : cm[*s1] - cm[*--s2];
00115 }
00116 #endif NO_GLOBALS
00117 
00118 
00119 #ifndef MOZILLA_CLIENT
00120 /* This is a duplicate of one we already have */
00121 char *
00122 strdup( const char *p )
00123 {
00124        char   *r;
00125 
00126        r = (char *) malloc( strlen( p ) + 1 );
00127        if ( r != NULL ) {
00128               strcpy( r, p );
00129        }
00130 
00131        return( r );
00132 }
00133 #endif