13 #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
14 #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
16 #define S_ISFIFO(m) (((m)&S_IFIFO) == S_IFIFO)
17 #define MAXPATHLEN 255
29 return magic_open(
flags);
37 return magic_file(
m,
f);
40 return magic_descriptor(
m,
fd);
43 return magic_buffer(
m,
b,
s);
46 return magic_error(
m);
53 return magic_load(
m,
f) != -1;
55 eprintf(
"Magic buffers should start with #\n");
60 return magic_load(
m,
f) != -1;
63 return magic_compile(
m,
x) != -1;
66 return magic_check(
m,
x) != -1;
69 return magic_errno(
m);
81 #define PIPE_BUF pathconf(".", _PC_PIPE_BUF)
92 for (ml = mlist->next; ml != mlist;) {
93 struct mlist *next = ml->next;
94 struct rz_magic *mg = ml->magic;
131 static const char *
file_or_fd(RzMagic *ms,
const char *inname,
int fd) {
142 #define SLOP (1 + sizeof(union VALUETYPE))
154 default: rv = 0;
goto done;
164 if (
stat(inname, &
sb) == 0 && S_ISFIFO(
sb.st_mode)) {
171 if ((
fd = open(inname,
flags)) < 0) {
172 eprintf(
"couldn't open file\n");
196 (
size_t)(HOWMANY -
nbytes))) > 0) {
214 file_error(ms, errno,
"cannot read `%s'", inname);
236 RzMagic *ms =
RZ_NEW0(RzMagic);
241 ms->o.buf = ms->o.pbuf =
NULL;
242 ms->c.li =
malloc((ms->c.len = 10) *
sizeof(*ms->c.li));
249 ms->file =
"unknown";
265 if (*magicdata ==
'#') {
273 eprintf(
"Magic buffers should start with #\n");
319 if (ms && ms->haderr) {
326 if (ms && ms->haderr) {
struct mlist * file_apprentice(RzMagic *ms, const char *fn, int action)
void file_delmagic(struct rz_magic *p, int type, size_t entries)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void nbytes
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset fstat
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags fcntl
int file_reset(struct rz_magic_set *)
const char * file_getbuffer(struct rz_magic_set *)
void file_error(struct rz_magic_set *, int, const char *,...)
int file_buffer(struct rz_magic_set *, int, const char *, const void *, size_t)
int file_fsmagic(struct rz_magic_set *, const char *, struct stat *)
int file_printf(struct rz_magic_set *, const char *,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
void * malloc(size_t size)
static void free_mlist(struct mlist *mlist)
RZ_API const char * rz_magic_descriptor(RzMagic *ms, int fd)
RZ_API int rz_magic_errno(RzMagic *ms)
static int info_from_stat(RzMagic *ms, unsigned short md)
static const char * file_or_fd(RzMagic *ms, const char *inname, int fd)
static void close_and_restore(const RzMagic *ms, const char *name, int fd, const struct stat *sb)
RZ_API const char * rz_magic_buffer(RzMagic *ms, const void *buf, size_t nb)
RZ_API const char * rz_magic_file(RzMagic *ms, const char *inname)
RZ_API bool rz_magic_check(RzMagic *ms, const char *magicfile)
RZ_API RzMagic * rz_magic_new(int flags)
RZ_API bool rz_magic_compile(RzMagic *ms, const char *magicfile)
RZ_API bool rz_magic_load_buffer(RzMagic *ms, const char *magicdata)
RZ_API bool rz_magic_load(RzMagic *ms, const char *magicfile)
RZ_API void rz_magic_setflags(RzMagic *ms, int flags)
RZ_API const char * rz_magic_error(RzMagic *ms)
RZ_API void rz_magic_free(RzMagic *ms)
static struct sockaddr static addrlen static backlog const void static flags void flags
static const z80_opcode fd[]
int read(izstream &zs, T *x, Items items)