Lines Matching +full:1 +full:ms

8  * 1. Redistributions of source code must retain the above copyright
102 if (access(tmppath, R_OK) == -1)
131 dllpath = calloc(MAX_PATH + 1, sizeof(*dllpath));
169 return 1;
193 if (stat(hmagicpath, &st) == -1) {
197 if (stat(hmagicpath, &st) == -1)
203 if (access(hmagicpath, R_OK) == -1)
273 unreadable_info(struct magic_set *ms, mode_t md, const char *file)
278 if (file_printf(ms, "writable, ") == -1)
279 return -1;
282 if (file_printf(ms, "executable, ") == -1)
283 return -1;
285 /* X_OK doesn't work well on MS-Windows */
292 if (file_printf(ms, "writable, ") == -1)
293 return -1;
298 if (file_printf(ms, "regular file, ") == -1)
299 return -1;
300 if (file_printf(ms, "no read permission") == -1)
301 return -1;
306 magic_close(struct magic_set *ms)
308 if (ms == NULL)
310 file_ms_free(ms);
317 magic_load(struct magic_set *ms, const char *magicfile)
319 if (ms == NULL)
320 return -1;
321 return file_apprentice(ms, magicfile, FILE_LOAD);
329 magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes,
332 if (ms == NULL)
333 return -1;
334 return buffer_apprentice(ms, RCAST(struct magic **, bufs),
340 magic_compile(struct magic_set *ms, const char *magicfile)
342 if (ms == NULL)
343 return -1;
344 return file_apprentice(ms, magicfile, FILE_COMPILE);
348 magic_check(struct magic_set *ms, const char *magicfile)
350 if (ms == NULL)
351 return -1;
352 return file_apprentice(ms, magicfile, FILE_CHECK);
356 magic_list(struct magic_set *ms, const char *magicfile)
358 if (ms == NULL)
359 return -1;
360 return file_apprentice(ms, magicfile, FILE_LIST);
364 close_and_restore(const struct magic_set *ms, const char *name, int fd,
371 if ((ms->flags & MAGIC_PRESERVE_ATIME) != 0) {
382 utsbuf[1].tv_sec = sb->st_mtime;
402 magic_descriptor(struct magic_set *ms, int fd)
404 if (ms == NULL)
406 return file_or_fd(ms, NULL, fd);
413 magic_file(struct magic_set *ms, const char *inname)
415 if (ms == NULL)
417 return file_or_fd(ms, inname, STDIN_FILENO);
421 file_or_fd(struct magic_set *ms, const char *inname, int fd)
423 int rv = -1;
429 off_t pos = CAST(off_t, -1);
431 if (file_reset(ms, 1) == -1)
438 #define SLOP (1 + sizeof(union VALUETYPE))
439 if ((buf = CAST(unsigned char *, malloc(ms->bytes_max + SLOP))) == NULL)
442 switch (file_fsmagic(ms, inname, &sb)) {
443 case -1: /* error */
471 okstat = 1;
475 unreadable_info(ms, sb.st_mode, inname) == -1)
485 if (fd != -1) {
488 ispipe = 1;
494 * try looking at the first ms->bytes_max bytes
497 if (fd != -1) {
501 CAST(size_t, ms->bytes_max - nbytes), 1)) > 0) {
509 if (unreadable_info(ms, sb.st_mode, inname) == -1)
515 } else if (fd != -1) {
521 ms->bytes_max;
522 if ((nbytes = read(fd, RCAST(void *, buf), howmany)) == -1) {
524 file_error(ms, errno, "cannot read fd %d", fd);
526 file_error(ms, errno, "cannot read `%s'",
533 if (file_buffer(ms, fd, okstat ? &sb : NULL, inname, buf, CAST(size_t, nbytes)) == -1)
538 if (fd != -1) {
539 if (pos != CAST(off_t, -1))
541 close_and_restore(ms, inname, fd, &sb);
544 return rv == 0 ? file_getbuffer(ms) : NULL;
549 magic_buffer(struct magic_set *ms, const void *buf, size_t nb)
551 if (ms == NULL)
553 if (file_reset(ms, 1) == -1)
559 if (file_buffer(ms, -1, NULL, NULL, buf, nb) == -1) {
562 return file_getbuffer(ms);
567 magic_error(struct magic_set *ms)
569 if (ms == NULL)
571 return (ms->event_flags & EVENT_HAD_ERR) ? ms->o.buf : NULL;
575 magic_errno(struct magic_set *ms)
577 if (ms == NULL)
579 return (ms->event_flags & EVENT_HAD_ERR) ? ms->error : 0;
583 magic_getflags(struct magic_set *ms)
585 if (ms == NULL)
586 return -1;
588 return ms->flags;
592 magic_setflags(struct magic_set *ms, int flags)
594 if (ms == NULL)
595 return -1;
598 return -1;
600 ms->flags = flags;
611 magic_setparam(struct magic_set *ms, int param, const void *val)
613 if (ms == NULL)
614 return -1;
618 ms->indir_max = CAST(uint16_t, v);
621 ms->name_max = CAST(uint16_t, v);
624 ms->elf_phnum_max = CAST(uint16_t, v);
627 ms->elf_shnum_max = CAST(uint16_t, v);
630 ms->elf_shsize_max = v;
633 ms->elf_notes_max = CAST(uint16_t, v);
636 ms->regex_max = CAST(uint16_t, v);
639 ms->bytes_max = v;
642 ms->encoding_max = v;
645 ms->magwarn_max = v;
649 return -1;
654 magic_getparam(struct magic_set *ms, int param, void *val)
656 if (ms == NULL)
657 return -1;
660 *CAST(size_t *, val) = ms->indir_max;
663 *CAST(size_t *, val) = ms->name_max;
666 *CAST(size_t *, val) = ms->elf_phnum_max;
669 *CAST(size_t *, val) = ms->elf_shnum_max;
672 *CAST(size_t *, val) = ms->elf_shsize_max;
675 *CAST(size_t *, val) = ms->elf_notes_max;
678 *CAST(size_t *, val) = ms->regex_max;
681 *CAST(size_t *, val) = ms->bytes_max;
684 *CAST(size_t *, val) = ms->encoding_max;
687 *CAST(size_t *, val) = ms->magwarn_max;
691 return -1;