OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [posix/] [execvp.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/* execvp.c */
2
 
3
/* This and the other exec*.c files in this directory require
4
   the target to provide the _execve syscall.  */
5
 
6
#include <_ansi.h>
7
#include <stdlib.h>
8
#include <unistd.h>
9
#include <errno.h>
10
#include <ctype.h>
11
 
12
#ifdef __CYGWIN32__
13
static char path_delim;
14
#define PATH_DELIM path_delim
15
#else
16
#define PATH_DELIM ':'
17
#endif
18
 
19
/*
20
 * Copy string, until c or <nul> is encountered.
21
 * NUL-terminate the destination string (s1).
22
 */
23
 
24
static char *
25
_DEFUN (strccpy, (s1, s2, c),
26
        char *s1 _AND
27
        char *s2 _AND
28
        char c)
29
{
30
  char *dest = s1;
31
 
32
  while (*s2 && *s2 != c)
33
    *s1++ = *s2++;
34
  *s1 = 0;
35
 
36
  return dest;
37
}
38
 
39
int
40
_DEFUN (execvp, (file, argv),
41
        _CONST char *file _AND
42
        char * _CONST argv[])
43
{
44
  char *path = getenv ("PATH");
45
  char buf[MAXNAMLEN];
46
 
47
  /* If $PATH doesn't exist, just pass FILE on unchanged.  */
48
  if (!path)
49
    return execv (file, argv);
50
 
51
  /* If FILE contains a directory, don't search $PATH.  */
52
  if (strchr (file, '/')
53
#ifdef __CYGWIN32__
54
      || strchr (file, '\\')
55
#endif
56
      )
57
    return execv (file, argv);
58
 
59
#ifdef __CYGWIN32__
60
  /* If a drive letter is passed, the path is still an absolute one.
61 56 joel
     Technically this isn't true, but Cygwin is currently defined so
62 39 lampret
     that it is.  */
63
  if ((isalpha (file[0]) && file[1] == ':')
64
      || file[0] == '\\')
65
    return execv (file, argv);
66
#endif
67
 
68
#ifdef __CYGWIN32__
69 56 joel
  path_delim = cygwin_posix_path_list_p (path) ? ':' : ';';
70 39 lampret
#endif
71
 
72
  while (*path)
73
    {
74
      strccpy (buf, path, PATH_DELIM);
75
      /* An empty entry means the current directory.  */
76
      if (*buf != 0)
77
        strcat (buf, "/");
78
      strcat (buf, file);
79
      if (execv (buf, argv) == -1 && errno != ENOENT)
80
        return -1;
81
      while (*path && *path != PATH_DELIM)
82
        path++;
83
      if (*path == PATH_DELIM)
84
        path++;                 /* skip over delim */
85
    }
86
 
87
  return -1;
88
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.