Skip to content

Commit 65ffdc2

Browse files
committed
Fixed bug #77576 pull the libmagic implementation of gmtime_r
PHP already has all the checks to handle the *_r function variants. Thus, reusing it to get right symbols.
1 parent 58cb331 commit 65ffdc2

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

ext/fileinfo/libmagic/cdf_time.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424
* POSSIBILITY OF SUCH DAMAGE.
2525
*/
26+
#include "php.h"
2627

2728
#include "file.h"
2829

@@ -152,7 +153,7 @@ cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timespec *ts)
152153
#endif
153154
#ifdef notyet
154155
struct tm tm;
155-
if (gmtime_r(&ts->ts_sec, &tm) == NULL) {
156+
if (php_gmtime_r(&ts->ts_sec, &tm) == NULL) {
156157
errno = EINVAL;
157158
return -1;
158159
}
@@ -168,7 +169,7 @@ cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timespec *ts)
168169
char *
169170
cdf_ctime(const time_t *sec, char *buf)
170171
{
171-
char *ptr = ctime_r(sec, buf);
172+
char *ptr = php_ctime_r(sec, buf);
172173
if (ptr != NULL)
173174
return buf;
174175
(void)snprintf(buf, 26, "*Bad* %#16.16" INT64_T_FORMAT "x\n",

ext/fileinfo/libmagic/print.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
/*
2929
* print.c - debugging printout routines
3030
*/
31-
#define _GNU_SOURCE
3231
#include "php.h"
3332

3433
#include "file.h"
@@ -45,11 +44,6 @@ FILE_RCSID("@(#)$File: print.c,v 1.82 2017/02/10 18:14:01 christos Exp $")
4544
#endif
4645
#include <time.h>
4746

48-
#ifdef PHP_WIN32
49-
# define asctime_r php_asctime_r
50-
# define ctime_r php_ctime_r
51-
#endif
52-
5347
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
5448

5549
#include "cdf.h"
@@ -240,8 +234,8 @@ protected const char *
240234
file_fmttime(uint64_t v, int flags, char *buf)
241235
{
242236
char *pp;
243-
time_t t = (time_t)v;
244-
struct tm *tm = NULL;
237+
time_t t;
238+
struct tm *tm, tmz;
245239

246240
if (flags & FILE_T_WINDOWS) {
247241
struct timespec ts;
@@ -254,33 +248,13 @@ file_fmttime(uint64_t v, int flags, char *buf)
254248
}
255249

256250
if (flags & FILE_T_LOCAL) {
257-
pp = ctime_r(&t, buf);
251+
tm = php_localtime_r(&t, &tmz);
258252
} else {
259-
#ifndef HAVE_DAYLIGHT
260-
private int daylight = 0;
261-
#ifdef HAVE_TM_ISDST
262-
private time_t now = (time_t)0;
263-
264-
if (now == (time_t)0) {
265-
struct tm *tm1;
266-
(void)time(&now);
267-
tm1 = localtime(&now);
268-
if (tm1 == NULL)
269-
goto out;
270-
daylight = tm1->tm_isdst;
271-
}
272-
#endif /* HAVE_TM_ISDST */
273-
#endif /* HAVE_DAYLIGHT */
274-
if (daylight)
275-
t += 3600;
276-
tm = gmtime(&t);
277-
if (tm == NULL)
278-
goto out;
279-
pp = asctime_r(tm, buf);
253+
tm = php_gmtime_r(&t, &tmz);
280254
}
281255
if (tm == NULL)
282256
goto out;
283-
pp = asctime_r(tm, buf);
257+
pp = php_asctime_r(tm, buf);
284258

285259
if (pp == NULL)
286260
goto out;

0 commit comments

Comments
 (0)