mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
63 lines
1.7 KiB
C++
63 lines
1.7 KiB
C++
// Filename: executionEnvironment.cxx
|
|
// Created by: drose (15May00)
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
//
|
|
// PANDA 3D SOFTWARE
|
|
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
|
//
|
|
// All use of this software is subject to the terms of the Panda 3d
|
|
// Software license. You should have received a copy of this license
|
|
// along with this source code; you will also find a current copy of
|
|
// the license at http://www.panda3d.org/license.txt .
|
|
//
|
|
// To contact the maintainers of this program write to
|
|
// panda3d@yahoogroups.com .
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#include "executionEnvironment.h"
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h> // for perror
|
|
|
|
#ifdef WIN32_VC
|
|
// Windows requires this for getcwd().
|
|
#include <direct.h>
|
|
#define getcwd _getcwd
|
|
#endif
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Function: ExecutionEnviroment::get_cwd
|
|
// Access: Public, Static
|
|
// Description: Returns the name of the current working directory.
|
|
////////////////////////////////////////////////////////////////////
|
|
Filename ExecutionEnvironment::
|
|
get_cwd() {
|
|
// getcwd() requires us to allocate a dynamic buffer and grow it on
|
|
// demand.
|
|
static size_t bufsize = 1024;
|
|
static char *buffer = NULL;
|
|
|
|
if (buffer == (char *)NULL) {
|
|
buffer = new char[bufsize];
|
|
}
|
|
|
|
while (getcwd(buffer, bufsize) == (char *)NULL) {
|
|
if (errno != ERANGE) {
|
|
perror("getcwd");
|
|
return string();
|
|
}
|
|
delete[] buffer;
|
|
bufsize = bufsize * 2;
|
|
buffer = new char[bufsize];
|
|
assert(buffer != (char *)NULL);
|
|
}
|
|
|
|
return Filename::from_os_specific(buffer);
|
|
}
|