Back to index

php5  5.3.10
print.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) Ian F. Darwin 1986-1995.
00003  * Software written by Ian F. Darwin and others;
00004  * maintained 1995-present by Christos Zoulas and others.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice immediately at the beginning of the file, without modification,
00011  *    this list of conditions, and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  *  
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00017  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
00020  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00022  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00023  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00024  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00025  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00026  * SUCH DAMAGE.
00027  */
00028 /*
00029  * print.c - debugging printout routines
00030  */
00031 
00032 #include "php.h"
00033 #include "main/snprintf.h"
00034 
00035 #include "file.h"
00036 
00037 #ifndef lint
00038 FILE_RCSID("@(#)$File: print.c,v 1.66 2009/02/03 20:27:51 christos Exp $")
00039 #endif  /* lint */
00040 
00041 #include <string.h>
00042 #include <stdarg.h>
00043 #include <stdlib.h>
00044 #ifdef HAVE_UNISTD_H
00045 #include <unistd.h>
00046 #endif
00047 #include <time.h>
00048 
00049 #define SZOF(a)      (sizeof(a) / sizeof(a[0]))
00050 
00051 /*VARARGS*/
00052 protected void
00053 file_magwarn(struct magic_set *ms, const char *f, ...)
00054 {
00055        va_list va;
00056        char *expanded_format;
00057        TSRMLS_FETCH();
00058 
00059        va_start(va, f);
00060        vasprintf(&expanded_format, f, va);
00061        va_end(va);
00062        
00063        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format);
00064 
00065        free(expanded_format);
00066 }
00067 
00068 protected const char *
00069 file_fmttime(uint32_t v, int local)
00070 {
00071        char *pp;
00072        time_t t = (time_t)v;
00073        struct tm *tm;
00074 
00075        if (local) {
00076               pp = ctime(&t);
00077        } else {
00078 #ifndef HAVE_DAYLIGHT
00079               private int daylight = 0;
00080 #ifdef HAVE_TM_ISDST
00081               private time_t now = (time_t)0;
00082 
00083               if (now == (time_t)0) {
00084                      struct tm *tm1;
00085                      (void)time(&now);
00086                      tm1 = localtime(&now);
00087                      if (tm1 == NULL)
00088                             return "*Invalid time*";
00089                      daylight = tm1->tm_isdst;
00090               }
00091 #endif /* HAVE_TM_ISDST */
00092 #endif /* HAVE_DAYLIGHT */
00093               if (daylight)
00094                      t += 3600;
00095               tm = gmtime(&t);
00096               if (tm == NULL)
00097                      return "*Invalid time*";
00098               pp = asctime(tm);
00099        }
00100 
00101        pp[strcspn(pp, "\n")] = '\0';
00102        return pp;
00103 }