29
29
* apprentice - make one pass through /etc/magic, learning its secrets.
30
30
*/
31
31
32
- #include "php.h"
33
-
34
32
#include "file.h"
35
33
36
34
#ifndef lint
@@ -39,19 +37,6 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.326 2022/09/13 18:46:07 christos Exp $")
39
37
40
38
#include "magic.h"
41
39
#include <stdlib.h>
42
-
43
- #if defined(__hpux ) && !defined(HAVE_STRTOULL )
44
- #if SIZEOF_LONG == 8
45
- # define strtoull strtoul
46
- #else
47
- # define strtoull __strtoull
48
- #endif
49
- #endif
50
-
51
- #ifdef PHP_WIN32
52
- #include "win32/unistd.h"
53
- #define strtoull _strtoui64
54
- #else
55
40
#ifdef HAVE_UNISTD_H
56
41
#include <unistd.h>
57
42
#endif
@@ -87,10 +72,6 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.326 2022/09/13 18:46:07 christos Exp $")
87
72
#endif
88
73
#endif
89
74
90
- #ifndef offsetof
91
- #define offsetof (STRUCTURE ,FIELD ) ((int)((char*)&((STRUCTURE*)0)->FIELD))
92
- #endif
93
-
94
75
#ifndef MAP_FAILED
95
76
#define MAP_FAILED (void *) -1
96
77
#endif
@@ -207,6 +188,39 @@ private struct {
207
188
208
189
#include "../data_file.c"
209
190
191
+ #ifdef COMPILE_ONLY
192
+
193
+ int main (int , char * []);
194
+
195
+ int
196
+ main (int argc , char * argv [])
197
+ {
198
+ int ret ;
199
+ struct magic_set * ms ;
200
+ char * progname ;
201
+
202
+ if ((progname = strrchr (argv [0 ], '/' )) != NULL )
203
+ progname ++ ;
204
+ else
205
+ progname = argv [0 ];
206
+
207
+ if (argc != 2 ) {
208
+ (void )fprintf (stderr , "Usage: %s file\n" , progname );
209
+ return 1 ;
210
+ }
211
+
212
+ if ((ms = magic_open (MAGIC_CHECK )) == NULL ) {
213
+ (void )fprintf (stderr , "%s: %s\n" , progname , strerror (errno ));
214
+ return 1 ;
215
+ }
216
+ ret = magic_compile (ms , argv [1 ]) == -1 ? 1 : 0 ;
217
+ if (ret == 1 )
218
+ (void )fprintf (stderr , "%s: %s\n" , progname , magic_error (ms ));
219
+ magic_close (ms );
220
+ return ret ;
221
+ }
222
+ #endif /* COMPILE_ONLY */
223
+
210
224
struct type_tbl_s {
211
225
const char name [16 ];
212
226
const size_t len ;
@@ -440,15 +454,7 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
440
454
ml -> map = idx == 0 ? map : NULL ;
441
455
ml -> magic = map -> magic [idx ];
442
456
ml -> nmagic = map -> nmagic [idx ];
443
- if (ml -> nmagic ) {
444
- ml -> magic_rxcomp = CAST (file_regex_t * * ,
445
- ecalloc (ml -> nmagic , sizeof (* ml -> magic_rxcomp )));
446
- if (ml -> magic_rxcomp == NULL ) {
447
- efree (ml );
448
- return -1 ;
449
- }
450
- } else
451
- ml -> magic_rxcomp = NULL ;
457
+
452
458
mlp -> prev -> next = ml ;
453
459
ml -> prev = mlp -> prev ;
454
460
ml -> next = mlp ;
@@ -656,51 +662,6 @@ mlist_free(struct mlist *mlist)
656
662
mlist_free_one (mlist );
657
663
}
658
664
659
- #ifndef COMPILE_ONLY
660
- /* void **bufs: an array of compiled magic files */
661
- protected int
662
- buffer_apprentice (struct magic_set * ms , struct magic * * bufs ,
663
- size_t * sizes , size_t nbufs )
664
- {
665
- size_t i , j ;
666
- struct mlist * ml ;
667
- struct magic_map * map ;
668
-
669
- if (nbufs == 0 )
670
- return -1 ;
671
-
672
- (void )file_reset (ms , 0 );
673
-
674
- init_file_tables ();
675
-
676
- for (i = 0 ; i < MAGIC_SETS ; i ++ ) {
677
- mlist_free (ms -> mlist [i ]);
678
- if ((ms -> mlist [i ] = mlist_alloc ()) == NULL ) {
679
- file_oomem (ms , sizeof (* ms -> mlist [i ]));
680
- goto fail ;
681
- }
682
- }
683
-
684
- for (i = 0 ; i < nbufs ; i ++ ) {
685
- map = apprentice_buf (ms , bufs [i ], sizes [i ]);
686
- if (map == NULL )
687
- goto fail ;
688
-
689
- for (j = 0 ; j < MAGIC_SETS ; j ++ ) {
690
- if (add_mlist (ms -> mlist [j ], map , j ) == -1 ) {
691
- file_oomem (ms , sizeof (* ml ));
692
- goto fail ;
693
- }
694
- }
695
- }
696
-
697
- return 0 ;
698
- fail :
699
- mlist_free_all (ms );
700
- return -1 ;
701
- }
702
- #endif
703
-
704
665
/* const char *fn: list of magic files and directories */
705
666
protected int
706
667
file_apprentice (struct magic_set * ms , const char * fn , int action )
@@ -3223,28 +3184,6 @@ eatsize(const char **p)
3223
3184
* p = l ;
3224
3185
}
3225
3186
3226
- /*
3227
- * handle a buffer containing a compiled file.
3228
- */
3229
- private struct magic_map *
3230
- apprentice_buf (struct magic_set * ms , struct magic * buf , size_t len )
3231
- {
3232
- struct magic_map * map ;
3233
-
3234
- if ((map = CAST (struct magic_map * , calloc (1 , sizeof (* map )))) == NULL ) {
3235
- file_oomem (ms , sizeof (* map ));
3236
- return NULL ;
3237
- }
3238
- map -> len = len ;
3239
- map -> p = buf ;
3240
- map -> type = MAP_TYPE_USER ;
3241
- if (check_buffer (ms , map , "buffer" ) != 0 ) {
3242
- apprentice_unmap (map );
3243
- return NULL ;
3244
- }
3245
- return map ;
3246
- }
3247
-
3248
3187
/*
3249
3188
* handle a compiled file.
3250
3189
*/
0 commit comments