MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / strncasecmp

Function strncasecmp

src/gmt_common_string.c:433–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

431 Note: This function cannot work correctly in multibyte locales. */
432
433int strncasecmp (const char *s1, const char *s2, size_t n) {
434 register const unsigned char *p1 = (const unsigned char *) s1;
435 register const unsigned char *p2 = (const unsigned char *) s2;
436 unsigned char c1, c2;
437
438 if (p1 == p2 || n == 0)
439 return 0;
440
441 do
442 {
443 c1 = TOLOWER (*p1);
444 c2 = TOLOWER (*p2);
445
446 if (--n == 0 || c1 == '\0')
447 break;
448
449 ++p1;
450 ++p2;
451 }
452 while (c1 == c2);
453
454 if (UCHAR_MAX <= INT_MAX)
455 return c1 - c2;
456 else
457 /* On machines where 'char' and 'int' are types of the same size, the
458 difference of two 'unsigned char' values - including the sign bit -
459 doesn't fit in an 'int'. */
460 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
461}
462#endif /* !defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP) */
463
464#if !defined(HAVE_STRTOK_R) && !defined(HAVE_STRTOK_S)

Callers 2

GMT_Call_ModuleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected