OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [libiberty/] [getcwd.c] - Diff between revs 834 and 842

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 834 Rev 842
/* 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 (char *buf, size_t len)
getcwd (char *buf, size_t 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;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.