Clean up Filesystem.h

develop
lethosor 2015-01-28 17:15:09 -05:00
parent 4c5b6a5282
commit 2e3261565c
2 changed files with 67 additions and 94 deletions

@ -60,6 +60,7 @@ SOFTWARE.
#define _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE
#endif #endif
#include <cstdio>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -87,34 +88,6 @@ SOFTWARE.
#include <utime.h> #include <utime.h>
#endif #endif
#define LFS_VERSION "1.6.2"
#define LFS_LIBNAME "lfs"
#if LUA_VERSION_NUM < 502
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
#endif
/* Define 'strerror' for systems that do not implement it */
#ifdef NO_STRERROR
#define strerror(_) "System unable to describe the error"
#endif
/* Define 'getcwd' for systems that do not implement it */
#ifdef NO_GETCWD
#define getcwd(p,s) NULL
#define getcwd_error "Function 'getcwd' not provided by system"
#else
#define getcwd_error strerror(errno)
#ifdef _WIN32
/* MAX_PATH seems to be 260. Seems kind of small. Is there a better one? */
#define LFS_MAXPATHLEN MAX_PATH
#else
/* For MAXPATHLEN: */
#include <sys/param.h>
#define LFS_MAXPATHLEN MAXPATHLEN
#endif
#endif
typedef struct dir_data { typedef struct dir_data {
int closed; int closed;
#ifdef _WIN32 #ifdef _WIN32

@ -57,12 +57,12 @@ bool DFHack::Filesystem::chdir (std::string path)
std::string DFHack::Filesystem::getcwd () std::string DFHack::Filesystem::getcwd ()
{ {
char *path; char *path;
char buf[LFS_MAXPATHLEN]; char buf[FILENAME_MAX];
std::string result = ""; std::string result = "";
#ifdef _WIN32 #ifdef _WIN32
if ((path = ::_getcwd(buf, LFS_MAXPATHLEN)) != NULL) if ((path = ::_getcwd(buf, FILENAME_MAX)) != NULL)
#else #else
if ((path = ::getcwd(buf, LFS_MAXPATHLEN)) != NULL) if ((path = ::getcwd(buf, FILENAME_MAX)) != NULL)
#endif #endif
result = buf; result = buf;
return result; return result;