Skip to content

Commit

Permalink
Single header for large file i/o support.
Browse files Browse the repository at this point in the history
This also fixes Path::IsFile().
  • Loading branch information
ivan-mogilko committed Aug 19, 2018
1 parent 3b1d304 commit 4820e22
Show file tree
Hide file tree
Showing 77 changed files with 78 additions and 119 deletions.
1 change: 0 additions & 1 deletion Common/ac/messageinfo.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "ac/messageinfo.h"
#include "util/stream.h"

Expand Down
1 change: 0 additions & 1 deletion Common/ac/mousecursor.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "ac/mousecursor.h"
#include "util/stream.h"

Expand Down
1 change: 0 additions & 1 deletion Common/ac/point.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "ac/point.h"
#include "ac/common.h" // quit()
#include "util/stream.h"
Expand Down
1 change: 0 additions & 1 deletion Common/ac/roomstruct.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "ac/roomstruct.h"
#include "ac/common.h"
#include "ac/wordsdictionary.h"
Expand Down
1 change: 1 addition & 0 deletions Common/ac/spritecache.cpp
Expand Up @@ -22,6 +22,7 @@
#pragma warning (disable: 4996 4312) // disable deprecation warnings
#endif

#include <stdio.h> // sprintf
#include "ac/common.h"
#include "ac/spritecache.h"
#include "core/assetmanager.h"
Expand Down
1 change: 0 additions & 1 deletion Common/ac/view.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <stdlib.h>
#include "ac/view.h"
#include "util/alignedstream.h"
Expand Down
1 change: 0 additions & 1 deletion Common/ac/wordsdictionary.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ac/wordsdictionary.h"
Expand Down
1 change: 0 additions & 1 deletion Common/font/fonts.cpp
Expand Up @@ -16,7 +16,6 @@
#define USE_ALFONT
#endif

#include <stdio.h>
#include "alfont.h"

#include "ac/common.h"
Expand Down
1 change: 0 additions & 1 deletion Common/font/ttffontrenderer.cpp
Expand Up @@ -16,7 +16,6 @@
#define USE_ALFONT
#endif

#include <stdio.h>
#include "alfont.h"
#include "ac/gamestructdefines.h" //FONT_OUTLINE_AUTO
#include "core/assetmanager.h"
Expand Down
1 change: 0 additions & 1 deletion Common/script/cc_error.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "cc_error.h"
Expand Down
1 change: 0 additions & 1 deletion Common/script/cc_script.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cc_script.h"
Expand Down
2 changes: 1 addition & 1 deletion Common/util/c99_snprintf.h
Expand Up @@ -26,7 +26,7 @@

#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdio.h> // sprintf

#define snprintf c99_snprintf
#define vsnprintf c99_vsnprintf
Expand Down
2 changes: 0 additions & 2 deletions Common/util/compress.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <stdlib.h>
#include "ac/common.h" // quit()
#include "ac/roomstruct.h"
Expand All @@ -28,7 +27,6 @@

#include "util/misc.h"
#include "util/stream.h"
#include "util/filestream.h"
#include "gfx/bitmap.h"

using namespace AGS::Common;
Expand Down
1 change: 0 additions & 1 deletion Common/util/compress.h
Expand Up @@ -15,7 +15,6 @@
#ifndef __AC_COMPRESS_H
#define __AC_COMPRESS_H

#include <stdio.h>
#include "util/wgt2allg.h" // color (allegro RGB)

namespace AGS { namespace Common { class Stream; class Bitmap; } }
Expand Down
12 changes: 1 addition & 11 deletions Common/util/file.cpp
Expand Up @@ -18,19 +18,9 @@
#include <unistd.h> // for unlink()
#endif
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include "util/file.h"
#include "util/filestream.h"

#if defined(_MSC_VER) // MSVC
#define stat_t _stat64
#define stat_fn _stati64
#else
#define stat_t stat
#define stat_fn stat
#endif

