Lines Matching refs:ms
67 file_clearbuf(struct magic_set *ms) in file_clearbuf() argument
69 efree(ms->o.buf); in file_clearbuf()
70 ms->o.buf = NULL; in file_clearbuf()
71 ms->o.blen = 0; in file_clearbuf()
133 file_vprintf(struct magic_set *ms, const char *fmt, va_list ap) in file_vprintf() argument
139 if (ms->event_flags & EVENT_HAD_ERR) in file_vprintf()
143 file_clearbuf(ms); in file_vprintf()
144 file_error(ms, 0, "Bad magic format `%s' (%s)", fmt, tbuf); in file_vprintf()
149 if (len > 1024 || len + ms->o.blen > 1024 * 1024) { in file_vprintf()
150 size_t blen = ms->o.blen; in file_vprintf()
152 file_clearbuf(ms); in file_vprintf()
153 file_error(ms, 0, "Output buffer space exceeded %" SIZE_T_FORMAT "u+%" in file_vprintf()
158 if (ms->o.buf != NULL) { in file_vprintf()
159 len = spprintf(&newstr, 0, "%s%s", ms->o.buf, buf); in file_vprintf()
161 efree(ms->o.buf); in file_vprintf()
164 ms->o.buf = buf; in file_vprintf()
165 ms->o.blen = len; in file_vprintf()
170 file_printf(struct magic_set *ms, const char *fmt, ...) in file_printf() argument
176 rv = file_vprintf(ms, fmt, ap); in file_printf()
187 file_error_core(struct magic_set *ms, int error, const char *f, va_list va, in file_error_core() argument
191 if (ms->event_flags & EVENT_HAD_ERR) in file_error_core()
194 file_clearbuf(ms); in file_error_core()
195 (void)file_printf(ms, "line %" SIZE_T_FORMAT "u:", lineno); in file_error_core()
197 if (ms->o.buf && *ms->o.buf) in file_error_core()
198 (void)file_printf(ms, " "); in file_error_core()
199 (void)file_vprintf(ms, f, va); in file_error_core()
201 (void)file_printf(ms, " (%s)", strerror(error)); in file_error_core()
202 ms->event_flags |= EVENT_HAD_ERR; in file_error_core()
203 ms->error = error; in file_error_core()
208 file_error(struct magic_set *ms, int error, const char *f, ...) in file_error() argument
212 file_error_core(ms, error, f, va, 0); in file_error()
221 file_magerror(struct magic_set *ms, const char *f, ...) in file_magerror() argument
225 file_error_core(ms, 0, f, va, ms->line); in file_magerror()
230 file_oomem(struct magic_set *ms, size_t len) in file_oomem() argument
232 file_error(ms, errno, "cannot allocate %" SIZE_T_FORMAT "u bytes", in file_oomem()
237 file_badseek(struct magic_set *ms) in file_badseek() argument
239 file_error(ms, errno, "error seeking"); in file_badseek()
243 file_badread(struct magic_set *ms) in file_badread() argument
245 file_error(ms, errno, "error reading"); in file_badread()
252 file_separator(struct magic_set *ms) in file_separator() argument
254 return file_printf(ms, FILE_SEPARATOR); in file_separator()
258 trim_separator(struct magic_set *ms) in trim_separator() argument
262 if (ms->o.buf == NULL) in trim_separator()
265 l = strlen(ms->o.buf); in trim_separator()
270 if (strcmp(ms->o.buf + l, FILE_SEPARATOR) != 0) in trim_separator()
273 ms->o.buf[l] = '\0'; in trim_separator()
277 checkdone(struct magic_set *ms, int *rv) in checkdone() argument
279 if ((ms->flags & MAGIC_CONTINUE) == 0) in checkdone()
281 if (file_separator(ms) == -1) in checkdone()
287 file_default(struct magic_set *ms, size_t nb) in file_default() argument
289 if (ms->flags & MAGIC_MIME) { in file_default()
290 if ((ms->flags & MAGIC_MIME_TYPE) && in file_default()
291 file_printf(ms, "application/%s", in file_default()
296 if (ms->flags & MAGIC_APPLE) { in file_default()
297 if (file_printf(ms, "UNKNUNKN") == -1) in file_default()
301 if (ms->flags & MAGIC_EXTENSION) { in file_default()
302 if (file_printf(ms, "???") == -1) in file_default()
317 file_buffer(struct magic_set *ms, php_stream *stream, zend_stat_t *st, in file_buffer() argument
343 ms->mode = b.st.st_mode; in file_buffer()
353 if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) { in file_buffer()
354 looks_text = file_encoding(ms, &b, NULL, 0, in file_buffer()
359 if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) { in file_buffer()
360 m = file_os2_apptype(ms, inname, &b); in file_buffer()
361 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
376 if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) { in file_buffer()
377 m = file_zmagic(ms, &b, inname); in file_buffer()
378 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
386 if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0) { in file_buffer()
387 m = file_is_tar(ms, &b); in file_buffer()
388 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
391 if (checkdone(ms, &rv)) in file_buffer()
397 if ((ms->flags & MAGIC_NO_CHECK_JSON) == 0) { in file_buffer()
398 m = file_is_json(ms, &b); in file_buffer()
399 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
402 if (checkdone(ms, &rv)) in file_buffer()
408 if ((ms->flags & MAGIC_NO_CHECK_CSV) == 0) { in file_buffer()
409 m = file_is_csv(ms, &b, looks_text, code); in file_buffer()
410 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
413 if (checkdone(ms, &rv)) in file_buffer()
419 if ((ms->flags & MAGIC_NO_CHECK_SIMH) == 0) { in file_buffer()
420 m = file_is_simh(ms, &b); in file_buffer()
421 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
424 if (checkdone(ms, &rv)) in file_buffer()
430 if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) { in file_buffer()
431 m = file_trycdf(ms, &b); in file_buffer()
432 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
435 if (checkdone(ms, &rv)) in file_buffer()
440 if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && nb > 5 && fd != -1) { in file_buffer()
452 if ((pb = file_push_buffer(ms)) == NULL) in file_buffer()
455 rv = file_tryelf(ms, &b); in file_buffer()
456 rbuf = file_pop_buffer(ms, pb); in file_buffer()
461 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
467 if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0) { in file_buffer()
468 m = file_softmagic(ms, &b, NULL, NULL, BINTEST, looks_text); in file_buffer()
469 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
472 if (file_printf(ms, "%s", rbuf) == -1) in file_buffer()
476 if (checkdone(ms, &rv)) in file_buffer()
482 if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) { in file_buffer()
484 m = file_ascmagic(ms, &b, looks_text); in file_buffer()
485 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
496 rv = file_default(ms, nb); in file_buffer()
498 if (file_printf(ms, "%s", def) == -1) in file_buffer()
502 trim_separator(ms); in file_buffer()
503 if ((ms->flags & MAGIC_MIME_ENCODING) != 0) { in file_buffer()
504 if (ms->flags & MAGIC_MIME_TYPE) in file_buffer()
505 if (file_printf(ms, "; charset=") == -1) in file_buffer()
507 if (file_printf(ms, "%s", code_mime) == -1) in file_buffer()
523 file_reset(struct magic_set *ms, int checkloaded) in file_reset() argument
525 if (checkloaded && ms->mlist[0] == NULL) { in file_reset()
526 file_error(ms, 0, "no magic files loaded"); in file_reset()
529 file_clearbuf(ms); in file_reset()
530 if (ms->o.pbuf) { in file_reset()
531 efree(ms->o.pbuf); in file_reset()
532 ms->o.pbuf = NULL; in file_reset()
534 ms->event_flags &= ~EVENT_HAD_ERR; in file_reset()
535 ms->error = -1; in file_reset()
548 file_getbuffer(struct magic_set *ms) in file_getbuffer() argument
553 if (ms->event_flags & EVENT_HAD_ERR) in file_getbuffer()
556 if (ms->flags & MAGIC_RAW) in file_getbuffer()
557 return ms->o.buf; in file_getbuffer()
559 if (ms->o.buf == NULL) in file_getbuffer()
563 len = strlen(ms->o.buf); in file_getbuffer()
565 file_oomem(ms, len); in file_getbuffer()
569 if ((pbuf = CAST(char *, erealloc(ms->o.pbuf, psize))) == NULL) { in file_getbuffer()
570 file_oomem(ms, psize); in file_getbuffer()
573 ms->o.pbuf = pbuf; in file_getbuffer()
584 np = ms->o.pbuf; in file_getbuffer()
585 op = ms->o.buf; in file_getbuffer()
610 return ms->o.pbuf; in file_getbuffer()
614 for (np = ms->o.pbuf, op = ms->o.buf; *op;) { in file_getbuffer()
622 return ms->o.pbuf; in file_getbuffer()
626 file_check_mem(struct magic_set *ms, unsigned int level) in file_check_mem() argument
630 if (level >= ms->c.len) { in file_check_mem()
631 len = (ms->c.len = 20 + level) * sizeof(*ms->c.li); in file_check_mem()
632 ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ? in file_check_mem()
634 erealloc(ms->c.li, len)); in file_check_mem()
635 if (ms->c.li == NULL) { in file_check_mem()
636 file_oomem(ms, len); in file_check_mem()
640 ms->c.li[level].got_match = 0; in file_check_mem()
642 ms->c.li[level].last_match = 0; in file_check_mem()
643 ms->c.li[level].last_cond = COND_NONE; in file_check_mem()
649 file_printedlen(const struct magic_set *ms) in file_printedlen() argument
651 return ms->o.blen; in file_printedlen()
655 file_replace(struct magic_set *ms, const char *pat, const char *rep) in file_replace() argument
674 res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), repl, -1, &rep_cnt); in file_replace()
682 memcpy(ms->o.buf, ZSTR_VAL(res), ZSTR_LEN(res)); in file_replace()
683 ms->o.buf[ZSTR_LEN(res)] = '\0'; in file_replace()
692 file_push_buffer(struct magic_set *ms) in file_push_buffer() argument
696 if (ms->event_flags & EVENT_HAD_ERR) in file_push_buffer()
702 pb->buf = ms->o.buf; in file_push_buffer()
703 pb->blen = ms->o.blen; in file_push_buffer()
704 pb->offset = ms->offset; in file_push_buffer()
706 ms->o.buf = NULL; in file_push_buffer()
707 ms->o.blen = 0; in file_push_buffer()
708 ms->offset = 0; in file_push_buffer()
714 file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) in file_pop_buffer() argument
718 if (ms->event_flags & EVENT_HAD_ERR) { in file_pop_buffer()
724 rbuf = ms->o.buf; in file_pop_buffer()
726 ms->o.buf = pb->buf; in file_pop_buffer()
727 ms->o.blen = pb->blen; in file_pop_buffer()
728 ms->offset = pb->offset; in file_pop_buffer()
738 file_printable(struct magic_set *ms, char *buf, size_t bufsiz, in file_printable() argument
746 if ((ms->flags & MAGIC_RAW) != 0 || isprint(*s)) { in file_printable()