117680Spst/*
217680Spst * Copyright (c) 1987 Regents of the University of California.
317680Spst * All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms are permitted
617680Spst * provided that this notice is preserved and that due credit is given
717680Spst * to the University of California at Berkeley. The name of the University
817680Spst * may not be used to endorse or promote products derived from this
917680Spst * software without specific written prior permission. This software
1017680Spst * is provided ``as is'' without express or implied warranty.
1117680Spst */
1217680Spst
1356893Sfenner#ifdef HAVE_CONFIG_H
1456893Sfenner#include "config.h"
1556893Sfenner#endif
1617680Spst
1775115Sfenner#ifndef lint
18127668Sbmsstatic const char rcsid[] _U_ =
19190207Srpaulo     "@(#) $Header: /tcpdump/master/tcpdump/strcasecmp.c,v 1.6 2003-11-16 09:36:43 guy Exp $";
2075115Sfenner#endif
2175115Sfenner
22127668Sbms#include <tcpdump-stdinc.h>
2317680Spst
2417680Spst#include "interface.h"
2517680Spst
2617680Spst/*
2717680Spst * This array is designed for mapping upper and lower case letter
2817680Spst * together for a case independent comparison.  The mappings are
2917680Spst * based upon ascii character sequences.
3017680Spst */
31214478Srpaulostatic const u_char charmap[] = {
3217680Spst	'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
3317680Spst	'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
3417680Spst	'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
3517680Spst	'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
3617680Spst	'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
3717680Spst	'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
3817680Spst	'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
3917680Spst	'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
4017680Spst	'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
4117680Spst	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
4217680Spst	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
4317680Spst	'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
4417680Spst	'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
4517680Spst	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
4617680Spst	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
4717680Spst	'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
4817680Spst	'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
4917680Spst	'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
5017680Spst	'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
5117680Spst	'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
5217680Spst	'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
5317680Spst	'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
5417680Spst	'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
5517680Spst	'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
5617680Spst	'\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
5717680Spst	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
5817680Spst	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
5917680Spst	'\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
6017680Spst	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
6117680Spst	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
6217680Spst	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
6317680Spst	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
6417680Spst};
6517680Spst
6617680Spstint
6717680Spststrcasecmp(s1, s2)
6817680Spst	const char *s1, *s2;
6917680Spst{
70214478Srpaulo	register const u_char *cm = charmap,
7117680Spst			*us1 = (u_char *)s1,
7217680Spst			*us2 = (u_char *)s2;
7317680Spst
7417680Spst	while (cm[*us1] == cm[*us2++])
7517680Spst		if (*us1++ == '\0')
7617680Spst			return(0);
7717680Spst	return(cm[*us1] - cm[*--us2]);
7817680Spst}
7917680Spst
8017680Spstint
8117680Spststrncasecmp(s1, s2, n)
8217680Spst	const char *s1, *s2;
8317680Spst	register int n;
8417680Spst{
85214478Srpaulo	register const u_char *cm = charmap,
8617680Spst			*us1 = (u_char *)s1,
8717680Spst			*us2 = (u_char *)s2;
8817680Spst
8917680Spst	while (--n >= 0 && cm[*us1] == cm[*us2++])
9017680Spst		if (*us1++ == '\0')
9117680Spst			return(0);
9217680Spst	return(n < 0 ? 0 : cm[*us1] - cm[*--us2]);
9317680Spst}
94