Skip to content

Commit

Permalink
Changed the naming of some code, implementing time function, incomple…
Browse files Browse the repository at this point in the history
…te. Temporary storage.
  • Loading branch information
ax-6 committed Aug 5, 2024
1 parent 1765e14 commit 6da8f81
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 19 deletions.
8 changes: 4 additions & 4 deletions aqvm/base/file/identifier/unix/identifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ int AqvmBaseFileIdentifierUnix_GetIdentifier(const char* filename,
return -1;
}

struct stat file_info;
struct stat st;

if (stat(filename, &file_info) != 0) {
if (stat(filename, &st) != 0) {
// TODO
return -2;
}

identifier->st_dev = file_info.st_dev;
identifier->st_ino = file_info.st_ino;
identifier->st_dev = st.st_dev;
identifier->st_ino = st.st_ino;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion aqvm/base/file/windows/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

HANDLE AqvmBaseFileWindows_FileToHandle(struct AqvmBaseFile_File* file) {
HANDLE AqvmBaseFileWindows_ConvertFileToHandle(struct AqvmBaseFile_File* file) {
HANDLE handle = (HANDLE)_get_osfhandle(_fileno(file->file));
if (handle == INVALID_HANDLE_VALUE) {
// TODO
Expand Down
4 changes: 2 additions & 2 deletions aqvm/base/file/windows/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

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

HANDLE AqvmBaseFileWindows_FileToHandle(struct AqvmBaseFile_File* file);
HANDLE AqvmBaseFileWindows_ConvertFileToHandle(struct AqvmBaseFile_File* file);

// fopen freopen setbuf tmpfile tmpnam vsprintf
// fopen freopen setbuf tmpfile tmpnam vsprintf

#endif
#endif
12 changes: 6 additions & 6 deletions aqvm/base/process/file_lock/unix/file_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ int AqvmBaseProcessFileLockUnix_LockFile(struct AqvmBaseFile_File* file) {
return -2;
}

int file_descriptor = fileno(file->file);
if (file_descriptor == -1) {
int fd = fileno(file->file);
if (fd == -1) {
return -3;
}

Expand All @@ -32,7 +32,7 @@ int AqvmBaseProcessFileLockUnix_LockFile(struct AqvmBaseFile_File* file) {



if (fcntl(file_descriptor, F_SETLK, &file_lock) == -1) {
if (fcntl(fd, F_SETLK, &file_lock) == -1) {
printf("%i",errno);
return -4;
}
Expand All @@ -49,15 +49,15 @@ int AqvmBaseProcessFileLockUnix_UnlockFile(struct AqvmBaseFile_File* file) {
return -2;
}

int file_descriptor = fileno(file->file);
if (file_descriptor == -1) {
int fd = fileno(file->file);
if (fd == -1) {
return -3;
}

struct flock file_lock = {0};
file_lock.l_type = F_UNLCK;

if (fcntl(file_descriptor, F_SETLK, &file_lock) == -1) {
if (fcntl(fd, F_SETLK, &file_lock) == -1) {
// TODO
return -4;
}
Expand Down
4 changes: 2 additions & 2 deletions aqvm/base/process/file_lock/windows/file_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int AqvmBaseProcessFileLockWindows_LockFile(struct AqvmBaseFile_File* file) {
return -1;
}

HANDLE handle_file = AqvmBaseFileWindows_FileToHandle(file);
HANDLE handle_file = AqvmBaseFileWindows_ConvertFileToHandle(file);
if (handle_file == INVALID_HANDLE_VALUE) {
// TODO
return -2;
Expand All @@ -35,7 +35,7 @@ int AqvmBaseProcessFileLockWindows_UnlockFile(struct AqvmBaseFile_File* file) {
return -1;
}

HANDLE handle_file = AqvmBaseFileWindows_FileToHandle(file);
HANDLE handle_file = AqvmBaseFileWindows_ConvertFileToHandle(file);
if (handle_file == INVALID_HANDLE_VALUE) {
// TODO
return -2;
Expand Down
52 changes: 49 additions & 3 deletions aqvm/base/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
#endif

int AqvmBaseTime_localtime(const time_t timestamp, struct tm* result) {
if (result == NULL) {
// TODO
return -1;
}

#ifdef __unix__
if (AqvmBaseTimeUnix_localtime(timestamp, result) != 0) {
// TODO
return -1;
return -2;
}
#elif _WIN32
if (AqvmBaseTimeWindows_localtime(timestamp, result) != 0) {
// TODO
return -2;
return -3;
}
#else
// TODO
Expand All @@ -32,14 +37,55 @@ int AqvmBaseTime_localtime(const time_t timestamp, struct tm* result) {
"The localtime function may cause thread unsafety.", NULL);
struct tm* local_time = localtime(&timestamp);
if (local_time == NULL) {
return -2;
return -4;
}
*result = *local_time;
#endif

return 0;
}

int AqvmBaseTime_GetCurrentTime(struct AqvmBaseTime_Time* result) {
if (result == NULL) {
// TODO
return -1;
}

#ifdef __unix__
if (AqvmBaseTimeUnix_GetCurrentTime(result) != 0) {
// TODO
return -2;
}
#elif _WIN32
if (AqvmBaseTimeWindows_GetCurrentTime(result) != 0) {
// TODO
return -3;
}
#else
struct tm local_time;
if (AqvmBaseTime_localtime(time(NULL), &local_time) != 0) {
// TODO
return -4;
}
result->year = local_time.tm_year + 1900;
result->month = local_time.tm_mon + 1;
result->day = local_time.tm_mday;
result->hour = local_time.tm_hour;
result->minute = local_time.tm_min;
result->second = local_time.tm_sec;
result->millisecond = 0;
result->weekday = local_time.tm_wday;
result->yearday = local_time.tm_yday;
result->isdst = local_time.tm_isdst;
#endif

return 0;
}

int AqvmBaseTime_ConvertTmToTime(){

}

int AqvmBaseTime_GetCurrentTimeString(char* result) {
if (result == NULL) {
// TODO
Expand Down
18 changes: 17 additions & 1 deletion aqvm/base/time/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@
#define AQ_AQVM_BASE_TIME_TIME_H_

#include <time.h>
#include <stdbool.h>

struct AqvmBaseTime_Time {
int year;
int month;
int day;
int hour;
int minute;
int second;
int millisecond;
int weekday;
int yearday;
int isdst;
};

int AqvmBaseTime_localtime(const time_t timestamp, struct tm* result);

int AqvmBaseTime_GetCurrentTime(struct AqvmBaseTime_Time* result);

int AqvmBaseTime_ConvertTmToTime(char* result);

// Get the current time. The current time is then formatted as an ISO 8601
// compliant string and written to |result|. |result| must not be NULL and must
// be at least 28 characters in length. Returns 0 if successful.
Expand Down
22 changes: 22 additions & 0 deletions aqvm/base/time/unix/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "aqvm/base/time/unix/time.h"

#include <sys/time.h>
#include <time.h>

#include "aqvm/base/logging/logging.h"
Expand All @@ -17,4 +18,25 @@ int AqvmBaseTimeUnix_localtime(const time_t timestamp, struct tm* result) {
}
return 0;
}

int AqvmBaseTimeUnix_GetCurrentTime(struct AqvmBaseTime_Time* result) {
if (result == NULL) {
// TODO
return -1;
}
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
struct timespec ts;
if (clock_gettime(CLOCK_REALTIME, &ts) != 0) {
// TODO
return -2;
}
#else
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0) {
// TODO
return -3;
}
#endif
return 0;
}
#endif
4 changes: 4 additions & 0 deletions aqvm/base/time/unix/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#include <time.h>

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

int AqvmBaseTimeUnix_localtime(const time_t timestamp, struct tm* result);

int AqvmBaseTimeUnix_GetCurrentTime(struct AqvmBaseTime_Time* result);

#endif
#endif
4 changes: 4 additions & 0 deletions aqvm/base/time/windows/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ int AqvmBaseTimeWindows_localtime(const time_t timestamp, struct tm* result) {
}
return 0;
}

int AqvmBaseTimeWindows_GetCurrentTime(struct AqvmBaseTime_Time* result){
return 0;
}
#endif
4 changes: 4 additions & 0 deletions aqvm/base/time/windows/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#include <time.h>

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

int AqvmBaseTimeWindows_localtime(const time_t timestamp, struct tm* result);

int AqvmBaseTimeWindows_GetCurrentTime(struct AqvmBaseTime_Time* result);

#endif
#endif

0 comments on commit 6da8f81

Please sign in to comment.