diff options
author | Andrey Nazarov <skuller@skuller.net> | 2012-11-12 18:17:44 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2012-11-12 18:17:44 +0400 |
commit | 681f6dc2a30d7d24d7f9c40e5b4a6e2cd5b97c78 (patch) | |
tree | b6c5a3d13bf192044630cbb39c650aed132558b3 | |
parent | 5ae5fa3733e1291a88beb6413f771ee8c32f1c2b (diff) |
Move OS-specific defines into appropriate header.
Also define os_access() and its mode flags.
-rw-r--r-- | inc/shared/platform.h | 61 | ||||
-rw-r--r-- | src/common/files.c | 32 |
2 files changed, 63 insertions, 30 deletions
diff --git a/inc/shared/platform.h b/inc/shared/platform.h index a7c8cb8..2f19deb 100644 --- a/inc/shared/platform.h +++ b/inc/shared/platform.h @@ -1,3 +1,35 @@ +/* +Copyright (C) 2012 Andrey Nazarov + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +// +// platform.h -- platform-specific definitions +// + +#include <sys/types.h> +#include <sys/stat.h> + +#ifdef _WIN32 +#include <io.h> +#include <direct.h> +#else +#include <unistd.h> +#endif + #ifdef _WIN32 #define PRIz "Iu" #else @@ -18,6 +50,35 @@ #define PATH_SEP_STRING "/" #endif +#ifdef _WIN32 +#define os_mkdir(p) _mkdir(p) +#define os_unlink(p) _unlink(p) +#define os_stat(p, s) _stat(p, s) +#define os_fstat(f, s) _fstat(f, s) +#define os_fileno(f) _fileno(f) +#define os_access(p, m) _access(p, m) +#define Q_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +#define Q_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) +#define Q_STATBUF struct _stat +#else +#define os_mkdir(p) mkdir(p, 0775) +#define os_unlink(p) unlink(p) +#define os_stat(p, s) stat(p, s) +#define os_fstat(f, s) fstat(f, s) +#define os_fileno(f) fileno(f) +#define os_access(p, m) access(p, m) +#define Q_ISREG(m) S_ISREG(m) +#define Q_ISDIR(m) S_ISDIR(m) +#define Q_STATBUF struct stat +#endif + +#ifndef F_OK +#define F_OK 0 +#define X_OK 1 +#define W_OK 2 +#define R_OK 4 +#endif + #ifdef __GNUC__ #define q_printf(f, a) __attribute__((format(printf, f, a))) diff --git a/src/common/files.c b/src/common/files.c index b29b928..7fc142b 100644 --- a/src/common/files.c +++ b/src/common/files.c @@ -26,40 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/client.h" #include "format/pak.h" -#include <sys/types.h> -#include <sys/stat.h> #include <fcntl.h> -#ifdef _WIN32 -#include <io.h> -#include <direct.h> -#else -#include <unistd.h> -#endif #if USE_ZLIB #include <zlib.h> #endif -#ifdef _WIN32 -#define os_mkdir(p) _mkdir(p) -#define os_unlink(p) _unlink(p) -#define os_stat(p, s) _stat(p, s) -#define os_fstat(f, s) _fstat(f, s) -#define os_fileno(f) _fileno(f) -#define Q_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) -#define Q_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -typedef struct _stat os_stat_t; -#else -#define os_mkdir(p) mkdir(p, 0775) -#define os_unlink(p) unlink(p) -#define os_stat(p, s) stat(p, s) -#define os_fstat(f, s) fstat(f, s) -#define os_fileno(f) fileno(f) -#define Q_ISREG(m) S_ISREG(m) -#define Q_ISDIR(m) S_ISDIR(m) -typedef struct stat os_stat_t; -#endif - /* ============================================================================= @@ -784,7 +756,7 @@ void FS_FCloseFile(qhandle_t f) static qerror_t get_path_info(const char *path, file_info_t *info) { - os_stat_t st; + Q_STATBUF st; if (os_stat(path, &st) == -1) return Q_Errno(); @@ -806,7 +778,7 @@ static qerror_t get_path_info(const char *path, file_info_t *info) static qerror_t get_fp_info(FILE *fp, file_info_t *info) { - os_stat_t st; + Q_STATBUF st; int fd; fd = os_fileno(fp); |