2
0

ansi_c.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: ansi_c.c /main/1 1996/04/21 19:25:03 drk $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1996 Hewlett-Packard Company.
  27. * (c) Copyright 1996 International Business Machines Corp.
  28. * (c) Copyright 1993-1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. */
  33. #include <ctype.h>
  34. #include "ansi_c.h"
  35. #ifdef NEED_STRCASECMP
  36. /*
  37. * In case strcasecmp and strncasecmp are not provided by the system
  38. * here are ones which do the trick.
  39. */
  40. int
  41. strcasecmp(const char *s1,
  42. const char *s2)
  43. {
  44. int c1, c2;
  45. while (*s1 && *s2) {
  46. c1 = isupper(*s1) ? tolower(*s1) : *s1;
  47. c2 = isupper(*s2) ? tolower(*s2) : *s2;
  48. if (c1 != c2)
  49. return (c1 - c2);
  50. s1++;
  51. s2++;
  52. }
  53. return (int) (*s1 - *s2);
  54. }
  55. int
  56. strncasecmp(const char *s1,
  57. const char *s2,
  58. size_t count)
  59. {
  60. int c1, c2;
  61. if (!count)
  62. return 0;
  63. while (*s1 && *s2) {
  64. c1 = isupper(*s1) ? tolower(*s1) : *s1;
  65. c2 = isupper(*s2) ? tolower(*s2) : *s2;
  66. if ((c1 != c2) || (! --count))
  67. return (c1 - c2);
  68. s1++;
  69. s2++;
  70. }
  71. return (int) (*s1 - *s2);
  72. }
  73. #else
  74. int ansi_c_strcasecmp_not_needed = 0; /* Make the compiler happy. */
  75. #endif