| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- // 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
- // [email protected] .
- //
- ////////////////////////////////////////////////////////////////////
- #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);
- }
|