1/* clib.c: Functions which we normally expect to find in the C library. 2 $Id: clib.c,v 1.1 2004/10/28 18:14:09 zooey Exp $ 3 4 This file is part of GNU Info, a program for reading online documentation 5 stored in Info format. 6 7 Copyright (C) 1995 Free Software Foundation, Inc. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2, or (at your option) 12 any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 23 Written by Brian Fox (bfox@ai.mit.edu). */ 24 25#include <stdio.h> 26 27#if defined (HAVE_UNISTD_H) 28#include <unistd.h> 29#endif 30 31#if defined (HAVE_STDLIB_H) 32#include <stdlib.h> 33#endif 34 35#if defined (HAVE_STRING_H) 36#include <string.h> 37#endif 38 39#include <sys/errno.h> 40 41extern void *xmalloc (), *xrealloc (); 42#include "general.h" 43 44#if !defined (errno) 45extern int errno; 46#endif 47 48#if !defined (HAVE_STRERROR) 49extern char *sys_errlist[]; 50extern int sys_nerr; 51 52char * 53strerror (num) 54 int num; 55{ 56 if (num >= sys_nerr) 57 return (""); 58 else 59 return (sys_errlist[num]); 60} 61#endif /* !HAVE_STRERROR */ 62 63#if !defined (HAVE_STRCASECMP) 64/* This Unix doesn't have the strcasecmp () function. */ 65int 66strcasecmp (string1, string2) 67 char *string1, *string2; 68{ 69 char ch1, ch2; 70 71 for (;;) 72 { 73 ch1 = *string1++; 74 ch2 = *string2++; 75 76 if (!(ch1 | ch2)) 77 return (0); 78 79 ch1 = info_toupper (ch1); 80 ch2 = info_toupper (ch2); 81 82 if (ch1 != ch2) 83 return (ch1 - ch2); 84 } 85} 86 87/* Compare at most COUNT characters from string1 to string2. Case 88 doesn't matter. */ 89int 90strncasecmp (string1, string2, count) 91 char *string1, *string2; 92 int count; 93{ 94 register char ch1, ch2; 95 96 while (count) 97 { 98 ch1 = *string1++; 99 ch2 = *string2++; 100 101 ch1 = info_toupper (ch1); 102 ch2 = info_toupper (ch2); 103 104 if (ch1 == ch2) 105 count--; 106 else 107 break; 108 } 109 return (count); 110} 111#endif /* !STRCASECMP */ 112 113