PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/php-src/ext/fileinfo/libmagic/print.c

https://gitlab.com/0072016/appengine-php
C | 120 lines | 74 code | 15 blank | 31 comment | 13 complexity | b6a1e9e154c235253f8bcfa2be1126ac MD5 | raw file
  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. #define _GNU_SOURCE
  32. #include "php.h"
  33. #include "file.h"
  34. #include "cdf.h"
  35. #ifndef lint
  36. FILE_RCSID("@(#)$File: print.c,v 1.76 2013/02/26 18:25:00 christos Exp $")
  37. #endif /* lint */
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <stdarg.h>
  41. #include <stdlib.h>
  42. #ifdef HAVE_UNISTD_H
  43. #include <unistd.h>
  44. #endif
  45. #include <time.h>
  46. #ifdef PHP_WIN32
  47. # define asctime_r php_asctime_r
  48. # define ctime_r php_ctime_r
  49. #endif
  50. #define SZOF(a) (sizeof(a) / sizeof(a[0]))
  51. /*VARARGS*/
  52. protected void
  53. file_magwarn(struct magic_set *ms, const char *f, ...)
  54. {
  55. va_list va;
  56. char *expanded_format;
  57. TSRMLS_FETCH();
  58. va_start(va, f);
  59. if (vasprintf(&expanded_format, f, va)); /* silence */
  60. va_end(va);
  61. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format);
  62. free(expanded_format);
  63. }
  64. protected const char *
  65. file_fmttime(uint64_t v, int flags, char *buf)
  66. {
  67. char *pp;
  68. time_t t = (time_t)v;
  69. struct tm *tm;
  70. if (flags & FILE_T_WINDOWS) {
  71. struct timeval ts;
  72. cdf_timestamp_to_timespec(&ts, t);
  73. t = ts.tv_sec;
  74. }
  75. if (flags & FILE_T_LOCAL) {
  76. pp = ctime_r(&t, buf);
  77. } else {
  78. #ifndef HAVE_DAYLIGHT
  79. private int daylight = 0;
  80. #ifdef HAVE_TM_ISDST
  81. private time_t now = (time_t)0;
  82. if (now == (time_t)0) {
  83. struct tm *tm1;
  84. (void)time(&now);
  85. tm1 = localtime(&now);
  86. if (tm1 == NULL)
  87. goto out;
  88. daylight = tm1->tm_isdst;
  89. }
  90. #endif /* HAVE_TM_ISDST */
  91. #endif /* HAVE_DAYLIGHT */
  92. if (daylight)
  93. t += 3600;
  94. tm = gmtime(&t);
  95. if (tm == NULL)
  96. goto out;
  97. pp = asctime_r(tm, buf);
  98. }
  99. if (pp == NULL)
  100. goto out;
  101. pp[strcspn(pp, "\n")] = '\0';
  102. return pp;
  103. out:
  104. return strcpy(buf, "*Invalid time*");
  105. }