URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Go to most recent revision |
Only display areas with differences |
Details |
Blame |
View Log
Rev 1181 |
Rev 1765 |
/* Emulate getcwd using getwd.
|
/* Emulate getcwd using getwd.
|
This function is in the public domain. */
|
This function is in the public domain. */
|
|
|
/*
|
/*
|
|
|
@deftypefn Supplemental char* getcwd (char *@var{pathname}, int @var{len})
|
@deftypefn Supplemental char* getcwd (char *@var{pathname}, int @var{len})
|
|
|
Copy the absolute pathname for the current working directory into
|
Copy the absolute pathname for the current working directory into
|
@var{pathname}, which is assumed to point to a buffer of at least
|
@var{pathname}, which is assumed to point to a buffer of at least
|
@var{len} bytes, and return a pointer to the buffer. If the current
|
@var{len} bytes, and return a pointer to the buffer. If the current
|
directory's path doesn't fit in @var{len} characters, the result is
|
directory's path doesn't fit in @var{len} characters, the result is
|
@code{NULL} and @code{errno} is set. If @var{pathname} is a null pointer,
|
@code{NULL} and @code{errno} is set. If @var{pathname} is a null pointer,
|
@code{getcwd} will obtain @var{len} bytes of space using
|
@code{getcwd} will obtain @var{len} bytes of space using
|
@code{malloc}.
|
@code{malloc}.
|
|
|
@end deftypefn
|
@end deftypefn
|
|
|
*/
|
*/
|
|
|
#include "config.h"
|
#include "config.h"
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
#ifdef HAVE_SYS_PARAM_H
|
#include <sys/param.h>
|
#include <sys/param.h>
|
#endif
|
#endif
|
#include <errno.h>
|
#include <errno.h>
|
#ifdef HAVE_STRING_H
|
#ifdef HAVE_STRING_H
|
#include <string.h>
|
#include <string.h>
|
#endif
|
#endif
|
#ifdef HAVE_STDLIB_H
|
#ifdef HAVE_STDLIB_H
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#endif
|
#endif
|
|
|
extern char *getwd ();
|
extern char *getwd ();
|
extern int errno;
|
extern int errno;
|
|
|
#ifndef MAXPATHLEN
|
#ifndef MAXPATHLEN
|
#define MAXPATHLEN 1024
|
#define MAXPATHLEN 1024
|
#endif
|
#endif
|
|
|
char *
|
char *
|
getcwd (buf, len)
|
getcwd (buf, len)
|
char *buf;
|
char *buf;
|
int len;
|
int len;
|
{
|
{
|
char ourbuf[MAXPATHLEN];
|
char ourbuf[MAXPATHLEN];
|
char *result;
|
char *result;
|
|
|
result = getwd (ourbuf);
|
result = getwd (ourbuf);
|
if (result) {
|
if (result) {
|
if (strlen (ourbuf) >= len) {
|
if (strlen (ourbuf) >= len) {
|
errno = ERANGE;
|
errno = ERANGE;
|
return 0;
|
return 0;
|
}
|
}
|
if (!buf) {
|
if (!buf) {
|
buf = (char*)malloc(len);
|
buf = (char*)malloc(len);
|
if (!buf) {
|
if (!buf) {
|
errno = ENOMEM;
|
errno = ENOMEM;
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
strcpy (buf, ourbuf);
|
strcpy (buf, ourbuf);
|
}
|
}
|
return buf;
|
return buf;
|
}
|
}
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.