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

@ -49,17 +49,18 @@ SOFTWARE.
#include "Export.h" #include "Export.h"
#ifndef _WIN32 #ifndef _WIN32
#ifndef _AIX #ifndef _AIX
#define _FILE_OFFSET_BITS 64 /* Linux, Solaris and HP-UX */ #define _FILE_OFFSET_BITS 64 /* Linux, Solaris and HP-UX */
#else #else
#define _LARGE_FILES 1 /* AIX */ #define _LARGE_FILES 1 /* AIX */
#endif #endif
#endif #endif
#ifndef _LARGEFILE64_SOURCE #ifndef _LARGEFILE64_SOURCE
#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>
@ -68,51 +69,23 @@ SOFTWARE.
#include <sys/stat.h> #include <sys/stat.h>
#ifdef _WIN32 #ifdef _WIN32
#include <direct.h> #include <direct.h>
#define NOMINMAX #define NOMINMAX
#include <windows.h> #include <windows.h>
#include <io.h> #include <io.h>
#include <sys/locking.h> #include <sys/locking.h>
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#include <utime.h> #include <utime.h>
#else
#include <sys/utime.h>
#endif
#include <fcntl.h>
#else
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <utime.h>
#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 #else
/* For MAXPATHLEN: */ #include <sys/utime.h>
#include <sys/param.h>
#define LFS_MAXPATHLEN MAXPATHLEN
#endif #endif
#include <fcntl.h>
#else
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <utime.h>
#endif #endif
typedef struct dir_data { typedef struct dir_data {
@ -133,15 +106,15 @@ typedef struct dir_data {
#define lfs_setmode(L,file,m) ((void)L, _setmode(_fileno(file), m)) #define lfs_setmode(L,file,m) ((void)L, _setmode(_fileno(file), m))
#define STAT_STRUCT struct _stati64 #define STAT_STRUCT struct _stati64
#endif #endif
#define STAT_FUNC _stati64 #define STAT_FUNC _stati64
#define LSTAT_FUNC STAT_FUNC #define LSTAT_FUNC STAT_FUNC
#else #else
#define _O_TEXT 0 #define _O_TEXT 0
#define _O_BINARY 0 #define _O_BINARY 0
#define lfs_setmode(L,file,m) ((void)L, (void)file, (void)m, 0) #define lfs_setmode(L,file,m) ((void)L, (void)file, (void)m, 0)
#define STAT_STRUCT struct stat #define STAT_STRUCT struct stat
#define STAT_FUNC stat #define STAT_FUNC stat
#define LSTAT_FUNC lstat #define LSTAT_FUNC lstat
#endif #endif
#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;