Newer
Older
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** Started on Tue Apr 11 00:23:47 2006 Seblu
*/
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include "../common/function.h"
#include "../shell/shell.h"
#include "../shell/var.h"
** Change directory to home directory
**
** @param name env var
**
** @return success status
static int cd_var(const char *name);
/*!
** Change of directory and on error, print good error.
**
** @param path new path
**
** @return error status with error code (0 is good)
*/
static int secure_chdir(const char *path);
/*
** ===========
** DEFINITIONS
** ===========
*/
int builtin_cd(char **argv)
if (!(new_dir = var_get(shell->var, name))) {
fprintf(stderr, "%s: cd: %s not set\n", shell->name, name);
return 1;
}
return secure_chdir(new_dir);
}
static int secure_chdir(const char *path)
{
char *tmp;
if (chdir(path)) {
fprintf(stderr, "%s: cd %s: %s\n", shell->name, path, strerror(errno));