Back to index

glibc  2.9
tst-execvp4.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include <unistd.h>
00006 #include <sys/stat.h>
00007 
00008 static int
00009 do_test (void)
00010 {
00011   char buf[40] = "/usr/bin/does-not-exist";
00012   size_t stemlen = strlen (buf);
00013   struct stat64 st;
00014   int cnt = 0;
00015   while (stat64 (buf, &st) != -1 || errno != ENOENT
00016         || stat64 (buf + 4, &st) != -1 || errno != ENOENT)
00017     {
00018       if (cnt++ == 100)
00019        {
00020          puts ("cannot find a unique file name");
00021          return 0;
00022        }
00023 
00024       strcpy (buf + stemlen, ".XXXXXX");
00025       mktemp (buf);
00026     }
00027 
00028   unsetenv ("PATH");
00029   char *argv[] = { buf + 9, NULL };
00030   execvp (argv[0], argv);
00031   return 0;
00032 }
00033 
00034 #define TEST_FUNCTION do_test ()
00035 #include "../test-skeleton.c"