file.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * file.h - definitions for file(1) program
  3. * @(#)$Id: file.h,v 1.27 1998/06/27 13:57:23 christos Exp $
  4. *
  5. * Copyright (c) Ian F. Darwin, 1987.
  6. * Written by Ian F. Darwin.
  7. *
  8. * This software is not subject to any license of the American Telephone
  9. * and Telegraph Company or of the Regents of the University of California.
  10. *
  11. * Permission is granted to anyone to use this software for any purpose on
  12. * any computer system, and to alter it and redistribute it freely, subject
  13. * to the following restrictions:
  14. *
  15. * 1. The author is not responsible for the consequences of use of this
  16. * software, no matter how awful, even if they arise from flaws in it.
  17. *
  18. * 2. The origin of this software must not be misrepresented, either by
  19. * explicit claim or by omission. Since few users ever read sources,
  20. * credits must appear in the documentation.
  21. *
  22. * 3. Altered versions must be plainly marked as such, and must not be
  23. * misrepresented as being the original software. Since few users
  24. * ever read sources, credits must appear in the documentation.
  25. *
  26. * 4. This notice may not be removed or altered.
  27. */
  28. #ifndef __file_h__
  29. #define __file_h__
  30. typedef int int32;
  31. typedef unsigned int uint32;
  32. #ifndef HOWMANY
  33. # define HOWMANY 8192 /* how much of the file to look at */
  34. #endif
  35. #define MAXMAGIS 1000 /* max entries in /etc/magic */
  36. #define MAXDESC 50 /* max leng of text description */
  37. #define MAXstring 32 /* max leng of "string" types */
  38. struct magic {
  39. short flag;
  40. #define INDIR 1 /* if '>(...)' appears, */
  41. #define UNSIGNED 2 /* comparison is unsigned */
  42. #define ADD 4 /* if '>&' appears, */
  43. short cont_level; /* level of ">" */
  44. struct {
  45. char type; /* byte short long */
  46. int32 offset; /* offset from indirection */
  47. } in;
  48. int32 offset; /* offset to magic number */
  49. unsigned char reln; /* relation (0=eq, '>'=gt, etc) */
  50. char type; /* int, short, long or string. */
  51. char vallen; /* length of string value, if any */
  52. #define BYTE 1
  53. #define SHORT 2
  54. #define LONG 4
  55. #define STRING 5
  56. #define DATE 6
  57. #define BESHORT 7
  58. #define BELONG 8
  59. #define BEDATE 9
  60. #define LESHORT 10
  61. #define LELONG 11
  62. #define LEDATE 12
  63. union VALUETYPE {
  64. unsigned char b;
  65. unsigned short h;
  66. uint32 l;
  67. char s[MAXstring];
  68. unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */
  69. unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */
  70. } value; /* either number or string */
  71. uint32 mask; /* mask before comparison with value */
  72. char nospflag; /* supress space character */
  73. char desc[MAXDESC]; /* description */
  74. };
  75. #include <stdio.h> /* Include that here, to make sure __P gets defined */
  76. #ifndef __P
  77. # if __STDC__ || __cplusplus
  78. # define __P(a) a
  79. # else
  80. # define __P(a) ()
  81. # define const
  82. # endif
  83. #endif
  84. extern int apprentice __P((const char *, int));
  85. extern int ascmagic __P((unsigned char *, int));
  86. extern void error __P((const char *, ...));
  87. extern void ckfputs __P((const char *, FILE *));
  88. struct stat;
  89. extern int fsmagic __P((const char *, struct stat *));
  90. extern int is_compress __P((const unsigned char *, int *));
  91. extern int is_tar __P((unsigned char *, int));
  92. extern void magwarn __P((const char *, ...));
  93. extern void mdump __P((struct magic *));
  94. extern void process __P((const char *, int));
  95. extern void showstr __P((FILE *, const char *, int));
  96. extern int softmagic __P((unsigned char *, int));
  97. extern int tryit __P((unsigned char *, int, int));
  98. extern int zmagic __P((unsigned char *, int));
  99. extern void ckfprintf __P((FILE *, const char *, ...));
  100. extern uint32 signextend __P((struct magic *, unsigned int32));
  101. extern int internatmagic __P((unsigned char *, int));
  102. extern void tryelf __P((int, char *, int));
  103. extern int errno; /* Some unixes don't define this.. */
  104. extern char *progname; /* the program name */
  105. extern const char *magicfile; /* name of the magic file */
  106. extern int lineno; /* current line number in magic file */
  107. extern struct magic *magic; /* array of magic entries */
  108. extern int nmagic; /* number of valid magic[]s */
  109. extern int debug; /* enable debugging? */
  110. extern int zflag; /* process compressed files? */
  111. extern int lflag; /* follow symbolic links? */
  112. extern int optind; /* From getopt(3) */
  113. extern char *optarg;
  114. #if defined(sun) || defined(__sun__) || defined (__sun)
  115. # if defined(__svr4) || defined (__SVR4) || defined(__svr4__)
  116. # define SOLARIS
  117. # else
  118. # define SUNOS
  119. # endif
  120. #endif
  121. #if !defined(__STDC__) || defined(SUNOS) || defined(__convex__)
  122. extern int sys_nerr;
  123. extern char *sys_errlist[];
  124. #define strerror(e) \
  125. (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
  126. #define strtoul(a, b, c) strtol(a, b, c)
  127. #endif
  128. #ifndef MAXPATHLEN
  129. #define MAXPATHLEN 512
  130. #endif
  131. #ifdef __STDC__
  132. #define FILE_RCSID(id) \
  133. static const char *rcsid(const char *p) { \
  134. return rcsid(p = id); \
  135. }
  136. #else
  137. #define FILE_RCSID(id) static char *rcsid[] = id;
  138. #endif
  139. #endif /* __file_h__ */