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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [posix/] [execvp.c] - Diff between revs 57 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 57 Rev 1765
/* execvp.c */
/* execvp.c */
 
 
/* This and the other exec*.c files in this directory require
/* This and the other exec*.c files in this directory require
   the target to provide the _execve syscall.  */
   the target to provide the _execve syscall.  */
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include <ctype.h>
#include <ctype.h>
 
 
#ifdef __CYGWIN32__
#ifdef __CYGWIN32__
static char path_delim;
static char path_delim;
#define PATH_DELIM path_delim
#define PATH_DELIM path_delim
#else
#else
#define PATH_DELIM ':'
#define PATH_DELIM ':'
#endif
#endif
 
 
/*
/*
 * Copy string, until c or <nul> is encountered.
 * Copy string, until c or <nul> is encountered.
 * NUL-terminate the destination string (s1).
 * NUL-terminate the destination string (s1).
 */
 */
 
 
static char *
static char *
_DEFUN (strccpy, (s1, s2, c),
_DEFUN (strccpy, (s1, s2, c),
        char *s1 _AND
        char *s1 _AND
        char *s2 _AND
        char *s2 _AND
        char c)
        char c)
{
{
  char *dest = s1;
  char *dest = s1;
 
 
  while (*s2 && *s2 != c)
  while (*s2 && *s2 != c)
    *s1++ = *s2++;
    *s1++ = *s2++;
  *s1 = 0;
  *s1 = 0;
 
 
  return dest;
  return dest;
}
}
 
 
int
int
_DEFUN (execvp, (file, argv),
_DEFUN (execvp, (file, argv),
        _CONST char *file _AND
        _CONST char *file _AND
        char * _CONST argv[])
        char * _CONST argv[])
{
{
  char *path = getenv ("PATH");
  char *path = getenv ("PATH");
  char buf[MAXNAMLEN];
  char buf[MAXNAMLEN];
 
 
  /* If $PATH doesn't exist, just pass FILE on unchanged.  */
  /* If $PATH doesn't exist, just pass FILE on unchanged.  */
  if (!path)
  if (!path)
    return execv (file, argv);
    return execv (file, argv);
 
 
  /* If FILE contains a directory, don't search $PATH.  */
  /* If FILE contains a directory, don't search $PATH.  */
  if (strchr (file, '/')
  if (strchr (file, '/')
#ifdef __CYGWIN32__
#ifdef __CYGWIN32__
      || strchr (file, '\\')
      || strchr (file, '\\')
#endif
#endif
      )
      )
    return execv (file, argv);
    return execv (file, argv);
 
 
#ifdef __CYGWIN32__
#ifdef __CYGWIN32__
  /* If a drive letter is passed, the path is still an absolute one.
  /* If a drive letter is passed, the path is still an absolute one.
     Technically this isn't true, but Cygwin is currently defined so
     Technically this isn't true, but Cygwin is currently defined so
     that it is.  */
     that it is.  */
  if ((isalpha (file[0]) && file[1] == ':')
  if ((isalpha (file[0]) && file[1] == ':')
      || file[0] == '\\')
      || file[0] == '\\')
    return execv (file, argv);
    return execv (file, argv);
#endif
#endif
 
 
#ifdef __CYGWIN32__
#ifdef __CYGWIN32__
  path_delim = cygwin_posix_path_list_p (path) ? ':' : ';';
  path_delim = cygwin_posix_path_list_p (path) ? ':' : ';';
#endif
#endif
 
 
  while (*path)
  while (*path)
    {
    {
      strccpy (buf, path, PATH_DELIM);
      strccpy (buf, path, PATH_DELIM);
      /* An empty entry means the current directory.  */
      /* An empty entry means the current directory.  */
      if (*buf != 0)
      if (*buf != 0)
        strcat (buf, "/");
        strcat (buf, "/");
      strcat (buf, file);
      strcat (buf, file);
      if (execv (buf, argv) == -1 && errno != ENOENT)
      if (execv (buf, argv) == -1 && errno != ENOENT)
        return -1;
        return -1;
      while (*path && *path != PATH_DELIM)
      while (*path && *path != PATH_DELIM)
        path++;
        path++;
      if (*path == PATH_DELIM)
      if (*path == PATH_DELIM)
        path++;                 /* skip over delim */
        path++;                 /* skip over delim */
    }
    }
 
 
  return -1;
  return -1;
}
}
 
 

powered by: WebSVN 2.1.0

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