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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [posix/] [execvp.c] - Blame information for rev 262

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

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

powered by: WebSVN 2.1.0

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