some-usable-scripts/C_Language/test.c

28 lines
502 B
C
Raw Normal View History

2011-02-20 18:52:23 +01:00
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
void changeDirectory(char * path);
void erreur(char *s);
int main(int argc, char **argv)
{
changeDirectory("");
char * wd = (char *) get_current_dir_name();
printf("Répertoire courant : %s\n", wd);
}
void changeDirectory(char * path)
{
if(strcmp(path, "") == 0)
chdir(getenv("HOME"));
else if(chdir(path) != 0 )
erreur("Impossible de changer de répertoire");
}
void erreur(char *s)
{
perror(s);
exit(-2);
}