Lines Matching defs:ms
57 file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
62 if (ms->event_flags & EVENT_HAD_ERR)
68 if (ms->o.buf != NULL) {
69 len = asprintf(&newstr, "%s%s", ms->o.buf, buf);
73 free(ms->o.buf);
76 ms->o.buf = buf;
79 file_error(ms, errno, "vasprintf failed");
84 file_printf(struct magic_set *ms, const char *fmt, ...)
90 rv = file_vprintf(ms, fmt, ap);
101 file_error_core(struct magic_set *ms, int error, const char *f, va_list va,
105 if (ms->event_flags & EVENT_HAD_ERR)
108 free(ms->o.buf);
109 ms->o.buf = NULL;
110 file_printf(ms, "line %" SIZE_T_FORMAT "u:", lineno);
112 if (ms->o.buf && *ms->o.buf)
113 file_printf(ms, " ");
114 file_vprintf(ms, f, va);
116 file_printf(ms, " (%s)", strerror(error));
117 ms->event_flags |= EVENT_HAD_ERR;
118 ms->error = error;
123 file_error(struct magic_set *ms, int error, const char *f, ...)
127 file_error_core(ms, error, f, va, 0);
136 file_magerror(struct magic_set *ms, const char *f, ...)
140 file_error_core(ms, 0, f, va, ms->line);
145 file_oomem(struct magic_set *ms, size_t len)
147 file_error(ms, errno, "cannot allocate %" SIZE_T_FORMAT "u bytes",
152 file_badseek(struct magic_set *ms)
154 file_error(ms, errno, "error seeking");
158 file_badread(struct magic_set *ms)
160 file_error(ms, errno, "error reading");
166 checkdone(struct magic_set *ms, int *rv)
168 if ((ms->flags & MAGIC_CONTINUE) == 0)
170 if (file_printf(ms, "\n- ") == -1)
177 file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__unused__)),
199 if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) {
200 looks_text = file_encoding(ms, ubuf, nb, &u8buf, &ulen,
205 if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) {
206 m = file_os2_apptype(ms, inname, buf, nb);
207 if ((ms->flags & MAGIC_DEBUG) != 0)
221 if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) {
222 m = file_zmagic(ms, fd, inname, ubuf, nb);
223 if ((ms->flags & MAGIC_DEBUG) != 0)
231 if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0) {
232 m = file_is_tar(ms, ubuf, nb);
233 if ((ms->flags & MAGIC_DEBUG) != 0)
236 if (checkdone(ms, &rv))
242 if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) {
243 m = file_trycdf(ms, fd, ubuf, nb);
244 if ((ms->flags & MAGIC_DEBUG) != 0)
247 if (checkdone(ms, &rv))
253 if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
254 m = file_softmagic(ms, ubuf, nb, NULL, NULL, BINTEST,
256 if ((ms->flags & MAGIC_DEBUG) != 0)
260 if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 &&
271 m = file_tryelf(ms, fd, ubuf, nb);
272 if ((ms->flags & MAGIC_DEBUG) != 0)
277 if (checkdone(ms, &rv))
282 if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) {
284 m = file_ascmagic(ms, ubuf, nb, looks_text);
285 if ((ms->flags & MAGIC_DEBUG) != 0)
288 if (checkdone(ms, &rv))
296 if (ms->flags & MAGIC_MIME) {
297 if ((ms->flags & MAGIC_MIME_TYPE) &&
298 file_printf(ms, "%s", type) == -1)
300 } else if (ms->flags & MAGIC_APPLE) {
301 if (file_printf(ms, "UNKNUNKN") == -1)
303 } else if (ms->flags & MAGIC_EXTENSION) {
304 if (file_printf(ms, "???") == -1)
307 if (file_printf(ms, "%s", def) == -1)
311 if ((ms->flags & MAGIC_MIME_ENCODING) != 0) {
312 if (ms->flags & MAGIC_MIME_TYPE)
313 if (file_printf(ms, "; charset=") == -1)
315 if (file_printf(ms, "%s", code_mime) == -1)
330 file_reset(struct magic_set *ms)
332 if (ms->mlist[0] == NULL) {
333 file_error(ms, 0, "no magic files loaded");
336 if (ms->o.buf) {
337 free(ms->o.buf);
338 ms->o.buf = NULL;
340 if (ms->o.pbuf) {
341 free(ms->o.pbuf);
342 ms->o.pbuf = NULL;
344 ms->event_flags &= ~EVENT_HAD_ERR;
345 ms->error = -1;
358 file_getbuffer(struct magic_set *ms)
363 if (ms->event_flags & EVENT_HAD_ERR)
366 if (ms->flags & MAGIC_RAW)
367 return ms->o.buf;
369 if (ms->o.buf == NULL)
373 len = strlen(ms->o.buf);
375 file_oomem(ms, len);
379 if ((pbuf = CAST(char *, realloc(ms->o.pbuf, psize))) == NULL) {
380 file_oomem(ms, psize);
383 ms->o.pbuf = pbuf;
394 np = ms->o.pbuf;
395 op = ms->o.buf;
420 return ms->o.pbuf;
424 for (np = ms->o.pbuf, op = ms->o.buf; *op;) {
432 return ms->o.pbuf;
436 file_check_mem(struct magic_set *ms, unsigned int level)
440 if (level >= ms->c.len) {
441 len = (ms->c.len = 20 + level) * sizeof(*ms->c.li);
442 ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ?
444 realloc(ms->c.li, len));
445 if (ms->c.li == NULL) {
446 file_oomem(ms, len);
450 ms->c.li[level].got_match = 0;
452 ms->c.li[level].last_match = 0;
453 ms->c.li[level].last_cond = COND_NONE;
459 file_printedlen(const struct magic_set *ms)
461 return ms->o.buf == NULL ? 0 : strlen(ms->o.buf);
465 file_replace(struct magic_set *ms, const char *pat, const char *rep)
472 file_regerror(&rx, rc, ms);
476 while (file_regexec(&rx, ms->o.buf, 1, &rm, 0) == 0) {
477 ms->o.buf[rm.rm_so] = '\0';
478 if (file_printf(ms, "%s%s", rep,
479 rm.rm_eo != 0 ? ms->o.buf + rm.rm_eo : "") == -1)
528 file_regerror(file_regex_t *rx, int rc, struct magic_set *ms)
533 file_magerror(ms, "regex error %d for `%s', (%s)", rc, rx->pat,
538 file_push_buffer(struct magic_set *ms)
542 if (ms->event_flags & EVENT_HAD_ERR)
548 pb->buf = ms->o.buf;
549 pb->offset = ms->offset;
551 ms->o.buf = NULL;
552 ms->offset = 0;
558 file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb)
562 if (ms->event_flags & EVENT_HAD_ERR) {
568 rbuf = ms->o.buf;
570 ms->o.buf = pb->buf;
571 ms->offset = pb->offset;