#include "util/stdio_compat.h"

namespace AGS
{
Expand Down
14 changes: 0 additions & 14 deletions Common/util/filestream.cpp
Expand Up @@ -12,23 +12,9 @@
//
//=============================================================================

#include <stdio.h>
#include "util/filestream.h"
#include "util/math.h"

#if defined(HAVE_FSEEKO) // Contemporary POSIX libc
#define file_off_t off_t
#define fseek fseeko
#define ftell ftello
#elif defined(_MSC_VER) // MSVC
#define file_off_t __int64
#define fseek _fseeki64
#define ftell _ftelli64
#else // No distinct interface with off_t
#define file_off_t long
#endif


namespace AGS
{
namespace Common
Expand Down
2 changes: 1 addition & 1 deletion Common/util/filestream.h
Expand Up @@ -18,9 +18,9 @@
#ifndef __AGS_CN_UTIL__FILESTREAM_H
#define __AGS_CN_UTIL__FILESTREAM_H

#include <stdio.h>
#include "util/datastream.h"
#include "util/file.h"
#include "util/stdio_compat.h"

namespace AGS
{
Expand Down
1 change: 0 additions & 1 deletion Common/util/lzw.cpp
Expand Up @@ -18,7 +18,6 @@

#define MSS

#include <stdio.h>
#include <stdlib.h>
#include "ac/common.h"
#include "util/stream.h"
Expand Down
10 changes: 8 additions & 2 deletions Common/util/misc.cpp
Expand Up @@ -41,9 +41,15 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "allegro.h"
#if !defined (WINDOWS_VERSION)
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#endif
#include <allegro.h>
#include "util/misc.h"
#include "util/filestream.h"
#include "util/stdio_compat.h"

using AGS::Common::Stream;

Expand Down
9 changes: 0 additions & 9 deletions Common/util/misc.h
Expand Up @@ -44,15 +44,6 @@
#ifndef __MISC_H
#define __MISC_H

#include <stdio.h>

#if !defined (WINDOWS_VERSION)
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#endif

#include "util/file.h"

namespace AGS { namespace Common { class Stream; } }
Expand Down
13 changes: 6 additions & 7 deletions Common/util/path.cpp
@@ -1,11 +1,10 @@

#include <sys/types.h>
#include <sys/stat.h>
#if defined (WINDOWS_VERSION)
#include <windows.h>
#endif
#include "util/path.h"
#include "allegro/file.h"
#include "util/path.h"
#include "util/stdio_compat.h"

// TODO: implement proper portable path length
#ifndef MAX_PATH
Expand All @@ -22,10 +21,10 @@ namespace Path

bool IsDirectory(const String &filename)
{
struct stat st;
struct stat_t st;
// stat() does not like trailing slashes, remove them
String fixed_path = MakePathNoSlash(filename);
if (stat(fixed_path, &st) == 0)
if (stat_fn(fixed_path, &st) == 0)
{
return (st.st_mode & S_IFMT) == S_IFDIR;
}
Expand All @@ -34,8 +33,8 @@ bool IsDirectory(const String &filename)

bool IsFile(const String &filename)
{
struct stat st;
if (stat(filename, &st) == 0)
struct stat_t st;
if (stat_fn(filename, &st) == 0)
{
return (st.st_mode & S_IFMT) == S_IFREG;
}
Expand Down
43 changes: 43 additions & 0 deletions Common/util/stdio_compat.h
@@ -0,0 +1,43 @@
//=============================================================================
//
// Adventure Game Studio (AGS)
//
// Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
// The full list of copyright holders can be found in the Copyright.txt
// file, which is part of this source code distribution.
//
// The AGS source code is provided under the Artistic License 2.0.
// A copy of this license can be found in the file License.txt and at
// http://www.opensource.org/licenses/artistic-license-2.0.php
//
//=============================================================================
#ifndef __AGS_CN_UTIL__STDIOCOMPAT_H
#define __AGS_CN_UTIL__STDIOCOMPAT_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

// 64-bit fseek/ftell
#if defined(HAVE_FSEEKO) // Contemporary POSIX libc
#define file_off_t off_t
#define fseek fseeko
#define ftell ftello
#elif defined(_MSC_VER) // MSVC
#define file_off_t __int64
#define fseek _fseeki64
#define ftell _ftelli64
#else // No distinct interface with off_t
#define file_off_t long
#endif

// 64-bit stat support for MSVC
#if defined(_MSC_VER) // MSVC
#define stat_t _stat64
#define stat_fn _stati64
#else
#define stat_t stat
#define stat_fn stat
#endif

#endif // __AGS_CN_UTIL__STDIOCOMPAT_H
2 changes: 1 addition & 1 deletion Common/util/string.cpp
Expand Up @@ -12,7 +12,7 @@
//
//=============================================================================

#include <stdio.h>
#include <stdio.h> // sprintf
#include <stdlib.h>
#include <string.h>
#include "debug/assert.h"
Expand Down
1 change: 0 additions & 1 deletion Common/util/string_utils.h
Expand Up @@ -18,7 +18,6 @@
#ifndef __AGS_CN_UTIL__STRINGUTILS_H
#define __AGS_CN_UTIL__STRINGUTILS_H

#include <stdio.h>
#include <stdarg.h>
#include <string.h>

Expand Down
2 changes: 1 addition & 1 deletion Common/util/textstreamwriter.cpp
Expand Up @@ -13,7 +13,7 @@
//=============================================================================

#include <stdarg.h>
#include <stdio.h>
#include <stdio.h> // sprintf
#include "util/textstreamwriter.h"
#include "util/stream.h"

Expand Down
1 change: 0 additions & 1 deletion Engine/ac/dialog.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "ac/dialog.h"
#include "ac/common.h"
#include "ac/character.h"
Expand Down
1 change: 0 additions & 1 deletion Engine/ac/drawingsurface.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "ac/draw.h"
#include "ac/drawingsurface.h"
#include "ac/common.h"
Expand Down
1 change: 0 additions & 1 deletion Engine/ac/dynobj/cc_dynamicarray.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <string.h>
#include "cc_dynamicarray.h"

Expand Down
1 change: 0 additions & 1 deletion Engine/ac/dynobj/cc_dynamicobject.cpp
Expand Up @@ -26,7 +26,6 @@

//#define DEBUG_MANAGED_OBJECTS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ac/dynobj/cc_dynamicobject.h"
Expand Down
1 change: 0 additions & 1 deletion Engine/ac/dynobj/cc_serializer.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <string.h>
#include "ac/dynobj/cc_serializer.h"
#include "ac/dynobj/all_dynamicclasses.h"
Expand Down
1 change: 0 additions & 1 deletion Engine/ac/dynobj/managedobjectpool.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ac/dynobj/managedobjectpool.h"
Expand Down
1 change: 0 additions & 1 deletion Engine/ac/event.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "event.h"
#include "ac/common.h"
#include "ac/draw.h"
Expand Down
2 changes: 1 addition & 1 deletion Engine/ac/game.cpp
Expand Up @@ -81,7 +81,7 @@
#include "script/script_runtime.h"
#include "util/alignedstream.h"
#include "util/directory.h"
#include "util/filestream.h"
#include "util/filestream.h" // TODO: needed only because plugins expect file handle
#include "util/path.h"
#include "util/string_utils.h"

Expand Down
1 change: 0 additions & 1 deletion Engine/ac/global_audio.cpp
Expand Up @@ -12,7 +12,6 @@
//
//=============================================================================

#include <stdio.h>
#include "ac/common.h"
#include "ac/game.h"
#include "ac/gamesetup.h"
Expand Down

0 comments on commit 4820e22

Please sign in to comment.