From: Alan Cox Date: Fri, 2 Jan 2015 21:50:47 +0000 (+0000) Subject: time: threadsafe functions X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b4db4c77f427503d1e04a66e8747cb585d917383;p=FUZIX.git time: threadsafe functions Not much use at the moment but since many modern apps favour them anyway we might as well provide them given they are pretty much zero cost. --- diff --git a/Library/include/time.h b/Library/include/time.h index 2c8a5798..8a3d2730 100644 --- a/Library/include/time.h +++ b/Library/include/time.h @@ -39,17 +39,18 @@ extern clock_t clock __P ((void)); extern time_t mktime __P ((struct tm * __tp)); extern double difftime __P ((time_t *__time2, time_t *__time1)); -extern time_t *gtime(time_t *tvec); extern void __tm_conv __P((struct tm *tmbuf, time_t *t, int offset)); -extern void __asctime __P((char *, struct tm *)); extern char *asctime __P ((struct tm * __tp)); +extern char *asctime_r __P((struct tm *, char * __buf)); extern char *ctime __P ((time_t * __tp)); +extern char *ctime_r __P ((time_t * __tp, char * __buf)); extern void tzset __P ((void)); extern struct tm *gmtime __P ((time_t *__tp)); extern struct tm *localtime __P ((time_t * __tp)); -extern unsigned long convtime __P ((time_t *time_field)); +extern struct tm *gmtime_r(time_t *tvec, struct tm *result); +extern struct tm *localtime_r(time_t *tvec, struct tm *result); typedef int clockid_t; diff --git a/Library/libs/Makefile b/Library/libs/Makefile index 28acf62b..dd8d66a5 100644 --- a/Library/libs/Makefile +++ b/Library/libs/Makefile @@ -21,9 +21,9 @@ SRC_C += fgetpos.c fgets.c fopen.c fprintf.c fputc.c fputs.c fread.c free.c SRC_C += fsetpos.c ftell.c fwrite.c getcwd.c SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getopt.c SRC_C += getpw.c __getpwent.c getpwnam.c getpwuid.c gets.c gettimeofday.c -SRC_C += gmtime.c grent.c index.c isatty.c itoa.c killpg.c -SRC_C += localtim.c lseek.c lsearch.c lstat.c ltoa.c ltostr.c malloc.c -SRC_C += mkfifo.c nanosleep.c opendir.c pause.c perror.c +SRC_C += gmtime.c gmtime_r.c grent.c index.c isatty.c itoa.c killpg.c +SRC_C += localtim.c localtim_r.c lseek.c lsearch.c lstat.c ltoa.c ltostr.c +SRC_C += malloc.c mkfifo.c nanosleep.c opendir.c pause.c perror.c SRC_C += popen.c printf.c putenv.c putgetch.c putpwent.c pwent.c qsort.c SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c setjmp.c diff --git a/Library/libs/asctime.c b/Library/libs/asctime.c index 9170fcc0..1f6caa83 100644 --- a/Library/libs/asctime.c +++ b/Library/libs/asctime.c @@ -16,7 +16,7 @@ static void hit(char *buf, int val) static char days[] = "SunMonTueWedThuFriSat"; static char mons[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; -void __asctime(char *buffer, struct tm *ptm) +char *asctime_r(struct tm *ptm, char *buffer) { int year; @@ -38,6 +38,7 @@ void __asctime(char *buffer, struct tm *ptm) hit(buffer + 21, year / 100); hit(buffer + 22, year / 10); hit(buffer + 23, year); + return buffer; } /* asctime - convert date and time to ascii. @@ -49,6 +50,5 @@ char *asctime(struct tm *timeptr) if (timeptr == 0) return 0; - __asctime(timebuf, timeptr); - return timebuf; + return asctime_r(timeptr, timebuf); } diff --git a/Library/libs/ctime_r.c b/Library/libs/ctime_r.c new file mode 100644 index 00000000..59760044 --- /dev/null +++ b/Library/libs/ctime_r.c @@ -0,0 +1,10 @@ +/*************************** CTIME ************************************/ + +#include +#include + +char *ctime_r(time_t * timep, char *buf) +{ + struct tm tmtmp; + return asctime_r(localtime_r(timep, &tmtmp), buf); +} diff --git a/Library/libs/gmtime_r.c b/Library/libs/gmtime_r.c new file mode 100644 index 00000000..c8f2ebeb --- /dev/null +++ b/Library/libs/gmtime_r.c @@ -0,0 +1,10 @@ +/*************************** GMTIME ************************************/ + +#include +#include + +struct tm *gmtime_r(time_t *timep, struct tm *result) +{ + __tm_conv(result, timep, (int) (timezone / 60)); + return result; +} diff --git a/Library/libs/localtim_r.c b/Library/libs/localtim_r.c new file mode 100644 index 00000000..04bad7a6 --- /dev/null +++ b/Library/libs/localtim_r.c @@ -0,0 +1,8 @@ +#include +#include + +struct tm *localtime_r(time_t * timep, struct tm *result) +{ + __tm_conv(result, timep, 0); + return result; +}