Lines Matching refs:ms
68 file_clearbuf(struct magic_set *ms) in file_clearbuf() argument
70 efree(ms->o.buf); in file_clearbuf()
71 ms->o.buf = NULL; in file_clearbuf()
72 ms->o.blen = 0; in file_clearbuf()
130 file_printf(struct magic_set *ms, const char *fmt, ...) in file_printf() argument
139 if (ms->o.buf != NULL) { in file_printf()
140 spprintf(&newstr, 0, "%s%s", ms->o.buf, (buf ? buf : "")); in file_printf()
144 efree(ms->o.buf); in file_printf()
145 ms->o.buf = newstr; in file_printf()
147 ms->o.buf = buf; in file_printf()
157 file_error_core(struct magic_set *ms, int error, const char *f, va_list va, in file_error_core() argument
163 if (ms->event_flags & EVENT_HAD_ERR) in file_error_core()
166 efree(ms->o.buf); in file_error_core()
167 ms->o.buf = NULL; in file_error_core()
168 file_printf(ms, "line %" SIZE_T_FORMAT "u:", lineno); in file_error_core()
175 file_printf(ms, "%s (%s)", (*buf ? buf : ""), strerror(error)); in file_error_core()
177 file_printf(ms, "%s", buf); in file_error_core()
184 ms->event_flags |= EVENT_HAD_ERR; in file_error_core()
185 ms->error = error; in file_error_core()
190 file_error(struct magic_set *ms, int error, const char *f, ...) in file_error() argument
194 file_error_core(ms, error, f, va, 0); in file_error()
203 file_magerror(struct magic_set *ms, const char *f, ...) in file_magerror() argument
207 file_error_core(ms, 0, f, va, ms->line); in file_magerror()
212 file_oomem(struct magic_set *ms, size_t len) in file_oomem() argument
214 file_error(ms, errno, "cannot allocate %" SIZE_T_FORMAT "u bytes", in file_oomem()
219 file_badseek(struct magic_set *ms) in file_badseek() argument
221 file_error(ms, errno, "error seeking"); in file_badseek()
225 file_badread(struct magic_set *ms) in file_badread() argument
227 file_error(ms, errno, "error reading"); in file_badread()
233 file_separator(struct magic_set *ms) in file_separator() argument
235 return file_printf(ms, "\n- "); in file_separator()
239 checkdone(struct magic_set *ms, int *rv) in checkdone() argument
241 if ((ms->flags & MAGIC_CONTINUE) == 0) in checkdone()
243 if (file_separator(ms) == -1) in checkdone()
249 file_default(struct magic_set *ms, size_t nb) in file_default() argument
251 if (ms->flags & MAGIC_MIME) { in file_default()
252 if ((ms->flags & MAGIC_MIME_TYPE) && in file_default()
253 file_printf(ms, "application/%s", in file_default()
258 if (ms->flags & MAGIC_APPLE) { in file_default()
259 if (file_printf(ms, "UNKNUNKN") == -1) in file_default()
263 if (ms->flags & MAGIC_EXTENSION) { in file_default()
264 if (file_printf(ms, "???") == -1) in file_default()
279 file_buffer(struct magic_set *ms, php_stream *stream, zend_stat_t *st, in file_buffer() argument
305 ms->mode = b.st.st_mode; in file_buffer()
315 if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) { in file_buffer()
316 looks_text = file_encoding(ms, &b, NULL, 0, in file_buffer()
321 if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) { in file_buffer()
322 m = file_os2_apptype(ms, inname, &b); in file_buffer()
323 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
338 if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) { in file_buffer()
339 m = file_zmagic(ms, &b, inname); in file_buffer()
340 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
348 if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0) { in file_buffer()
349 m = file_is_tar(ms, &b); in file_buffer()
350 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
353 if (checkdone(ms, &rv)) in file_buffer()
359 if ((ms->flags & MAGIC_NO_CHECK_JSON) == 0) { in file_buffer()
360 m = file_is_json(ms, &b); in file_buffer()
361 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
364 if (checkdone(ms, &rv)) in file_buffer()
370 if ((ms->flags & MAGIC_NO_CHECK_CSV) == 0) { in file_buffer()
371 m = file_is_csv(ms, &b, looks_text); in file_buffer()
372 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
375 if (checkdone(ms, &rv)) in file_buffer()
381 if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) { in file_buffer()
382 m = file_trycdf(ms, &b); in file_buffer()
383 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
386 if (checkdone(ms, &rv)) in file_buffer()
391 if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && nb > 5 && fd != -1) { in file_buffer()
403 if ((pb = file_push_buffer(ms)) == NULL) in file_buffer()
406 rv = file_tryelf(ms, &b); in file_buffer()
407 rbuf = file_pop_buffer(ms, pb); in file_buffer()
412 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
418 if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0) { in file_buffer()
419 m = file_softmagic(ms, &b, NULL, NULL, BINTEST, looks_text); in file_buffer()
420 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
423 if (file_printf(ms, "%s", rbuf) == -1) in file_buffer()
427 if (checkdone(ms, &rv)) in file_buffer()
433 if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) { in file_buffer()
435 m = file_ascmagic(ms, &b, looks_text); in file_buffer()
436 if ((ms->flags & MAGIC_DEBUG) != 0) in file_buffer()
447 rv = file_default(ms, nb); in file_buffer()
449 if (file_printf(ms, "%s", def) == -1) in file_buffer()
453 if ((ms->flags & MAGIC_MIME_ENCODING) != 0) { in file_buffer()
454 if (ms->flags & MAGIC_MIME_TYPE) in file_buffer()
455 if (file_printf(ms, "; charset=") == -1) in file_buffer()
457 if (file_printf(ms, "%s", code_mime) == -1) in file_buffer()
473 file_reset(struct magic_set *ms, int checkloaded) in file_reset() argument
475 if (checkloaded && ms->mlist[0] == NULL) { in file_reset()
476 file_error(ms, 0, "no magic files loaded"); in file_reset()
479 file_clearbuf(ms); in file_reset()
480 if (ms->o.pbuf) { in file_reset()
481 efree(ms->o.pbuf); in file_reset()
482 ms->o.pbuf = NULL; in file_reset()
484 ms->event_flags &= ~EVENT_HAD_ERR; in file_reset()
485 ms->error = -1; in file_reset()
498 file_getbuffer(struct magic_set *ms) in file_getbuffer() argument
503 if (ms->event_flags & EVENT_HAD_ERR) in file_getbuffer()
506 if (ms->flags & MAGIC_RAW) in file_getbuffer()
507 return ms->o.buf; in file_getbuffer()
509 if (ms->o.buf == NULL) in file_getbuffer()
513 len = strlen(ms->o.buf); in file_getbuffer()
515 file_oomem(ms, len); in file_getbuffer()
519 if ((pbuf = CAST(char *, erealloc(ms->o.pbuf, psize))) == NULL) { in file_getbuffer()
520 file_oomem(ms, psize); in file_getbuffer()
523 ms->o.pbuf = pbuf; in file_getbuffer()
534 np = ms->o.pbuf; in file_getbuffer()
535 op = ms->o.buf; in file_getbuffer()
560 return ms->o.pbuf; in file_getbuffer()
564 for (np = ms->o.pbuf, op = ms->o.buf; *op;) { in file_getbuffer()
572 return ms->o.pbuf; in file_getbuffer()
576 file_check_mem(struct magic_set *ms, unsigned int level) in file_check_mem() argument
580 if (level >= ms->c.len) { in file_check_mem()
581 len = (ms->c.len = 20 + level) * sizeof(*ms->c.li); in file_check_mem()
582 ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ? in file_check_mem()
584 erealloc(ms->c.li, len)); in file_check_mem()
585 if (ms->c.li == NULL) { in file_check_mem()
586 file_oomem(ms, len); in file_check_mem()
590 ms->c.li[level].got_match = 0; in file_check_mem()
592 ms->c.li[level].last_match = 0; in file_check_mem()
593 ms->c.li[level].last_cond = COND_NONE; in file_check_mem()
599 file_printedlen(const struct magic_set *ms) in file_printedlen() argument
601 return ms->o.buf == NULL ? 0 : strlen(ms->o.buf); in file_printedlen()
605 file_replace(struct magic_set *ms, const char *pat, const char *rep) in file_replace() argument
624 res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), repl, -1, &rep_cnt); in file_replace()
632 strncpy(ms->o.buf, ZSTR_VAL(res), ZSTR_LEN(res)); in file_replace()
633 ms->o.buf[ZSTR_LEN(res)] = '\0'; in file_replace()
642 file_push_buffer(struct magic_set *ms) in file_push_buffer() argument
646 if (ms->event_flags & EVENT_HAD_ERR) in file_push_buffer()
652 pb->buf = ms->o.buf; in file_push_buffer()
653 pb->blen = ms->o.blen; in file_push_buffer()
654 pb->offset = ms->offset; in file_push_buffer()
656 ms->o.buf = NULL; in file_push_buffer()
657 ms->o.blen = 0; in file_push_buffer()
658 ms->offset = 0; in file_push_buffer()
664 file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) in file_pop_buffer() argument
668 if (ms->event_flags & EVENT_HAD_ERR) { in file_pop_buffer()
674 rbuf = ms->o.buf; in file_pop_buffer()
676 ms->o.buf = pb->buf; in file_pop_buffer()
677 ms->o.blen = pb->blen; in file_pop_buffer()
678 ms->offset = pb->offset; in file_pop_buffer()