boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

015-strops.c (1037B)


      1 /* Public string ops the libc surfaces from string/. tests/cc/129
      2  * exercises the libp1pp-provided memcpy/memset/strlen labels by way
      3  * of bare-name extern decls; this fixture instead drives the calls
      4  * through the libc.P1pp surface (where strcmp / strchr come from
      5  * mes's string/strcmp.c and string/strchr.c). */
      6 typedef unsigned long size_t;
      7 typedef long ssize_t;
      8 
      9 extern size_t strlen (char const *s);
     10 extern int    strcmp (char const *a, char const *b);
     11 extern char  *strchr (char const *s, int c);
     12 extern ssize_t write (int fd, void const *buf, size_t n);
     13 
     14 int
     15 main (void)
     16 {
     17   if (strlen ("abc") != 3)
     18     {
     19       write (1, "len-fail\n", 9);
     20       return 1;
     21     }
     22   if (strcmp ("foo", "foo") != 0)
     23     {
     24       write (1, "eq-fail\n", 8);
     25       return 2;
     26     }
     27   if (strcmp ("foo", "bar") == 0)
     28     {
     29       write (1, "ne-fail\n", 8);
     30       return 3;
     31     }
     32   char *p = strchr ("hello", 'l');
     33   if (!p || *p != 'l' || p[1] != 'l')
     34     {
     35       write (1, "chr-fail\n", 9);
     36       return 4;
     37     }
     38   write (1, "ok\n", 3);
     39   return 0;
     40 }