1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00
This commit is contained in:
Jakub Jelinek
2007-07-12 18:26:36 +00:00
parent 7d58530341
commit 0ecb606cb6
6215 changed files with 494638 additions and 305010 deletions

View File

@ -1,5 +1,5 @@
/* Tester for string functions.
Copyright (C) 1995-2000, 2001, 2003 Free Software Foundation, Inc.
Copyright (C) 1995-2001, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -34,10 +34,6 @@
#include <strings.h>
#include <fcntl.h>
#ifndef HAVE_GNU_LD
#define _sys_nerr sys_nerr
#define _sys_errlist sys_errlist
#endif
#define STREQ(a, b) (strcmp((a), (b)) == 0)
@ -348,6 +344,9 @@ test_strncat (void)
(void) strncat (one, "gh", 2);
equal (one, "abcdgh", 12); /* Count and length equal. */
(void) strncat (one, "ij", (size_t)-1); /* set sign bit in count */
equal (one, "abcdghij", 13);
}
static void
@ -368,6 +367,8 @@ test_strncmp (void)
check (strncmp ("abce", "abc", 3) == 0, 11); /* Count == length. */
check (strncmp ("abcd", "abce", 4) < 0, 12); /* Nudging limit. */
check (strncmp ("abc", "def", 0) == 0, 13); /* Zero count. */
check (strncmp ("abc", "", (size_t)-1) > 0, 14); /* set sign bit in count */
check (strncmp ("abc", "abc", (size_t)-2) == 0, 15);
}
static void
@ -433,6 +434,29 @@ test_strlen (void)
}
}
static void
test_strnlen (void)
{
it = "strnlen";
check (strnlen ("", 10) == 0, 1); /* Empty. */
check (strnlen ("a", 10) == 1, 2); /* Single char. */
check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */
check (strnlen ("foo", (size_t)-1) == 3, 4); /* limits of n. */
{
char buf[4096];
int i;
char *p;
for (i=0; i < 0x100; i++)
{
p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i;
strcpy (p, "OK");
strcpy (p+3, "BAD/WRONG");
check (strnlen (p, 100) == 2, 5+i);
}
}
}
static void
test_strchr (void)
{
@ -1386,6 +1410,9 @@ main (void)
/* strlen. */
test_strlen ();
/* strnlen. */
test_strnlen ();
/* strchr. */
test_strchr ();