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

Subversion Repositories or1k

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

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

Line No. Rev Author Line
1 1010 ivang
/* 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 <dirent.h>
10
#include <string.h>
11
#include <errno.h>
12
#include <ctype.h>
13
 
14
#define PATH_DELIM ':'
15
 
16
/*
17
 * Copy string, until c or <nul> is encountered.
18
 * NUL-terminate the destination string (s1).
19
 */
20
 
21
static char *
22
_DEFUN (strccpy, (s1, s2, c),
23
        char *s1 _AND
24
        char *s2 _AND
25
        char c)
26
{
27
  char *dest = s1;
28
 
29
  while (*s2 && *s2 != c)
30
    *s1++ = *s2++;
31
  *s1 = 0;
32
 
33
  return dest;
34
}
35
 
36
int
37
_DEFUN (execvp, (file, argv),
38
        _CONST char *file _AND
39
        char * _CONST argv[])
40
{
41
  char *path = getenv ("PATH");
42
  char buf[MAXNAMLEN];
43
 
44
  /* If $PATH doesn't exist, just pass FILE on unchanged.  */
45
  if (!path)
46
    return execv (file, argv);
47
 
48
  /* If FILE contains a directory, don't search $PATH.  */
49
  if (strchr (file, '/')
50
      )
51
    return execv (file, argv);
52
 
53
  while (*path)
54
    {
55
      strccpy (buf, path, PATH_DELIM);
56
      /* An empty entry means the current directory.  */
57
      if (*buf != 0 && buf[strlen(buf) - 1] != '/')
58
        strcat (buf, "/");
59
      strcat (buf, file);
60
      if (execv (buf, argv) == -1 && errno != ENOENT)
61
        return -1;
62
      while (*path && *path != PATH_DELIM)
63
        path++;
64
      if (*path == PATH_DELIM)
65
        path++;                 /* skip over delim */
66
    }
67
 
68
  return -1;
69
}

powered by: WebSVN 2.1.0

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