Skip to content

Commit

Permalink
Streamlined file, file_id and io related related functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-6 committed Aug 1, 2024
1 parent 494686f commit 905170e
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 341 deletions.
32 changes: 16 additions & 16 deletions aqvm/base/file/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int AqvmBaseFile_UnlockFile(struct AqvmBaseFile_File* file) {
}

void AqvmBaseFile_clearerr(struct AqvmBaseFile_File* stream) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return;
}
Expand All @@ -48,7 +48,7 @@ void AqvmBaseFile_clearerr(struct AqvmBaseFile_File* stream) {
}

int AqvmBaseFile_fclose(struct AqvmBaseFile_File* stream) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return -1;
}
Expand All @@ -70,7 +70,7 @@ int AqvmBaseFile_fclose(struct AqvmBaseFile_File* stream) {
}

int AqvmBaseFile_feof(struct AqvmBaseFile_File* stream) {
if (stream == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return -1;
}
Expand All @@ -90,7 +90,7 @@ int AqvmBaseFile_ferror(struct AqvmBaseFile_File* stream) {
}

int AqvmBaseFile_fflush(struct AqvmBaseFile_File* stream) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return -1;
}
Expand All @@ -116,7 +116,7 @@ int AqvmBaseFile_fflush(struct AqvmBaseFile_File* stream) {
}

int AqvmBaseFile_fgetpos(struct AqvmBaseFile_File* stream, fpos_t* pos) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) ||
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0 ||
pos == NULL) {
// TODO
return -1;
Expand Down Expand Up @@ -156,7 +156,7 @@ struct AqvmBaseFile_File* AqvmBaseFile_fopen(const char* filename,
}

stream->file = fopen(filename, mode);
if (stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
free(stream);
// TODO
return NULL;
Expand All @@ -174,7 +174,7 @@ struct AqvmBaseFile_File* AqvmBaseFile_fopen(const char* filename,
size_t AqvmBaseFile_fread(void* ptr, size_t size, size_t nmemb,
struct AqvmBaseFile_File* stream) {
if (ptr == NULL || stream == NULL || stream->file == NULL ||
AqvmBaseFile_ferror(stream)) {
AqvmBaseFile_ferror(stream) != 0) {
// TODO
return 0;
}
Expand All @@ -197,7 +197,7 @@ size_t AqvmBaseFile_fread(void* ptr, size_t size, size_t nmemb,
struct AqvmBaseFile_File* AqvmBaseFile_freopen(
const char* filename, const char* mode, struct AqvmBaseFile_File* stream) {
if (filename == NULL || mode == NULL || stream == NULL ||
stream->file == NULL || AqvmBaseFile_ferror(stream)) {
stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return NULL;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ struct AqvmBaseFile_File* AqvmBaseFile_freopen(

int AqvmBaseFile_fseek(struct AqvmBaseFile_File* stream, long int offset,
int whence) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return -1;
}
Expand All @@ -255,7 +255,7 @@ int AqvmBaseFile_fseek(struct AqvmBaseFile_File* stream, long int offset,
}

int AqvmBaseFile_fsetpos(struct AqvmBaseFile_File* stream, const fpos_t* pos) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) ||
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0 ||
pos == NULL) {
// TODO
return -1;
Expand All @@ -282,7 +282,7 @@ int AqvmBaseFile_fsetpos(struct AqvmBaseFile_File* stream, const fpos_t* pos) {
}

long int AqvmBaseFile_ftell(struct AqvmBaseFile_File* stream) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return -1L;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ long int AqvmBaseFile_ftell(struct AqvmBaseFile_File* stream) {
size_t AqvmBaseFile_fwrite(const void* ptr, size_t size, size_t nmemb,
struct AqvmBaseFile_File* stream) {
if (ptr == NULL || stream == NULL || stream->file == NULL ||
AqvmBaseFile_ferror(stream)) {
AqvmBaseFile_ferror(stream) != 0) {
// TODO
return 0;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ int AqvmBaseFile_rename(const char* old_filename, const char* new_filename) {
}

void AqvmBaseFile_rewind(struct AqvmBaseFile_File* stream) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return;
}
Expand All @@ -377,7 +377,7 @@ void AqvmBaseFile_rewind(struct AqvmBaseFile_File* stream) {
}

void AqvmBaseFile_setbuf(struct AqvmBaseFile_File* stream, char* buffer) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return;
}
Expand All @@ -396,7 +396,7 @@ void AqvmBaseFile_setbuf(struct AqvmBaseFile_File* stream, char* buffer) {

int AqvmBaseFile_setvbuf(struct AqvmBaseFile_File* stream, char* buffer,
int mode, size_t size) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream == NULL || stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
// TODO
return -1;
}
Expand Down Expand Up @@ -430,7 +430,7 @@ struct AqvmBaseFile_File* AqvmBaseFile_tmpfile(void) {
}

stream->file = tmpfile();
if (stream->file == NULL || AqvmBaseFile_ferror(stream)) {
if (stream->file == NULL || AqvmBaseFile_ferror(stream) != 0) {
free(stream);
// TODO
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions aqvm/base/file/file_id/file_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int AqvmBaseFileFileId_GetFileId(const char* filename,
return -2;
}
#elif _WIN32
if (AqvmBaseFileFileIdUnix_GetFileId(filename, file_id) != 0) {
if (AqvmBaseFileFileIdWindows_GetFileId(filename, file_id) != 0) {
// TODO
return -3;
}
Expand All @@ -48,7 +48,7 @@ uint32_t AqvmBaseFileFileId_GetFileIdHash(AqvmBaseFileFileId_FileId* file_id) {
#ifdef __unix__
return AqvmBaseFileFileIdUnix_GetFileIdHash(file_id);
#elif _WIN32
return AqvmBaseFileFileIdUnix_GetFileIdHash(file_id);
return AqvmBaseFileFileIdWindows_GetFileIdHash(file_id);
#else
// TODO
return 0;
Expand Down
8 changes: 5 additions & 3 deletions aqvm/base/file/file_id/windows/file_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <windows.h>

#include "aqvm/base/hash/hash.h"

int AqvmBaseFileFileIdWindows_GetFileId(
const char* filename, AqvmBaseFileFileIdWindows_FileId* file_id) {
if (filename == NULL || file_id == NULL) {
Expand All @@ -23,9 +25,9 @@ int AqvmBaseFileFileIdWindows_GetFileId(

BY_HANDLE_FILE_INFORMATION file_info;
if (GetFileInformationByHandle(handle_file, &file_info)) {
file_id.dwVolumeSerialNumber = file_info.dwVolumeSerialNumber;
file_id.nFileIndexHigh = file_info.nFileIndexHigh;
file_id.nFileIndexLow = file_info.nFileIndexLow;
file_id->dwVolumeSerialNumber = file_info.dwVolumeSerialNumber;
file_id->nFileIndexHigh = file_info.nFileIndexHigh;
file_id->nFileIndexLow = file_info.nFileIndexLow;
} else {
// TODO
return -3;
Expand Down
2 changes: 2 additions & 0 deletions aqvm/base/file/windows/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@

HANDLE AqvmBaseFileWindows_FileToHandle(struct AqvmBaseFile_File* file);

// fopen freopen setbuf tmpfile tmpnam vsprintf

#endif
#endif
Loading

0 comments on commit 905170e

Please sign in to comment.