Exemplo n.º 1
0
char	*my_getabsolutepath(char *str, char **env)
{
  char	*tmp;
  char	*out;
  char	**path;
  int	i;

  if (str == NULL || env == NULL || (path = my_getpath(env)) == NULL)
    return (NULL);
  i = -1;
  if (str[0] == '.' || str[0] == '/')
    return (my_strdup(str));
  while (path[++i] != NULL)
    {
      if ((tmp = my_strstick(path[i], "/")) == NULL ||
	  (out = my_strstick(tmp, str)) == NULL)
	return (NULL);
      if (!access(out, F_OK))
	{
	  gbgc_free(NULL, tmp);
	  return (out);
	}
      gbgc_free(NULL, tmp);
      gbgc_free(NULL, out);
    }
  free_strtab(path);
  return (NULL);
}
Exemplo n.º 2
0
Arquivo: sh_exe.c Projeto: k6s/yaod
char    		exe_cmd(t_prog *s_prog, char **av, char **environ,
                        WINDOW **wins)
{
    size_t		pathlen;
    char			pathname[NAME_MAX + PATH_MAX];
    pid_t			pid;
    int			status;
    int           fds[2];

    if (pipe(fds))
        return (-1);
    pathlen = my_strlen(s_prog->path);
    my_strncpy(pathname, s_prog->path, PATH_MAX);
    if (pathname[pathlen] != '/')
        pathname[(pathlen++)] = '/';
    my_strncpy(pathname + pathlen, s_prog->name, NAME_MAX);
    pathname[NAME_MAX + PATH_MAX - 1] = 0;
    if ((pid = fork()) > -1)
    {
        if (!pid)
        {
            /* restore_termcap(tsave); */
            close(fds[0]);
            if ((dup2(fds[1], 1)) < 0)
                exit(EXIT_FAILURE);
            execve(pathname, av, environ);
            exit(EXIT_FAILURE);
        }
        else
        {
            close(fds[1]);
            my_bzero(pathname, sizeof(pathname));
            while (read(fds[0], pathname, NAME_MAX + PATH_MAX - 1) > 0)
            {
                pathname[NAME_MAX + PATH_MAX - 1] = 0;
                waddstr(wins[WIN_SH], pathname);
                wrefresh(wins[WIN_SH]);
            }
            waitpid(pid, &status, 0);
            free_strtab(av);
            return (WEXITSTATUS(status));
        }
    }
    free_strtab(av);
    waddstr(wins[WIN_SH], "err: cannot fork process\n");
    return (-2);
}
Exemplo n.º 3
0
Arquivo: sh_exe.c Projeto: k6s/yaod
char    		exe_builtin(t_prog *prog, char **av, t_term *s_term)
{
    char  ret;

    ret = (*prog->builtfp)(s_term, av);
    free_strtab(av);
    return ((char)ret);
}
Exemplo n.º 4
0
int	dtf_delete(t_dtf *data)
{
  if (get_crtreturn(NULL))
    return (0);
  if (data == NULL)
    return (0);
  if (data->map != NULL)
    free_strtab((char **)data->map);
  if (data->units != NULL)
    freelist(data->units, NULL);
  gbgc_free(NULL, data);
  return (1);
}
Exemplo n.º 5
0
int	createpipe(t_lid *data)
{
  t_pip	*pipe;
  char	**tab;
  char	*line;

  if (data == NULL || (line = get_last_line(data->file)) == NULL)
    return (FALSE);
  if (line[0] == '#')
    return (TRUE);
  if ((tab = my_strtok(line, "-")) == NULL || tab_length(tab) != 2 ||
      (pipe = create_pipe(tab[0], tab[1])) == NULL ||
      data->existPipe(data, pipe))
    return (FALSE);
  data->addPipe(data, pipe);
  gbgc_free(NULL, line);
  free_strtab(tab);
  return (TRUE);
}