home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / texinfo-3.7-src.tgz / tar.out / fsf / texinfo / info / clib.c next >
C/C++ Source or Header  |  1996-09-28  |  3KB  |  125 lines

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