Deleted Added
full compact
magic.c (267897) magic.c (275698)
1/*
2 * Copyright (c) Christos Zoulas 2003.
3 * All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 19 unchanged lines hidden (view full) ---

28#ifdef WIN32
29#include <windows.h>
30#include <shlwapi.h>
31#endif
32
33#include "file.h"
34
35#ifndef lint
1/*
2 * Copyright (c) Christos Zoulas 2003.
3 * All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 19 unchanged lines hidden (view full) ---

28#ifdef WIN32
29#include <windows.h>
30#include <shlwapi.h>
31#endif
32
33#include "file.h"
34
35#ifndef lint
36FILE_RCSID("@(#)$File: magic.c,v 1.84 2014/05/14 23:15:42 christos Exp $")
36FILE_RCSID("@(#)$File: magic.c,v 1.90 2014/12/04 15:56:46 christos Exp $")
37#endif /* lint */
38
39#include "magic.h"
40
41#include <stdlib.h>
42#include <unistd.h>
43#include <string.h>
44#ifdef QUICK

--- 78 unchanged lines hidden (view full) ---

123 return default_magic;
124out:
125 default_magic = NULL;
126 free(hmagicpath);
127 return MAGIC;
128#else
129 char *hmagicp;
130 char *tmppath = NULL;
37#endif /* lint */
38
39#include "magic.h"
40
41#include <stdlib.h>
42#include <unistd.h>
43#include <string.h>
44#ifdef QUICK

--- 78 unchanged lines hidden (view full) ---

123 return default_magic;
124out:
125 default_magic = NULL;
126 free(hmagicpath);
127 return MAGIC;
128#else
129 char *hmagicp;
130 char *tmppath = NULL;
131 LPTSTR dllpath;
131 hmagicpath = NULL;
132
133#define APPENDPATH() \
134 do { \
135 if (tmppath && access(tmppath, R_OK) != -1) { \
136 if (hmagicpath == NULL) \
137 hmagicpath = tmppath; \
138 else { \

--- 29 unchanged lines hidden (view full) ---

168
169 /* Second, try to get a magic file from Common Files */
170 if ((home = getenv("COMMONPROGRAMFILES")) != NULL) {
171 if (asprintf(&tmppath, "%s%s", home, hmagic) >= 0)
172 APPENDPATH();
173 }
174
175 /* Third, try to get magic file relative to dll location */
132 hmagicpath = NULL;
133
134#define APPENDPATH() \
135 do { \
136 if (tmppath && access(tmppath, R_OK) != -1) { \
137 if (hmagicpath == NULL) \
138 hmagicpath = tmppath; \
139 else { \

--- 29 unchanged lines hidden (view full) ---

169
170 /* Second, try to get a magic file from Common Files */
171 if ((home = getenv("COMMONPROGRAMFILES")) != NULL) {
172 if (asprintf(&tmppath, "%s%s", home, hmagic) >= 0)
173 APPENDPATH();
174 }
175
176 /* Third, try to get magic file relative to dll location */
176 LPTSTR dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1));
177 dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1));
177 dllpath[MAX_PATH] = 0; /* just in case long path gets truncated and not null terminated */
178 if (GetModuleFileNameA(NULL, dllpath, MAX_PATH)){
179 PathRemoveFileSpecA(dllpath);
180 if (strlen(dllpath) > 3 &&
181 stricmp(&dllpath[strlen(dllpath) - 3], "bin") == 0) {
182 if (asprintf(&tmppath,
183 "%s/../share/misc/magic.mgc", dllpath) >= 0)
184 APPENDPATH();

--- 67 unchanged lines hidden (view full) ---

252public int
253magic_load(struct magic_set *ms, const char *magicfile)
254{
255 if (ms == NULL)
256 return -1;
257 return file_apprentice(ms, magicfile, FILE_LOAD);
258}
259
178 dllpath[MAX_PATH] = 0; /* just in case long path gets truncated and not null terminated */
179 if (GetModuleFileNameA(NULL, dllpath, MAX_PATH)){
180 PathRemoveFileSpecA(dllpath);
181 if (strlen(dllpath) > 3 &&
182 stricmp(&dllpath[strlen(dllpath) - 3], "bin") == 0) {
183 if (asprintf(&tmppath,
184 "%s/../share/misc/magic.mgc", dllpath) >= 0)
185 APPENDPATH();

--- 67 unchanged lines hidden (view full) ---

253public int
254magic_load(struct magic_set *ms, const char *magicfile)
255{
256 if (ms == NULL)
257 return -1;
258 return file_apprentice(ms, magicfile, FILE_LOAD);
259}
260
261#ifndef COMPILE_ONLY
262/*
263 * Install a set of compiled magic buffers.
264 */
260public int
265public int
266magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes,
267 size_t nbufs)
268{
269 if (ms == NULL)
270 return -1;
271 return buffer_apprentice(ms, (struct magic **)bufs, sizes, nbufs);
272}
273#endif
274
275public int
261magic_compile(struct magic_set *ms, const char *magicfile)
262{
263 if (ms == NULL)
264 return -1;
265 return file_apprentice(ms, magicfile, FILE_COMPILE);
266}
267
268public int

--- 248 unchanged lines hidden (view full) ---

517 return 0;
518}
519
520public int
521magic_version(void)
522{
523 return MAGIC_VERSION;
524}
276magic_compile(struct magic_set *ms, const char *magicfile)
277{
278 if (ms == NULL)
279 return -1;
280 return file_apprentice(ms, magicfile, FILE_COMPILE);
281}
282
283public int

--- 248 unchanged lines hidden (view full) ---

532 return 0;
533}
534
535public int
536magic_version(void)
537{
538 return MAGIC_VERSION;
539}
540
541public int
542magic_setparam(struct magic_set *ms, int param, const void *val)
543{
544 switch (param) {
545 case MAGIC_PARAM_INDIR_MAX:
546 ms->indir_max = *(const size_t *)val;
547 return 0;
548 case MAGIC_PARAM_NAME_MAX:
549 ms->name_max = *(const size_t *)val;
550 return 0;
551 case MAGIC_PARAM_ELF_PHNUM_MAX:
552 ms->elf_phnum_max = *(const size_t *)val;
553 return 0;
554 case MAGIC_PARAM_ELF_SHNUM_MAX:
555 ms->elf_shnum_max = *(const size_t *)val;
556 return 0;
557 default:
558 errno = EINVAL;
559 return -1;
560 }
561}
562
563public int
564magic_getparam(struct magic_set *ms, int param, void *val)
565{
566 switch (param) {
567 case MAGIC_PARAM_INDIR_MAX:
568 *(size_t *)val = ms->indir_max;
569 return 0;
570 case MAGIC_PARAM_NAME_MAX:
571 *(size_t *)val = ms->name_max;
572 return 0;
573 case MAGIC_PARAM_ELF_PHNUM_MAX:
574 *(size_t *)val = ms->elf_phnum_max;
575 return 0;
576 case MAGIC_PARAM_ELF_SHNUM_MAX:
577 *(size_t *)val = ms->elf_shnum_max;
578 return 0;
579 default:
580 errno = EINVAL;
581 return -1;
582 }
583}