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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [libiberty/] [getcwd.c] - Diff between revs 579 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/* Emulate getcwd using getwd.
/* Emulate getcwd using getwd.
   This function is in the public domain. */
   This function is in the public domain. */
 
 
/*
/*
NAME
NAME
        getcwd -- get absolute pathname for current working directory
        getcwd -- get absolute pathname for current working directory
 
 
SYNOPSIS
SYNOPSIS
        char *getcwd (char pathname[len], len)
        char *getcwd (char pathname[len], len)
 
 
DESCRIPTION
DESCRIPTION
        Copy the absolute pathname for the current working directory into
        Copy the absolute pathname for the current working directory into
        the supplied buffer and return a pointer to the buffer.  If the
        the supplied buffer and return a pointer to the buffer.  If the
        current directory's path doesn't fit in LEN characters, the result
        current directory's path doesn't fit in LEN characters, the result
        is NULL and errno is set.
        is NULL and errno is set.
 
 
        If pathname is a null pointer, getcwd() will obtain size bytes of
        If pathname is a null pointer, getcwd() will obtain size bytes of
        space using malloc.
        space using malloc.
 
 
BUGS
BUGS
        Emulated via the getwd() call, which is reasonable for most
        Emulated via the getwd() call, which is reasonable for most
        systems that do not have getcwd().
        systems that do not have getcwd().
 
 
*/
*/
 
 
#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>
 
 
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;
}
}
 
 

powered by: WebSVN 2.1.0

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