| OLD | NEW |
| 1 #include <time.h> | 1 #include <time.h> |
| 2 #include <pthread.h> | 2 #include <pthread.h> |
| 3 #include <errno.h> | 3 #include <errno.h> |
| 4 #include <stdio.h> | 4 #include <stdio.h> |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 int getdate_err; | 7 int getdate_err; |
| 8 | 8 |
| 9 struct tm *getdate(const char *s) | 9 struct tm* getdate(const char* s) { |
| 10 { | 10 static struct tm tmbuf; |
| 11 » static struct tm tmbuf; | 11 struct tm* ret = 0; |
| 12 » struct tm *ret = 0; | 12 char* datemsk = getenv("DATEMSK"); |
| 13 » char *datemsk = getenv("DATEMSK"); | 13 FILE* f = 0; |
| 14 » FILE *f = 0; | 14 char fmt[100], *p; |
| 15 » char fmt[100], *p; | 15 int cs; |
| 16 » int cs; | |
| 17 | 16 |
| 18 » pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED, &cs); | 17 pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED, &cs); |
| 19 | 18 |
| 20 » if (!datemsk) { | 19 if (!datemsk) { |
| 21 » » getdate_err = 1; | 20 getdate_err = 1; |
| 22 » » goto out; | 21 goto out; |
| 23 » } | 22 } |
| 24 | 23 |
| 25 » f = fopen(datemsk, "rbe"); | 24 f = fopen(datemsk, "rbe"); |
| 26 » if (!f) { | 25 if (!f) { |
| 27 » » if (errno == ENOMEM) getdate_err = 6; | 26 if (errno == ENOMEM) |
| 28 » » else getdate_err = 2; | 27 getdate_err = 6; |
| 29 » » goto out; | 28 else |
| 30 » } | 29 getdate_err = 2; |
| 30 goto out; |
| 31 } |
| 31 | 32 |
| 32 » while (fgets(fmt, sizeof fmt, f)) { | 33 while (fgets(fmt, sizeof fmt, f)) { |
| 33 » » p = strptime(s, fmt, &tmbuf); | 34 p = strptime(s, fmt, &tmbuf); |
| 34 » » if (p && !*p) { | 35 if (p && !*p) { |
| 35 » » » ret = &tmbuf; | 36 ret = &tmbuf; |
| 36 » » » goto out; | 37 goto out; |
| 37 » » } | 38 } |
| 38 » } | 39 } |
| 39 | 40 |
| 40 » getdate_err = 7; | 41 getdate_err = 7; |
| 41 out: | 42 out: |
| 42 » if (f) fclose(f); | 43 if (f) |
| 43 » pthread_setcancelstate(cs, 0); | 44 fclose(f); |
| 44 » return ret; | 45 pthread_setcancelstate(cs, 0); |
| 46 return ret; |
| 45 } | 47 } |
| OLD | NEW |