Files
glibc/string/strcmp.c
T

48 lines
1.4 KiB
C
Raw Normal View History

/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
1996-12-20 01:39:50 +00:00
This file is part of the GNU C Library.
1995-02-18 01:27:10 +00:00
1996-12-20 01:39:50 +00:00
The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
1995-02-18 01:27:10 +00:00
1996-12-20 01:39:50 +00:00
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
Lesser General Public License for more details.
1995-02-18 01:27:10 +00:00
2001-07-06 04:58:11 +00:00
You should have received a copy of the GNU Lesser General Public
2012-02-09 23:18:22 +00:00
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
1995-02-18 01:27:10 +00:00
#include <string.h>
1997-09-11 12:09:10 +00:00
#undef strcmp
2015-08-26 10:26:22 +02:00
#ifndef STRCMP
# define STRCMP strcmp
#endif
1995-02-18 01:27:10 +00:00
/* Compare S1 and S2, returning less than, equal to or
1996-12-20 01:39:50 +00:00
greater than zero if S1 is lexicographically less than,
1995-02-18 01:27:10 +00:00
equal to or greater than S2. */
int
2015-08-26 10:26:22 +02:00
STRCMP (const char *p1, const char *p2)
1995-02-18 01:27:10 +00:00
{
const unsigned char *s1 = (const unsigned char *) p1;
const unsigned char *s2 = (const unsigned char *) p2;
2012-04-18 16:19:10 -07:00
unsigned char c1, c2;
1995-02-18 01:27:10 +00:00
do
{
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0')
return c1 - c2;
}
while (c1 == c2);
return c1 - c2;
}
2003-04-29 22:49:58 +00:00
libc_hidden_builtin_def (strcmp)