Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log4zFileHandler::open不支持单个2GB以上的文件 #66

Open
alongL opened this issue Aug 31, 2020 · 0 comments
Open

Log4zFileHandler::open不支持单个2GB以上的文件 #66

alongL opened this issue Aug 31, 2020 · 0 comments

Comments

@alongL
Copy link

alongL commented Aug 31, 2020

ftell 和fseek只支持返回 long ,就是32位,最大2GB文件,超过2GB的文件会返回-1。

inline long open(const char *path, const char * mod)
    {
        if (_file != NULL){fclose(_file);_file = NULL;}
        _file = fopen(path, mod);
        if (_file)
        {
            long tel = 0;
            long cur = ftell(_file);
            fseek(_file, 0L, SEEK_END);
            tel = ftell(_file);
            fseek(_file, cur, SEEK_SET);
            return tel;
        }
        return -1;
    }

可以改成:
同时要修改相关变量的数据类型 int型到int64_t

	inline int64_t open64(const char *path, const char * mod)
	{
		if (_file != NULL) { fclose(_file); _file = NULL; }
		_file = fopen(path, mod);
		if (_file)
		{
			
#ifdef WIN32
#define ftell64  _ftelli64 
#define fseek64  _fseeki64
#else
#define ftell64  ftello64 
#define fseek64  fseeko64
#endif
			//along 支持2G以上的文件
			int64_t tel = 0;
			auto cur = ftell64(_file);
			fseek64(_file, 0L, SEEK_END);
			tel = ftell64(_file);
			fseek64(_file, cur, SEEK_SET);
			return tel;
		}
		return -1;
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant