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,104 +69,76 @@ 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 #else
#include <sys/utime.h> #include <sys/utime.h>
#endif #endif
#include <fcntl.h> #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 #else
#define getcwd_error strerror(errno) #include <unistd.h>
#ifdef _WIN32 #include <dirent.h>
/* MAX_PATH seems to be 260. Seems kind of small. Is there a better one? */ #include <fcntl.h>
#define LFS_MAXPATHLEN MAX_PATH #include <sys/types.h>
#else #include <utime.h>
/* For MAXPATHLEN: */
#include <sys/param.h>
#define LFS_MAXPATHLEN MAXPATHLEN
#endif
#endif #endif
typedef struct dir_data { typedef struct dir_data {
int closed; int closed;
#ifdef _WIN32 #ifdef _WIN32
intptr_t hFile; intptr_t hFile;
char pattern[MAX_PATH+1]; char pattern[MAX_PATH+1];
#else #else
DIR *dir; DIR *dir;
#endif #endif
} dir_data; } dir_data;
#ifdef _WIN32 #ifdef _WIN32
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#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
#else #else
#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
#ifndef S_ISDIR #ifndef S_ISDIR
#define S_ISDIR(mode) (mode&_S_IFDIR) #define S_ISDIR(mode) (mode&_S_IFDIR)
#endif #endif
#ifndef S_ISREG #ifndef S_ISREG
#define S_ISREG(mode) (mode&_S_IFREG) #define S_ISREG(mode) (mode&_S_IFREG)
#endif #endif
#ifndef S_ISLNK #ifndef S_ISLNK
#define S_ISLNK(mode) (0) #define S_ISLNK(mode) (0)
#endif #endif
#ifndef S_ISSOCK #ifndef S_ISSOCK
#define S_ISSOCK(mode) (0) #define S_ISSOCK(mode) (0)
#endif #endif
#ifndef S_ISFIFO #ifndef S_ISFIFO
#define S_ISFIFO(mode) (0) #define S_ISFIFO(mode) (0)
#endif #endif
#ifndef S_ISCHR #ifndef S_ISCHR
#define S_ISCHR(mode) (mode&_S_IFCHR) #define S_ISCHR(mode) (mode&_S_IFCHR)
#endif #endif
#ifndef S_ISBLK #ifndef S_ISBLK
#define S_ISBLK(mode) (0) #define S_ISBLK(mode) (0)
#endif #endif
#endif #endif
enum _filetype { enum _filetype {

@ -57,14 +57,14 @@ 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;
} }