file.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * file.h - definitions for file(1) program
  3. * @(#)$Id: file.h,v 1.23 1996/06/22 22:04:22 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 HOWMANY
  29. # define HOWMANY 8192 /* how much of the file to look at */
  30. #endif
  31. #define MAXMAGIS 1000 /* max entries in /etc/magic */
  32. #define MAXDESC 50 /* max leng of text description */
  33. #define MAXstring 32 /* max leng of "string" types */
  34. struct magic {
  35. short flag;
  36. #define INDIR 1 /* if '>(...)' appears, */
  37. #define UNSIGNED 2 /* comparison is unsigned */
  38. #define ADD 4 /* if '>&' appears, */
  39. short cont_level; /* level of ">" */
  40. struct {
  41. char type; /* byte short long */
  42. long offset; /* offset from indirection */
  43. } in;
  44. long offset; /* offset to magic number */
  45. unsigned char reln; /* relation (0=eq, '>'=gt, etc) */
  46. char type; /* int, short, long or string. */
  47. char vallen; /* length of string value, if any */
  48. #define BYTE 1
  49. #define SHORT 2
  50. #define LONG 4
  51. #define STRING 5
  52. #define DATE 6
  53. #define BESHORT 7
  54. #define BELONG 8
  55. #define BEDATE 9
  56. #define LESHORT 10
  57. #define LELONG 11
  58. #define LEDATE 12
  59. union VALUETYPE {
  60. unsigned char b;
  61. unsigned short h;
  62. unsigned long l;
  63. char s[MAXstring];
  64. unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */
  65. unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */
  66. } value; /* either number or string */
  67. unsigned long mask; /* mask before comparison with value */
  68. char nospflag; /* supress space character */
  69. char desc[MAXDESC]; /* description */
  70. };
  71. #include <stdio.h> /* Include that here, to make sure __P gets defined */
  72. #ifndef __P
  73. # if __STDC__ || __cplusplus
  74. # define __P(a) a
  75. # else
  76. # define __P(a) ()
  77. # define const
  78. # endif
  79. #endif
  80. extern int apprentice __P((char *, int));
  81. extern int ascmagic __P((unsigned char *, int));
  82. extern void error __P((const char *, ...));
  83. extern void ckfputs __P((const char *, FILE *));
  84. struct stat;
  85. extern int fsmagic __P((const char *, struct stat *));
  86. extern int is_compress __P((const unsigned char *, int *));
  87. extern int is_tar __P((unsigned char *, int));
  88. extern void magwarn __P((const char *, ...));
  89. extern void mdump __P((struct magic *));
  90. extern void process __P((const char *, int));
  91. extern void showstr __P((FILE *, const char *, int));
  92. extern int softmagic __P((unsigned char *, int));
  93. extern int tryit __P((unsigned char *, int, int));
  94. extern int zmagic __P((unsigned char *, int));
  95. extern void ckfprintf __P((FILE *, const char *, ...));
  96. extern unsigned long signextend __P((struct magic *, unsigned long));
  97. extern int errno; /* Some unixes don't define this.. */
  98. extern char *progname; /* the program name */
  99. extern char *magicfile; /* name of the magic file */
  100. extern int lineno; /* current line number in magic file */
  101. extern struct magic *magic; /* array of magic entries */
  102. extern int nmagic; /* number of valid magic[]s */
  103. extern int debug; /* enable debugging? */
  104. extern int zflag; /* process compressed files? */
  105. extern int lflag; /* follow symbolic links? */
  106. extern int optind; /* From getopt(3) */
  107. extern char *optarg;
  108. #if !defined(__STDC__) || defined(sun) || defined(__sun__) || defined(__convex__)
  109. extern int sys_nerr;
  110. extern char *sys_errlist[];
  111. #define strerror(e) \
  112. (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
  113. #define strtoul(a, b, c) strtol(a, b, c)
  114. #endif
  115. #ifndef MAXPATHLEN
  116. #define MAXPATHLEN 512
  117. #endif