Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. strcscmp.cxx
  5. Abstract:
  6. This module implements case insensitive string comparison routines.
  7. Author:
  8. Mike Massa (mikemas) Sept 20, 1991
  9. Revision History:
  10. Who When What
  11. -------- -------- ----------------------------------------------
  12. mikemas 9-20-91 created
  13. Notes:
  14. Exports:
  15. None
  16. --*/
  17. #include "smtpinc.h"
  18. #ident "@(#)strcasecmp.c 5.3 3/8/91"
  19. /******************************************************************
  20. *
  21. * SpiderTCP BIND
  22. *
  23. * Copyright 1990 Spider Systems Limited
  24. *
  25. * STRCASECMP.C
  26. *
  27. ******************************************************************/
  28. /*
  29. * /usr/projects/tcp/SCCS.rel3/rel/src/lib/net/0/s.strcasecmp.c
  30. * @(#)strcasecmp.c 5.3
  31. *
  32. * Last delta created 14:12:01 3/4/91
  33. * This file extracted 11:20:35 3/8/91
  34. *
  35. * Modifications:
  36. *
  37. * GSS 24 Jul 90 New File
  38. */
  39. /*
  40. * Copyright (c) 1987 Regents of the University of California.
  41. * All rights reserved.
  42. *
  43. * Redistribution and use in source and binary forms are permitted
  44. * provided that the above copyright notice and this paragraph are
  45. * duplicated in all such forms and that any documentation,
  46. * advertising materials, and other materials related to such
  47. * distribution and use acknowledge that the software was developed
  48. * by the University of California, Berkeley. The name of the
  49. * University may not be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  52. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  53. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  54. */
  55. #if defined(LIBC_SCCS) && !defined(lint)
  56. static char sccsid[] = "@(#)strcasecmp.c 5.7 (Berkeley) 2/7/89";
  57. #endif /* LIBC_SCCS and not lint */
  58. /**************************************************************************/
  59. #include <winsock.h>
  60. //#include "winsockp.h"
  61. /*
  62. * This array is designed for mapping upper and lower case letter
  63. * together for a case independent comparison. The mappings are
  64. * based upon ascii character sequences.
  65. */
  66. static char charmap[] = {
  67. '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  68. '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  69. '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  70. '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  71. '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  72. '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  73. '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  74. '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  75. '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  76. '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  77. '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  78. '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  79. '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  80. '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  81. '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  82. '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  83. '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  84. '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  85. '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  86. '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  87. '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  88. '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  89. '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  90. '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  91. '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
  92. '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
  93. '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
  94. '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
  95. '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  96. '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  97. '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  98. '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  99. };
  100. int
  101. strcasecmp(
  102. char *s1,
  103. char *s2
  104. )
  105. {
  106. register char *cm = charmap,
  107. *us1 = (char *)s1,
  108. *us2 = (char *)s2;
  109. while (cm[*us1] == cm[*us2++])
  110. if (*us1++ == '\0')
  111. return(0);
  112. return(cm[*us1] - cm[*--us2]);
  113. }
  114. int
  115. strncasecmp(
  116. char *s1,
  117. char *s2,
  118. int n
  119. )
  120. {
  121. register char *cm = charmap,
  122. *us1 = (char *)s1,
  123. *us2 = (char *)s2;
  124. while (--n >= 0 && cm[*us1] == cm[*us2++])
  125. if (*us1++ == '\0')
  126. return(0);
  127. return(n < 0 ? 0 : cm[*us1] - cm[*--us2]);
  128. }