MagickCore  7.1.0
Convert, Edit, Or Compose Bitmap Images
magic.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % M M AAA GGGG IIIII CCCC %
7 % MM MM A A G I C %
8 % M M M AAAAA G GGG I C %
9 % M M A A G G I C %
10 % M M A A GGGG IIIII CCCC %
11 % %
12 % %
13 % MagickCore Image Magic Methods %
14 % %
15 % Software Design %
16 % Bob Friesenhahn %
17 % July 2000 %
18 % %
19 % %
20 % Copyright @ 2000 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
25 % %
26 % https://imagemagick.org/script/license.php %
27 % %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 */
38 
39 /*
40  Include declarations.
41 */
42 #include "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/client.h"
45 #include "MagickCore/configure.h"
47 #include "MagickCore/exception.h"
49 #include "MagickCore/linked-list.h"
50 #include "MagickCore/magic.h"
52 #include "MagickCore/memory_.h"
54 #include "MagickCore/semaphore.h"
55 #include "MagickCore/string_.h"
57 #include "MagickCore/token.h"
58 #include "MagickCore/utility.h"
60 #include "coders/coders.h"
61 
62 /*
63  Define declarations.
64 */
65 #define AddMagickCoder(coder) Magick ## coder ## Headers
66 
67 /*
68  Typedef declarations.
69 */
70 typedef struct _MagicMapInfo
71 {
72  const char
73  name[10];
74 
75  const MagickOffsetType
77 
78  const unsigned char
79  *const magic;
80 
81  const size_t
83 } MagicMapInfo;
84 
85 struct _MagicInfo
86 {
87  char
88  *path,
89  *name,
90  *target;
91 
92  unsigned char
94 
95  size_t
97 
100 
103  stealth;
104 
105  size_t
107 };
108 
109 /*
110  Static declarations.
111 */
112 static const MagicMapInfo
114  {
115  #include "coders/coders-list.h"
116  MagickCoderHeader("CGM", 0, "BEGMF")
117  MagickCoderHeader("FIG", 0, "#FIG")
118  MagickCoderHeader("HPGL", 0, "IN;")
119  MagickCoderHeader("ILBM", 8, "ILBM")
120  };
121 
122 static LinkedListInfo
125 
126 static SemaphoreInfo
129 
130 /*
131  Forward declarations.
132 */
133 static MagickBooleanType
135 
136 /*
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 % %
139 % %
140 % %
141 % A c q u i r e M a g i c L i s t %
142 % %
143 % %
144 % %
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 %
147 % AcquireMagicList() caches one or more magic configurations which provides a
148 % mapping between magic attributes and a magic name.
149 %
150 % The format of the AcquireMagicList method is:
151 %
152 % LinkedListInfo *AcquireMagicList(ExceptionInfo *exception)
153 %
154 % A description of each parameter follows:
155 %
156 % o filename: the font file name.
157 %
158 % o exception: return any errors or warnings in this structure.
159 %
160 */
161 
162 static int CompareMagickInfoExtent(const void *a,const void *b)
163 {
164  MagicInfo
165  *ma,
166  *mb;
167 
169  delta;
170 
171  ma=(MagicInfo *) a;
172  mb=(MagicInfo *) b;
174  if (ma->offset != mb->offset)
175  {
176  /*
177  Offset is near the start? Let's search a bit further in the stream.
178  */
179  delta=ma->offset-mb->offset;
180  if ((ma->offset > mb->offset ? ma->offset : mb->offset) <= 10)
181  delta=mb->offset-ma->offset;
182  }
183  return(delta > INT_MAX ? 0 : (int) delta);
184 }
185 
187 {
189  *list;
190 
192  status;
193 
194  ssize_t
195  i;
196 
197  list=NewLinkedList(0);
198  status=MagickTrue;
199  /*
200  Load built-in magic map.
201  */
202  for (i=0; i < (ssize_t) (sizeof(MagicMap)/sizeof(*MagicMap)); i++)
203  {
204  MagicInfo
205  *magic_info;
206 
207  const MagicMapInfo
208  *p;
209 
210  p=MagicMap+i;
211  magic_info=(MagicInfo *) AcquireMagickMemory(sizeof(*magic_info));
212  if (magic_info == (MagicInfo *) NULL)
213  {
214  (void) ThrowMagickException(exception,GetMagickModule(),
215  ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name);
216  continue;
217  }
218  (void) memset(magic_info,0,sizeof(*magic_info));
219  magic_info->path=(char *) "[built-in]";
220  magic_info->name=(char *) p->name;
221  magic_info->offset=p->offset;
222  magic_info->target=(char *) p->magic;
223  magic_info->magic=(unsigned char *) p->magic;
224  magic_info->length=p->length;
225  magic_info->exempt=MagickTrue;
226  magic_info->signature=MagickCoreSignature;
228  NULL,magic_info);
229  if (status == MagickFalse)
230  (void) ThrowMagickException(exception,GetMagickModule(),
231  ResourceLimitError,"MemoryAllocationFailed","`%s'",magic_info->name);
232  }
233  return(list);
234 }
235 
236 /*
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % %
239 % %
240 % %
241 % G e t M a g i c I n f o %
242 % %
243 % %
244 % %
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 %
247 % GetMagicInfo() searches the magic list for the specified name and if found
248 % returns attributes for that magic.
249 %
250 % The format of the GetMagicInfo method is:
251 %
252 % const MagicInfo *GetMagicInfo(const unsigned char *magic,
253 % const size_t length,ExceptionInfo *exception)
254 %
255 % A description of each parameter follows:
256 %
257 % o magic: A binary string generally representing the first few characters
258 % of the image file or blob.
259 %
260 % o length: the length of the binary signature.
261 %
262 % o exception: return any errors or warnings in this structure.
263 %
264 */
266 {
267  if (magic_cache == (LinkedListInfo *) NULL)
268  {
269  if (magic_cache_semaphore == (SemaphoreInfo *) NULL)
272  if (magic_cache == (LinkedListInfo *) NULL)
275  }
276  return(magic_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
277 }
278 
279 MagickExport const MagicInfo *GetMagicInfo(const unsigned char *magic,
280  const size_t length,ExceptionInfo *exception)
281 {
282  const MagicInfo
283  *p;
284 
286  offset;
287 
288  assert(exception != (ExceptionInfo *) NULL);
289  if (IsMagicListInstantiated(exception) == MagickFalse)
290  return((const MagicInfo *) NULL);
292  return((const MagicInfo *) NULL);
293  /*
294  Search for cached entries.
295  */
296  if (magic != (const unsigned char *) NULL)
297  {
301  while (p != (const MagicInfo *) NULL)
302  {
303  offset=p->offset+(MagickOffsetType) p->length;
304  if ((offset <= (MagickOffsetType) length) &&
305  (memcmp(magic+p->offset,p->magic,p->length) == 0))
306  break;
308  }
310  if (p != (const MagicInfo *) NULL)
311  return(p);
312  }
313  /*
314  Search for magic tag.
315  */
319  if (magic == (const unsigned char *) NULL)
320  {
322  return(p);
323  }
324  while (p != (const MagicInfo *) NULL)
325  {
326  assert(p->offset >= 0);
327  offset=p->offset+(MagickOffsetType) p->length;
328  if ((offset <= (MagickOffsetType) length) &&
329  (memcmp(magic+p->offset,p->magic,p->length) == 0))
330  break;
332  }
334  if (p != (const MagicInfo *) NULL)
335  {
338  NULL,p);
340  }
341  return(p);
342 }
343 
344 /*
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 % %
347 % %
348 % %
349 % G e t M a g i c P a t t e r n E x t e n t %
350 % %
351 % %
352 % %
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 %
355 % GetMagicPatternExtent() returns the extent of the buffer that is
356 % required to check all the MagickInfos. It returns zero if the list is empty.
357 %
358 % The format of the GetMagicPatternExtent method is:
359 %
360 % size_t GetMagicPatternExtent(ExceptionInfo *exception)
361 %
362 % A description of each parameter follows:
363 %
364 % o exception: return any errors or warnings in this structure.
365 %
366 */
368 {
369  const MagicInfo
370  *p;
371 
373  max_offset,
374  offset;
375 
376  static size_t
377  extent = 0;
378 
379  assert(exception != (ExceptionInfo *) NULL);
380  if ((extent != 0) || (IsMagicListInstantiated(exception) == MagickFalse))
381  return(extent);
385  for (max_offset=0; p != (const MagicInfo *) NULL; )
386  {
387  offset=p->offset+(MagickOffsetType) p->length;
388  if (offset > max_offset)
389  max_offset=offset;
391  }
392  if (max_offset > (MagickOffsetType) (MAGICK_SSIZE_MAX/2))
393  return(0);
394  extent=(size_t) max_offset;
396  return(extent);
397 }
398 
399 /*
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 % %
402 % %
403 % %
404 % G e t M a g i c I n f o L i s t %
405 % %
406 % %
407 % %
408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 %
410 % GetMagicInfoList() returns any image aliases that match the specified
411 % pattern.
412 %
413 % The magic of the GetMagicInfoList function is:
414 %
415 % const MagicInfo **GetMagicInfoList(const char *pattern,
416 % size_t *number_aliases,ExceptionInfo *exception)
417 %
418 % A description of each parameter follows:
419 %
420 % o pattern: Specifies a pointer to a text string containing a pattern.
421 %
422 % o number_aliases: This integer returns the number of aliases in the list.
423 %
424 % o exception: return any errors or warnings in this structure.
425 %
426 */
427 
428 #if defined(__cplusplus) || defined(c_plusplus)
429 extern "C" {
430 #endif
431 
432 static int MagicInfoCompare(const void *x,const void *y)
433 {
434  const MagicInfo
435  **p,
436  **q;
437 
438  p=(const MagicInfo **) x,
439  q=(const MagicInfo **) y;
440  if (LocaleCompare((*p)->path,(*q)->path) == 0)
441  return(LocaleCompare((*p)->name,(*q)->name));
442  return(LocaleCompare((*p)->path,(*q)->path));
443 }
444 
445 #if defined(__cplusplus) || defined(c_plusplus)
446 }
447 #endif
448 
449 MagickExport const MagicInfo **GetMagicInfoList(const char *pattern,
450  size_t *number_aliases,ExceptionInfo *exception)
451 {
452  const MagicInfo
453  **aliases;
454 
455  const MagicInfo
456  *p;
457 
458  ssize_t
459  i;
460 
461  /*
462  Allocate magic list.
463  */
464  assert(pattern != (char *) NULL);
465  assert(number_aliases != (size_t *) NULL);
466  if (IsEventLogging() != MagickFalse)
467  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
468  *number_aliases=0;
469  p=GetMagicInfo((const unsigned char *) NULL,0,exception);
470  if (p == (const MagicInfo *) NULL)
471  return((const MagicInfo **) NULL);
472  aliases=(const MagicInfo **) AcquireQuantumMemory((size_t)
473  GetNumberOfElementsInLinkedList(magic_list)+1UL,sizeof(*aliases));
474  if (aliases == (const MagicInfo **) NULL)
475  return((const MagicInfo **) NULL);
476  /*
477  Generate magic list.
478  */
482  for (i=0; p != (const MagicInfo *) NULL; )
483  {
484  if ((p->stealth == MagickFalse) &&
485  (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
486  aliases[i++]=p;
488  }
490  qsort((void *) aliases,(size_t) i,sizeof(*aliases),MagicInfoCompare);
491  aliases[i]=(MagicInfo *) NULL;
492  *number_aliases=(size_t) i;
493  return(aliases);
494 }
495 
496 /*
497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 % %
499 % %
500 % %
501 % G e t M a g i c L i s t %
502 % %
503 % %
504 % %
505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 %
507 % GetMagicList() returns any image format aliases that match the specified
508 % pattern.
509 %
510 % The format of the GetMagicList function is:
511 %
512 % char **GetMagicList(const char *pattern,size_t *number_aliases,
513 % ExceptionInfo *exception)
514 %
515 % A description of each parameter follows:
516 %
517 % o pattern: Specifies a pointer to a text string containing a pattern.
518 %
519 % o number_aliases: This integer returns the number of image format aliases
520 % in the list.
521 %
522 % o exception: return any errors or warnings in this structure.
523 %
524 */
525 
526 #if defined(__cplusplus) || defined(c_plusplus)
527 extern "C" {
528 #endif
529 
530 static int MagicCompare(const void *x,const void *y)
531 {
532  const char
533  *p,
534  *q;
535 
536  p=(const char *) x;
537  q=(const char *) y;
538  return(LocaleCompare(p,q));
539 }
540 
541 #if defined(__cplusplus) || defined(c_plusplus)
542 }
543 #endif
544 
545 MagickExport char **GetMagicList(const char *pattern,size_t *number_aliases,
546  ExceptionInfo *exception)
547 {
548  char
549  **aliases;
550 
551  const MagicInfo
552  *p;
553 
554  ssize_t
555  i;
556 
557  /*
558  Allocate configure list.
559  */
560  assert(pattern != (char *) NULL);
561  assert(number_aliases != (size_t *) NULL);
562  if (IsEventLogging() != MagickFalse)
563  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
564  *number_aliases=0;
565  p=GetMagicInfo((const unsigned char *) NULL,0,exception);
566  if (p == (const MagicInfo *) NULL)
567  return((char **) NULL);
568  aliases=(char **) AcquireQuantumMemory((size_t)
569  GetNumberOfElementsInLinkedList(magic_list)+1UL,sizeof(*aliases));
570  if (aliases == (char **) NULL)
571  return((char **) NULL);
575  for (i=0; p != (const MagicInfo *) NULL; )
576  {
577  if ((p->stealth == MagickFalse) &&
578  (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
579  aliases[i++]=ConstantString(p->name);
581  }
583  qsort((void *) aliases,(size_t) i,sizeof(*aliases),MagicCompare);
584  aliases[i]=(char *) NULL;
585  *number_aliases=(size_t) i;
586  return(aliases);
587 }
588 
589 /*
590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
591 % %
592 % %
593 % %
594 % G e t M a g i c N a m e %
595 % %
596 % %
597 % %
598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599 %
600 % GetMagicName() returns the name associated with the magic.
601 %
602 % The format of the GetMagicName method is:
603 %
604 % const char *GetMagicName(const MagicInfo *magic_info)
605 %
606 % A description of each parameter follows:
607 %
608 % o magic_info: The magic info.
609 %
610 */
611 MagickExport const char *GetMagicName(const MagicInfo *magic_info)
612 {
613  assert(magic_info != (MagicInfo *) NULL);
614  assert(magic_info->signature == MagickCoreSignature);
615  if (IsEventLogging() != MagickFalse)
616  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
617  return(magic_info->name);
618 }
619 
620 /*
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 % %
623 % %
624 % %
625 + I s M a g i c L i s t I n s t a n t i a t e d %
626 % %
627 % %
628 % %
629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 %
631 % IsMagicListInstantiated() determines if the magic list is instantiated.
632 % If not, it instantiates the list and returns it.
633 %
634 % The format of the IsMagicListInstantiated method is:
635 %
636 % MagickBooleanType IsMagicListInstantiated(ExceptionInfo *exception)
637 %
638 % A description of each parameter follows.
639 %
640 % o exception: return any errors or warnings in this structure.
641 %
642 */
644 {
645  if (magic_list == (LinkedListInfo *) NULL)
646  {
647  if (magic_list_semaphore == (SemaphoreInfo *) NULL)
650  if (magic_list == (LinkedListInfo *) NULL)
651  magic_list=AcquireMagicList(exception);
653  }
654  return(magic_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
655 }
656 
657 /*
658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 % %
660 % %
661 % %
662 % L i s t M a g i c I n f o %
663 % %
664 % %
665 % %
666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
667 %
668 % ListMagicInfo() lists the magic info to a file.
669 %
670 % The format of the ListMagicInfo method is:
671 %
672 % MagickBooleanType ListMagicInfo(FILE *file,ExceptionInfo *exception)
673 %
674 % A description of each parameter follows.
675 %
676 % o file: An pointer to a FILE.
677 %
678 % o exception: return any errors or warnings in this structure.
679 %
680 */
682  ExceptionInfo *exception)
683 {
684  const char
685  *path;
686 
687  const MagicInfo
688  **magic_info;
689 
690  ssize_t
691  i;
692 
693  size_t
694  number_aliases;
695 
696  ssize_t
697  j;
698 
699  if (file == (const FILE *) NULL)
700  file=stdout;
701  magic_info=GetMagicInfoList("*",&number_aliases,exception);
702  if (magic_info == (const MagicInfo **) NULL)
703  return(MagickFalse);
704  path=(const char *) NULL;
705  for (i=0; i < (ssize_t) number_aliases; i++)
706  {
707  if (magic_info[i]->stealth != MagickFalse)
708  continue;
709  if ((path == (const char *) NULL) ||
710  (LocaleCompare(path,magic_info[i]->path) != 0))
711  {
712  if (magic_info[i]->path != (char *) NULL)
713  (void) FormatLocaleFile(file,"\nPath: %s\n\n",magic_info[i]->path);
714  (void) FormatLocaleFile(file,"Name Offset Target\n");
715  (void) FormatLocaleFile(file,
716  "-------------------------------------------------"
717  "------------------------------\n");
718  }
719  path=magic_info[i]->path;
720  (void) FormatLocaleFile(file,"%s",magic_info[i]->name);
721  for (j=(ssize_t) strlen(magic_info[i]->name); j <= 9; j++)
722  (void) FormatLocaleFile(file," ");
723  (void) FormatLocaleFile(file,"%6ld ",(long) magic_info[i]->offset);
724  if (magic_info[i]->target != (char *) NULL)
725  {
726  for (j=0; magic_info[i]->target[j] != '\0'; j++)
727  if (isprint((int) ((unsigned char) magic_info[i]->target[j])) != 0)
728  (void) FormatLocaleFile(file,"%c",magic_info[i]->target[j]);
729  else
730  (void) FormatLocaleFile(file,"\\%03o",(unsigned int)
731  ((unsigned char) magic_info[i]->target[j]));
732  }
733  (void) FormatLocaleFile(file,"\n");
734  }
735  (void) fflush(file);
736  magic_info=(const MagicInfo **) RelinquishMagickMemory((void *) magic_info);
737  return(MagickTrue);
738 }
739 
740 /*
741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742 % %
743 % %
744 % %
745 + M a g i c C o m p o n e n t G e n e s i s %
746 % %
747 % %
748 % %
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 %
751 % MagicComponentGenesis() instantiates the magic component.
752 %
753 % The format of the MagicComponentGenesis method is:
754 %
755 % MagickBooleanType MagicComponentGenesis(void)
756 %
757 */
759 {
760  if (magic_list_semaphore == (SemaphoreInfo *) NULL)
762  return(MagickTrue);
763 }
764 
765 /*
766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767 % %
768 % %
769 % %
770 + M a g i c C o m p o n e n t T e r m i n u s %
771 % %
772 % %
773 % %
774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775 %
776 % MagicComponentTerminus() destroys the magic component.
777 %
778 % The format of the MagicComponentTerminus method is:
779 %
780 % MagicComponentTerminus(void)
781 %
782 */
783 
784 static void *DestroyMagicElement(void *magic_info)
785 {
786  MagicInfo
787  *p;
788 
789  p=(MagicInfo *) magic_info;
790  if (p->exempt == MagickFalse)
791  {
792  if (p->path != (char *) NULL)
793  p->path=DestroyString(p->path);
794  if (p->name != (char *) NULL)
795  p->name=DestroyString(p->name);
796  if (p->target != (char *) NULL)
797  p->target=DestroyString(p->target);
798  if (p->magic != (unsigned char *) NULL)
799  p->magic=(unsigned char *) RelinquishMagickMemory(p->magic);
800  }
802  return((void *) NULL);
803 }
804 
806 {
807  if (magic_list_semaphore == (SemaphoreInfo *) NULL)
810  if (magic_list != (LinkedListInfo *) NULL)
814  if (magic_cache_semaphore == (SemaphoreInfo *) NULL)
817  if (magic_cache != (LinkedListInfo *) NULL)
818  magic_cache=DestroyLinkedList(magic_cache,(void *(*)(void *)) NULL);
821 }
MagickExport char ** GetMagicList(const char *pattern, size_t *number_aliases, ExceptionInfo *exception)
Definition: magic.c:545
char * path
Definition: magic.c:88
MagickExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:449
MagickExport void ResetLinkedListIterator(LinkedListInfo *list_info)
Definition: linked-list.c:959
MagickExport LinkedListInfo * DestroyLinkedList(LinkedListInfo *list_info, void *(*relinquish_value)(void *))
Definition: linked-list.c:219
MagickExport const char * GetMagicName(const MagicInfo *magic_info)
Definition: magic.c:611
MagickExport MagickBooleanType InsertValueInSortedLinkedList(LinkedListInfo *list_info, int(*compare)(const void *, const void *), void **replace, const void *value)
Definition: linked-list.c:548
MagickExport SemaphoreInfo * AcquireSemaphoreInfo(void)
Definition: semaphore.c:192
static LinkedListInfo * AcquireMagicList(ExceptionInfo *exception)
Definition: magic.c:186
#define MAGICK_SSIZE_MAX
Definition: studio.h:339
static int MagicCompare(const void *x, const void *y)
Definition: magic.c:530
static int MagicInfoCompare(const void *x, const void *y)
Definition: magic.c:432
Definition: log.h:52
ssize_t MagickOffsetType
Definition: magick-type.h:133
MagickExport void * GetNextValueInLinkedList(LinkedListInfo *list_info)
Definition: linked-list.c:305
#define MagickCoreSignature
MagickExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:293
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:371
MagickBooleanType
Definition: magick-type.h:161
unsigned int MagickStatusType
Definition: magick-type.h:125
MagickExport MagickBooleanType ListMagicInfo(FILE *file, ExceptionInfo *exception)
Definition: magic.c:681
MagickExport MagickBooleanType GlobExpression(const char *magick_restrict expression, const char *magick_restrict pattern, const MagickBooleanType case_insensitive)
Definition: token.c:354
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:665
const size_t length
Definition: magic.c:82
MagickExport MagickBooleanType IsEventLogging(void)
Definition: log.c:763
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1145
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1699
static SemaphoreInfo * magic_cache_semaphore
Definition: magic.c:127
static void * DestroyMagicElement(void *magic_info)
Definition: magic.c:784
MagickExport LinkedListInfo * NewLinkedList(const size_t capacity)
Definition: linked-list.c:713
static int CompareMagickInfoExtent(const void *a, const void *b)
Definition: magic.c:162
MagickBooleanType stealth
Definition: magic.c:102
static SemaphoreInfo * magic_list_semaphore
Definition: magic.c:128
MagickBooleanType exempt
Definition: magic.c:102
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1406
char * target
Definition: magic.c:88
#define GetMagickModule()
Definition: log.h:28
char * name
Definition: magic.c:88
static MagickBooleanType IsMagicCacheInstantiated()
Definition: magic.c:265
MagickExport const MagicInfo ** GetMagicInfoList(const char *pattern, size_t *number_aliases, ExceptionInfo *exception)
Definition: magic.c:449
MagickExport char * DestroyString(char *string)
Definition: string.c:788
MagickExport void * AcquireMagickMemory(const size_t size)
Definition: memory.c:552
MagickExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:98
MagickExport size_t GetNumberOfElementsInLinkedList(const LinkedListInfo *list_info)
Definition: linked-list.c:348
static const MagicMapInfo MagicMap[]
Definition: magic.c:113
MagickOffsetType offset
Definition: magic.c:99
MagickExport const MagicInfo * GetMagicInfo(const unsigned char *magic, const size_t length, ExceptionInfo *exception)
Definition: magic.c:279
const MagickOffsetType offset
Definition: magic.c:76
static LinkedListInfo * magic_list
Definition: magic.c:124
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1162
const unsigned char *const magic
Definition: magic.c:79
MagickExport size_t GetMagicPatternExtent(ExceptionInfo *exception)
Definition: magic.c:367
size_t signature
Definition: magic.c:106
#define MagickPrivate
static LinkedListInfo * magic_cache
Definition: magic.c:123
#define MagickExport
MagickPrivate void MagicComponentTerminus(void)
Definition: magic.c:805
struct _MagicMapInfo MagicMapInfo
const char name[10]
Definition: magic.c:73
MagickPrivate MagickBooleanType MagicComponentGenesis(void)
Definition: magic.c:758
size_t length
Definition: magic.c:96
unsigned char * magic
Definition: magic.c:93
MagickExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:351
MagickExport char * ConstantString(const char *source)
Definition: string.c:678
static MagickBooleanType IsMagicListInstantiated(ExceptionInfo *)
Definition: magic.c:643