mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-04 16:25:25 +00:00
getcwd -> getwd
This commit is contained in:
48
getwd.c
48
getwd.c
@@ -19,9 +19,9 @@
|
|||||||
*
|
*
|
||||||
*******************************************************************
|
*******************************************************************
|
||||||
*
|
*
|
||||||
* This module contains getcwd(3) for those systems that lack it.
|
* This module contains getwd(3) for those systems that lack it.
|
||||||
* getcwd(3) returns a pointer to the current working dir. It uses
|
* getwd(3) returns a pointer to the current working dir. It uses
|
||||||
* path as a copy-out parameter and malloc(3)s space if path is NULL.
|
* path as a copy-out parameter.
|
||||||
*
|
*
|
||||||
* Todd C. Miller (millert@colorado.edu) Fri Jun 3 18:32:19 MDT 1994
|
* Todd C. Miller (millert@colorado.edu) Fri Jun 3 18:32:19 MDT 1994
|
||||||
*/
|
*/
|
||||||
@@ -45,9 +45,6 @@ static char rcsid[] = "$Id$";
|
|||||||
#ifdef HAVE_STRINGS_H
|
#ifdef HAVE_STRINGS_H
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#endif /* HAVE_STRINGS_H */
|
#endif /* HAVE_STRINGS_H */
|
||||||
#ifdef HAVE_MALLOC_H
|
|
||||||
#include <malloc.h>
|
|
||||||
#endif /* HAVE_MALLOC_H */
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -58,9 +55,6 @@ static char rcsid[] = "$Id$";
|
|||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
#ifndef STDC_HEADERS
|
#ifndef STDC_HEADERS
|
||||||
#ifndef __GNUC__ /* gcc has its own malloc */
|
|
||||||
extern char *malloc __P((size_t));
|
|
||||||
#endif /* __GNUC__ */
|
|
||||||
extern char *strcpy __P((char *, const char *));
|
extern char *strcpy __P((char *, const char *));
|
||||||
extern int strlen __P((const char *));
|
extern int strlen __P((const char *));
|
||||||
extern char *getwd __P((char *));
|
extern char *getwd __P((char *));
|
||||||
@@ -83,30 +77,28 @@ extern int errno;
|
|||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* getcwd()
|
* getwd()
|
||||||
*
|
*
|
||||||
* getcwd() returns a pointer to the current working dir. It uses
|
* getwd() returns a pointer to the current working dir. It uses
|
||||||
* path as a copy-out parameter and malloc(3)s space if path is NULL.
|
* path as a copy-out parameter.
|
||||||
* getcwd() will use getwd() if available, else it will use pwd(1).
|
* getwd() will use getcwd() if available, else it will use pwd(1).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char * getcwd(path, len)
|
char * getwd(path)
|
||||||
char * path; /* path to copy into */
|
char * path; /* path to copy into */
|
||||||
size_t len; /* length of path */
|
|
||||||
{
|
{
|
||||||
|
#ifndef HAVE_GETCWD
|
||||||
char buf[MAXPATHLEN+1]; /* temp buffer */
|
char buf[MAXPATHLEN+1]; /* temp buffer */
|
||||||
#ifndef HAVE_GETWD
|
|
||||||
FILE * pwd; /* for popen */
|
FILE * pwd; /* for popen */
|
||||||
#endif /* HAVE_GETWD */
|
#endif /* HAVE_GETCWD */
|
||||||
|
|
||||||
if (path && len <= 0) {
|
if (path == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GETWD
|
#ifdef HAVE_GETCWD
|
||||||
if (!getwd(buf))
|
return(getcwd(path, MAXPATHLEN));
|
||||||
return(NULL);
|
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* open a pipe to pwd and read a line
|
* open a pipe to pwd and read a line
|
||||||
@@ -122,20 +114,8 @@ char * getcwd(path, len)
|
|||||||
pclose(pwd);
|
pclose(pwd);
|
||||||
|
|
||||||
buf[strlen(buf)-1] = '\0'; /* remove newline */
|
buf[strlen(buf)-1] = '\0'; /* remove newline */
|
||||||
#endif /* HAVE_GETWD */
|
|
||||||
|
|
||||||
if (len < strlen(buf) + 1) {
|
|
||||||
errno = ERANGE;
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path == NULL) {
|
|
||||||
if (!(path = (char *) malloc(MAXPATHLEN+1))) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) strcpy(path, buf);
|
(void) strcpy(path, buf);
|
||||||
return(path);
|
return(path);
|
||||||
|
#endif /* HAVE_GETCWD */
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user