From 56e09c3b77809bf25d2ec3136cb66b8444d488a1 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 7 Jun 1994 18:55:44 +0000 Subject: [PATCH] now works if no fchdir --- realpath.c | 27 +++++++++++++++++++++++++++ sudo_realpath.c | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/realpath.c b/realpath.c index cc96d7a3a..172c786fc 100644 --- a/realpath.c +++ b/realpath.c @@ -68,7 +68,11 @@ extern int lstat(); /* * Prototypes */ +#ifdef HAVE_FCHDIR static char * realpath_ret(char *, FILE *); +#else +static char * realpath_ret(char *, char *); +#endif /* HAVE_FCHDIR */ /****************************************************************** @@ -84,7 +88,11 @@ char * realpath(old, new) char * new; { char buf[MAXPATHLEN]; /* generic path buffer */ +#ifdef HAVE_FCHDIR FILE * cwd; /* current working dir */ +#else + static char cwd[MAXPATHLEN]; /* old working dir */ +#endif /* HAVE_FCHDIR */ struct stat statbuf; /* for lstat() */ char * temp; /* temporary ptr */ int len; /* length parameter */ @@ -94,8 +102,13 @@ char * realpath(old, new) return(NULL); /* save old cwd so we can get back */ +#ifdef HAVE_FCHDIR if (!(cwd = fopen(".", "r"))) return(NULL); +#else + if (!getcwd(cwd, sizeof(cwd))) + return(NULL); +#endif /* HAVE_FCHDIR */ new[MAXPATHLEN - 1] = '\0'; (void) strncpy(new, old, MAXPATHLEN - 1); @@ -180,6 +193,7 @@ char * realpath(old, new) * this function cd's to cwd, closes it, and returns path. */ +#ifdef HAVE_FCHDIR static char * realpath_ret(path, cwd) char * path; FILE * cwd; @@ -192,3 +206,16 @@ static char * realpath_ret(path, cwd) errno = old_errno; return(path); } +#else +static char * realpath_ret(path, cwd) + char * path; + char * cwd; +{ + int old_errno = errno; /* so we can restore errno... */ + + (void) chdir(cwd); + + errno = old_errno; + return(path); +} +#endif /* HAVE_FCHDIR */ diff --git a/sudo_realpath.c b/sudo_realpath.c index cc96d7a3a..172c786fc 100644 --- a/sudo_realpath.c +++ b/sudo_realpath.c @@ -68,7 +68,11 @@ extern int lstat(); /* * Prototypes */ +#ifdef HAVE_FCHDIR static char * realpath_ret(char *, FILE *); +#else +static char * realpath_ret(char *, char *); +#endif /* HAVE_FCHDIR */ /****************************************************************** @@ -84,7 +88,11 @@ char * realpath(old, new) char * new; { char buf[MAXPATHLEN]; /* generic path buffer */ +#ifdef HAVE_FCHDIR FILE * cwd; /* current working dir */ +#else + static char cwd[MAXPATHLEN]; /* old working dir */ +#endif /* HAVE_FCHDIR */ struct stat statbuf; /* for lstat() */ char * temp; /* temporary ptr */ int len; /* length parameter */ @@ -94,8 +102,13 @@ char * realpath(old, new) return(NULL); /* save old cwd so we can get back */ +#ifdef HAVE_FCHDIR if (!(cwd = fopen(".", "r"))) return(NULL); +#else + if (!getcwd(cwd, sizeof(cwd))) + return(NULL); +#endif /* HAVE_FCHDIR */ new[MAXPATHLEN - 1] = '\0'; (void) strncpy(new, old, MAXPATHLEN - 1); @@ -180,6 +193,7 @@ char * realpath(old, new) * this function cd's to cwd, closes it, and returns path. */ +#ifdef HAVE_FCHDIR static char * realpath_ret(path, cwd) char * path; FILE * cwd; @@ -192,3 +206,16 @@ static char * realpath_ret(path, cwd) errno = old_errno; return(path); } +#else +static char * realpath_ret(path, cwd) + char * path; + char * cwd; +{ + int old_errno = errno; /* so we can restore errno... */ + + (void) chdir(cwd); + + errno = old_errno; + return(path); +} +#endif /* HAVE_FCHDIR */ -- 2.40.0