Automatic save file creation.

This commit is contained in:
sorgelig
2018-11-21 07:28:07 +08:00
parent f7cef9475a
commit c63bc586f7
4 changed files with 81 additions and 19 deletions

View File

@@ -65,7 +65,7 @@ int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute)
char *p = strrchr(full_path, '/');
strcpy(file->name, (mode == -1) ? full_path : p+1);
file->fd = (mode == -1) ? shm_open("/vtrd", O_CREAT | O_RDWR | O_TRUNC, 0777) : open(full_path, mode);
file->fd = (mode == -1) ? shm_open("/vtrd", O_CREAT | O_RDWR | O_TRUNC, 0777) : open(full_path, mode, 0777);
if (file->fd <= 0)
{
if(!mute) printf("FileOpenEx(open) File:%s, error: %d.\n", full_path, file->fd);
@@ -100,6 +100,15 @@ int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute)
return 1;
}
__off64_t FileGetSize(fileTYPE *file)
{
if (file->fd <= 0) return 0;
struct stat64 st;
int ret = fstat64(file->fd, &st);
return (ret < 0) ? 0 : st.st_size;
}
int FileOpen(fileTYPE *file, const char *name, char mute)
{
return FileOpenEx(file, name, O_RDONLY, mute);