Skip to content

Commit 6c50092

Browse files
Merge pull request #111 from olehermanse/gmtime
Fixed error in gmtime example
2 parents d957c15 + 00c552f commit 6c50092

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// BAD: using gmtime
22
int is_morning_bad() {
3-
struct tm *now = gmtime(time(NULL));
3+
const time_t now_seconds = time(NULL);
4+
struct tm *now = gmtime(&now_seconds);
45
return (now->tm_hour < 12);
56
}
67

78
// GOOD: using gmtime_r
89
int is_morning_good() {
10+
const time_t now_seconds = time(NULL);
911
struct tm now;
10-
gmtime_r(time(NULL), &now);
12+
gmtime_r(&now_seconds, &now);
1113
return (now.tm_hour < 12);
1214
}

0 commit comments

Comments
 (0)