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

Fixed a bug in pthread_cond_timedwait #179

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/c.lib_rev.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define REVISION 0
#define SUBREVISION 0

#define DATE "23.05.2024"
#define DATE "28.05.2024"
#define VERS "clib4.library 1.0.0"
#define VSTRING "clib4.library 1.0.0 (23.05.2024)\r\n"
#define VERSTAG "\0$VER: clib4.library 1.0.0 (23.05.2024)"
#define VSTRING "clib4.library 1.0.0 (28.05.2024)\r\n"
#define VERSTAG "\0$VER: clib4.library 1.0.0 (28.05.2024)"
8 changes: 4 additions & 4 deletions library/include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct timespec64 {
{ \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
if ((result)->tv_usec >= 1000000) \
if ((int32) ((result)->tv_usec) >= 1000000) \
{ \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
Expand All @@ -113,7 +113,7 @@ struct timespec64 {
{ \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) \
if ((int32) ((result)->tv_usec) < 0) \
{ \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
Expand All @@ -129,7 +129,7 @@ struct timespec64 {
{ \
(result)->Seconds = (a)->Seconds + (b)->Seconds; \
(result)->Microseconds = (a)->Microseconds + (b)->Microseconds; \
if ((result)->Microseconds >= 1000000) \
if ((int32) ((result)->Microseconds) >= 1000000) \
{ \
++(result)->Seconds; \
(result)->Microseconds -= 1000000; \
Expand All @@ -140,7 +140,7 @@ struct timespec64 {
{ \
(result)->Seconds = (a)->Seconds - (b)->Seconds; \
(result)->Microseconds = (a)->Microseconds - (b)->Microseconds; \
if ((result)->Microseconds < 0) \
if ((int32) ((result)->Microseconds) < 0) \
{ \
--(result)->Seconds; \
(result)->Microseconds += 1000000; \
Expand Down
1 change: 1 addition & 0 deletions library/stdio/gets.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ gets(char *s) {
file->iob_BufferPosition += num_characters_in_line;
s[num_characters_in_line] = 0;
/* And that concludes the line read operation. */
(*s) = '\0';
goto out;
}

Expand Down
42 changes: 5 additions & 37 deletions library/time/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#endif /* _UNISTD_HEADERS_H */

int
gettimeofday(struct timeval *tp, struct timezone *tzp) {
gettimeofday(struct timeval *tv, struct timezone *tzp) {
struct _clib4 *__clib4 = __CLIB4;
int32 gmtoffset = 0;
int8 dstime = -1;
Expand All @@ -31,7 +31,7 @@ gettimeofday(struct timeval *tp, struct timezone *tzp) {
ENTER();

if (!__clib4->__ITimer) {
tp->tv_sec = tp->tv_usec = tzp->tz_minuteswest = tzp->tz_dsttime = 0;
tv->tv_sec = tv->tv_usec = tzp->tz_minuteswest = tzp->tz_dsttime = 0;
RETURN(0);
}

Expand All @@ -40,44 +40,12 @@ gettimeofday(struct timeval *tp, struct timezone *tzp) {
GetTimezoneAttrs(NULL, TZA_UTCOffset, &gmtoffset, TZA_TimeFlag, &dstime, TAG_DONE);

/* Obtain the current system time. */
#if defined(__NEW_TIMEVAL_DEFINITION_USED__)
{
struct TimeVal tv;

GetSysTime(&tv);

seconds = tv.Seconds;
microseconds = tv.Microseconds;
}
#else
{
struct timeval tv;

GetSysTime(&tv);

seconds = tv.tv_sec;
microseconds = tv.tv_usec;
}
#endif /* __NEW_TIMEVAL_DEFINITION_USED__ */
GetSysTime((struct TimeVal *) tv);

ReleaseSemaphore(__clib4->__timer_semaphore);

/* Convert the number of seconds so that they match the Unix epoch, which
starts (January 1st, 1970) eight years before the AmigaOS epoch. */
seconds += UNIX_TIME_OFFSET;

/* If possible, adjust for the local time zone. We do this because the
AmigaOS system time is returned in local time and we want to return
it in UTC. */
seconds += 60 * gmtoffset;

if (tp != NULL) {
tp->tv_sec = (long) seconds;
tp->tv_usec = (long) microseconds;

SHOWVALUE(tp->tv_sec);
SHOWVALUE(tp->tv_usec);
}
/* 2922 is the number of days between 1.1.1970 and 1.1.1978 */
tv->tv_sec += (2922 * 24 * 60 + gmtoffset) * 60;

if (tzp != NULL) {
tzp->tz_minuteswest = gmtoffset;
Expand Down
19 changes: 7 additions & 12 deletions library/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@

time_t
time(time_t *tptr) {
struct DateStamp ds;
time_t result;

DateStamp(&ds);
struct timeval now;

/* This converts the DateStamp contents into the number of
seconds elapsed since January 1st 1970. The time is
given as relative to UTC, not local time. */
result = __convert_datestamp_to_time(&ds);

if (tptr != NULL)
(*tptr) = result;

return (result);
if (gettimeofday(&now, (struct timezone *) 0) >= 0) {
if (tptr)
*tptr = now.tv_sec;
return now.tv_sec;
}
return -1;
}