now works if no fchdir
This commit is contained in:
27
realpath.c
27
realpath.c
@@ -68,7 +68,11 @@ extern int lstat();
|
|||||||
/*
|
/*
|
||||||
* Prototypes
|
* Prototypes
|
||||||
*/
|
*/
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
static char * realpath_ret(char *, FILE *);
|
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 * new;
|
||||||
{
|
{
|
||||||
char buf[MAXPATHLEN]; /* generic path buffer */
|
char buf[MAXPATHLEN]; /* generic path buffer */
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
FILE * cwd; /* current working dir */
|
FILE * cwd; /* current working dir */
|
||||||
|
#else
|
||||||
|
static char cwd[MAXPATHLEN]; /* old working dir */
|
||||||
|
#endif /* HAVE_FCHDIR */
|
||||||
struct stat statbuf; /* for lstat() */
|
struct stat statbuf; /* for lstat() */
|
||||||
char * temp; /* temporary ptr */
|
char * temp; /* temporary ptr */
|
||||||
int len; /* length parameter */
|
int len; /* length parameter */
|
||||||
@@ -94,8 +102,13 @@ char * realpath(old, new)
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
/* save old cwd so we can get back */
|
/* save old cwd so we can get back */
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
if (!(cwd = fopen(".", "r")))
|
if (!(cwd = fopen(".", "r")))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
#else
|
||||||
|
if (!getcwd(cwd, sizeof(cwd)))
|
||||||
|
return(NULL);
|
||||||
|
#endif /* HAVE_FCHDIR */
|
||||||
|
|
||||||
new[MAXPATHLEN - 1] = '\0';
|
new[MAXPATHLEN - 1] = '\0';
|
||||||
(void) strncpy(new, old, MAXPATHLEN - 1);
|
(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.
|
* this function cd's to cwd, closes it, and returns path.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
static char * realpath_ret(path, cwd)
|
static char * realpath_ret(path, cwd)
|
||||||
char * path;
|
char * path;
|
||||||
FILE * cwd;
|
FILE * cwd;
|
||||||
@@ -192,3 +206,16 @@ static char * realpath_ret(path, cwd)
|
|||||||
errno = old_errno;
|
errno = old_errno;
|
||||||
return(path);
|
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 */
|
||||||
|
@@ -68,7 +68,11 @@ extern int lstat();
|
|||||||
/*
|
/*
|
||||||
* Prototypes
|
* Prototypes
|
||||||
*/
|
*/
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
static char * realpath_ret(char *, FILE *);
|
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 * new;
|
||||||
{
|
{
|
||||||
char buf[MAXPATHLEN]; /* generic path buffer */
|
char buf[MAXPATHLEN]; /* generic path buffer */
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
FILE * cwd; /* current working dir */
|
FILE * cwd; /* current working dir */
|
||||||
|
#else
|
||||||
|
static char cwd[MAXPATHLEN]; /* old working dir */
|
||||||
|
#endif /* HAVE_FCHDIR */
|
||||||
struct stat statbuf; /* for lstat() */
|
struct stat statbuf; /* for lstat() */
|
||||||
char * temp; /* temporary ptr */
|
char * temp; /* temporary ptr */
|
||||||
int len; /* length parameter */
|
int len; /* length parameter */
|
||||||
@@ -94,8 +102,13 @@ char * realpath(old, new)
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
/* save old cwd so we can get back */
|
/* save old cwd so we can get back */
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
if (!(cwd = fopen(".", "r")))
|
if (!(cwd = fopen(".", "r")))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
#else
|
||||||
|
if (!getcwd(cwd, sizeof(cwd)))
|
||||||
|
return(NULL);
|
||||||
|
#endif /* HAVE_FCHDIR */
|
||||||
|
|
||||||
new[MAXPATHLEN - 1] = '\0';
|
new[MAXPATHLEN - 1] = '\0';
|
||||||
(void) strncpy(new, old, MAXPATHLEN - 1);
|
(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.
|
* this function cd's to cwd, closes it, and returns path.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_FCHDIR
|
||||||
static char * realpath_ret(path, cwd)
|
static char * realpath_ret(path, cwd)
|
||||||
char * path;
|
char * path;
|
||||||
FILE * cwd;
|
FILE * cwd;
|
||||||
@@ -192,3 +206,16 @@ static char * realpath_ret(path, cwd)
|
|||||||
errno = old_errno;
|
errno = old_errno;
|
||||||
return(path);
|
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 */
|
||||||
|
Reference in New Issue
Block a user