1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| | #include <magic.h>
#include <config.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include "lisp.h"
/*
*/
/*
magic_t
magic_open(int flags);
void
magic_close(magic_t cookie);
const char *
magic_error(magic_t cookie);
int
magic_errno(magic_t cookie);
const char *
magic_file(magic_t cookie, const char *filename);
const char *
magic_buffer(magic_t cookie, const void *buffer, size_t length);
int
magic_setflags(magic_t cookie, int flags);
int
magic_check(magic_t cookie, const char *filename);
int
magic_compile(magic_t cookie, const char *filename);
int
magic_load(magic_t cookie, const char *filename);
*/
DEFUN ("file-magic-file", Ffile_magic_file, Sfile_magic_file, 1,1,0,
doc: /* return libmagic file description for filename */)
(filename)
Lisp_Object filename;
{
if (!STRINGP (filename)) return Qnil;
printf("filename:%s\n",SDATA(filename));
magic_t cookie= magic_open(MAGIC_MIME_TYPE);
magic_load(cookie,NULL);
printf("cookie:%d\n",cookie);
char *rvs=magic_file(cookie, SDATA(filename));
printf("rvs:%s\n",rvs);
Lisp_Object rv=intern(rvs);
magic_close(cookie);
return rv;
}
void
syms_of_filemagic ()
{
defsubr (&Sfile_magic_file);
}
|