(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.c-torture/
execute/
builtins/
strncmp.c
       1  /* Copyright (C) 2000, 2001, 2003  Free Software Foundation.
       2  
       3     Ensure all expected transformations of builtin strncmp occur and
       4     perform correctly.
       5  
       6     Written by Kaveh R. Ghazi, 11/26/2000.  */
       7  
       8  extern void abort (void);
       9  typedef __SIZE_TYPE__ size_t;
      10  extern int strncmp (const char *, const char *, size_t);
      11  
      12  void
      13  main_test (void)
      14  {
      15    const char *const s1 = "hello world";
      16    const char *s2, *s3;
      17    
      18    if (strncmp (s1, "hello world", 12) != 0)
      19      abort();
      20    if (strncmp ("hello world", s1, 12) != 0)
      21      abort();
      22    if (strncmp ("hello", "hello", 6) != 0)
      23      abort();
      24    if (strncmp ("hello", "hello", 2) != 0)
      25      abort();
      26    if (strncmp ("hello", "hello", 100) != 0)
      27      abort();
      28    if (strncmp (s1+10, "d", 100) != 0)
      29      abort();
      30    if (strncmp (10+s1, "d", 100) != 0)
      31      abort();
      32    if (strncmp ("d", s1+10, 1) != 0)
      33      abort();
      34    if (strncmp ("d", 10+s1, 1) != 0)
      35      abort();
      36    if (strncmp ("hello", "aaaaa", 100) <= 0)
      37      abort();
      38    if (strncmp ("aaaaa", "hello", 100) >= 0)
      39      abort();
      40    if (strncmp ("hello", "aaaaa", 1) <= 0)
      41      abort();
      42    if (strncmp ("aaaaa", "hello", 1) >= 0)
      43      abort();
      44  
      45    s2 = s1; s3 = s1+4;
      46    if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5)
      47      abort();
      48    s2 = s1;
      49    if (strncmp (++s2, "", 1) <= 0 || s2 != s1+1)
      50      abort();
      51    if (strncmp ("", ++s2, 1) >= 0 || s2 != s1+2)
      52      abort();
      53    if (strncmp (++s2, "", 100) <= 0 || s2 != s1+3)
      54      abort();
      55    if (strncmp ("", ++s2, 100) >= 0 || s2 != s1+4)
      56      abort();
      57    if (strncmp (++s2+6, "", 100) != 0 || s2 != s1+5)
      58      abort();
      59    if (strncmp ("", ++s2+5, 100) != 0 || s2 != s1+6)
      60      abort();
      61    if (strncmp ("ozz", ++s2, 1) != 0 || s2 != s1+7)
      62      abort();
      63    if (strncmp (++s2, "rzz", 1) != 0 || s2 != s1+8)
      64      abort();
      65    s2 = s1; s3 = s1+4;
      66    if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5)
      67      abort();
      68    
      69    /* Test at least one instance of the __builtin_ style.  We do this
      70       to ensure that it works and that the prototype is correct.  */
      71    if (__builtin_strncmp ("hello", "a", 100) <= 0)
      72      abort();
      73  }