Annotation of embedaddon/php/ext/fileinfo/libmagic/print.c, revision 1.1.1.2
1.1 misho 1: /*
2: * Copyright (c) Ian F. Darwin 1986-1995.
3: * Software written by Ian F. Darwin and others;
4: * maintained 1995-present by Christos Zoulas and others.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice immediately at the beginning of the file, without modification,
11: * this list of conditions, and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26: * SUCH DAMAGE.
27: */
28: /*
29: * print.c - debugging printout routines
30: */
31:
1.1.1.2 ! misho 32: #define _GNU_SOURCE
1.1 misho 33: #include "php.h"
34:
35: #include "file.h"
36:
37: #ifndef lint
1.1.1.2 ! misho 38: FILE_RCSID("@(#)$File: print.c,v 1.71 2011/09/20 15:28:09 christos Exp $")
1.1 misho 39: #endif /* lint */
40:
1.1.1.2 ! misho 41: #include <stdio.h>
1.1 misho 42: #include <string.h>
43: #include <stdarg.h>
44: #include <stdlib.h>
45: #ifdef HAVE_UNISTD_H
46: #include <unistd.h>
47: #endif
48: #include <time.h>
49:
50: #define SZOF(a) (sizeof(a) / sizeof(a[0]))
51:
52: /*VARARGS*/
53: protected void
54: file_magwarn(struct magic_set *ms, const char *f, ...)
55: {
56: va_list va;
57: char *expanded_format;
58: TSRMLS_FETCH();
59:
60: va_start(va, f);
61: vasprintf(&expanded_format, f, va);
62: va_end(va);
63:
64: php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format);
65:
66: free(expanded_format);
67: }
68:
69: protected const char *
70: file_fmttime(uint32_t v, int local)
71: {
72: char *pp;
73: time_t t = (time_t)v;
74: struct tm *tm;
75:
76: if (local) {
77: pp = ctime(&t);
78: } else {
79: #ifndef HAVE_DAYLIGHT
80: private int daylight = 0;
81: #ifdef HAVE_TM_ISDST
82: private time_t now = (time_t)0;
83:
84: if (now == (time_t)0) {
85: struct tm *tm1;
86: (void)time(&now);
87: tm1 = localtime(&now);
88: if (tm1 == NULL)
1.1.1.2 ! misho 89: goto out;
1.1 misho 90: daylight = tm1->tm_isdst;
91: }
92: #endif /* HAVE_TM_ISDST */
93: #endif /* HAVE_DAYLIGHT */
94: if (daylight)
95: t += 3600;
96: tm = gmtime(&t);
97: if (tm == NULL)
1.1.1.2 ! misho 98: goto out;
1.1 misho 99: pp = asctime(tm);
100: }
101:
1.1.1.2 ! misho 102: if (pp == NULL)
! 103: goto out;
1.1 misho 104: pp[strcspn(pp, "\n")] = '\0';
105: return pp;
1.1.1.2 ! misho 106: out:
! 107: return "*Invalid time*";
1.1 misho 108: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>