root/maint/gnulib/tests/test-execvpe-main.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_environ_assignment
  2. create_minimal_env
  3. main

   1 /* Test of execvpe().
   2    Copyright (C) 2020-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software; you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3, or (at your option)
   7    any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program; if not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Bruno Haible <bruno@clisp.org>, 2020.  */
  18 
  19 #include <config.h>
  20 
  21 /* Specification.  */
  22 #include <unistd.h>
  23 
  24 #include "signature.h"
  25 SIGNATURE_CHECK (execvpe, int, (const char *, char * const *, char * const *));
  26 
  27 #include <stdio.h>
  28 #include <string.h>
  29 
  30 /* Looks up the NAME=VALUE assignment among the environment variables.
  31    Returns it, or NULL if not found.  */
  32 static const char *
  33 get_environ_assignment (const char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35   size_t name_len = strlen (name);
  36   char **p;
  37   for (p = environ; *p != NULL; p++)
  38     {
  39       const char *assignment = *p;
  40       if (strncmp (assignment, name, name_len) == 0
  41           && assignment[name_len] == '=')
  42         return assignment;
  43     }
  44   return NULL;
  45 }
  46 
  47 /* Creates a minimal environment.  */
  48 static void
  49 create_minimal_env (const char *env[5])
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51   const char **p = env;
  52   *p++ =
  53     #ifdef __CYGWIN__
  54     /* The Cygwin DLLs needed by the program are in /bin.  */
  55     "PATH=.:/bin";
  56     #else
  57     "PATH=.";
  58     #endif
  59   *p = get_environ_assignment ("QEMU_LD_PREFIX");
  60   if (*p != NULL)
  61     p++;
  62   *p = get_environ_assignment ("QEMU_CPU");
  63   if (*p != NULL)
  64     p++;
  65   *p++ = "Hommingberg=Gepardenforelle";
  66   *p = NULL;
  67 }
  68 
  69 int
  70 main ()
     /* [previous][next][first][last][top][bottom][index][help] */
  71 {
  72   const char *progname = "test-exec-child";
  73   const char *argv[12] =
  74     {
  75       progname,
  76       "abc def",
  77       "abc\"def\"ghi",
  78       "xyz\"",
  79       "abc\\def\\ghi",
  80       "xyz\\",
  81       "???",
  82       "***",
  83       "",
  84       "foo",
  85       "",
  86       NULL
  87     };
  88   const char *env[5];
  89   create_minimal_env (env);
  90   execvpe (progname, (char * const *) argv, (char * const *) env);
  91 
  92   perror ("execvpe");
  93   return 1;
  94 }

/* [previous][next][first][last][top][bottom][index][help] */