diff -ruN file-3.40.org/apprentice.c file-3.40/apprentice.c --- file-3.40.org/apprentice.c Wed Jul 3 20:00:40 2002 +++ file-3.40/apprentice.c Fri Feb 28 10:29:46 2003 @@ -37,6 +37,8 @@ #include #endif +#include "os2defs.h" + #ifndef lint FILE_RCSID("@(#)$Id: apprentice.c,v 1.49 2002/07/03 19:00:41 christos Exp $") #endif /* lint */ diff -ruN file-3.40.org/apptype.c file-3.40/apptype.c --- file-3.40.org/apptype.c Thu Jan 1 00:00:00 1970 +++ file-3.40/apptype.c Wed Oct 3 17:50:14 2001 @@ -0,0 +1,152 @@ +/* Adapted from: + apptype.c, Written by Eberhard Mattes and put into the public domain + +Notes: +1. Qualify the filename so that DosQueryAppType does not do + extraneous searches. + +2. DosQueryAppType will return FAPPTYP_DOS on a file ending with ".com" + (other than an OS/2 exe or Win exe with this name). Eberhard Mattes + remarks Tue, 6 Apr 93: + Moreover, it reports the type of the (new and very bug ridden) Win + Emacs as "OS/2 executable". + +3. apptype() uses the filename if given, otherwise a tmp file is created + with the contents of buf. If buf is not the complete file, apptype + can incorrectly identify the exe type. The "-z" option of "file" is + the reason for this ugly code. +*/ + +/* + amai: + Darrel Hankerson did the changes described here. + + It remains to check the validity of comments (2.) since + it's referred to an "old" OS/2 version. + +*/ + +#include +#include +#include +#include +#define INCL_DOSSESMGR +#define INCL_DOSERRORS +#define INCL_DOSFILEMGR +#include +typedef ULONG APPTYPE; + +#include "file.h" + + +int +os2_apptype (const char *fn, char *buf, int nb) +{ + APPTYPE rc, type; + char path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], + fname[_MAX_FNAME], ext[_MAX_EXT]; + char *filename; + FILE *fp; + + if (fn) + filename = strdup(fn); + else + if ((filename = tempnam("./", "tmp")) == NULL) { + error("can't create tempnam (%s).\n", strerror(errno)); + } + + /* qualify the filename to prevent extraneous searches */ + _splitpath(filename, drive, dir, fname, ext); + sprintf(path, "%s%s%s%s", drive, + (*dir == '\0') ? "./" : dir, + fname, + (*ext == '\0') ? "." : ext); + + if (fn == NULL) { + if ((fp = fopen(path, "wb")) == NULL) { + error("can't open tmp file '%s' (%s).\n", path, strerror(errno)); + } + if (fwrite(buf, 1, nb, fp) != nb) { + error("can't write tmp file '%s' (%s).\n", path, strerror(errno)); + } + fclose(fp); + } + + rc = DosQueryAppType (path, &type); + + if (fn == NULL) { + unlink(path); + free(filename); + } + +#if 0 + if (rc == ERROR_INVALID_EXE_SIGNATURE) + printf ("%s: not an executable file\n", fname); + else if (rc == ERROR_FILE_NOT_FOUND) + printf ("%s: not found\n", fname); + else if (rc == ERROR_ACCESS_DENIED) + printf ("%s: access denied\n", fname); + else if (rc != 0) + printf ("%s: error code = %lu\n", fname, rc); + else +#else + +/* for our purpose here it's sufficient to just ignore the + error and return w/o success (=0) */ + + if (rc) + return(0); + +#endif + + if (type & FAPPTYP_32BIT) + ckfputs("32-bit ", stdout); + if (type & FAPPTYP_PHYSDRV) { + ckfputs("physical device driver", stdout); + } + else if (type & FAPPTYP_VIRTDRV) { + ckfputs("virtual device driver", stdout); + } + else if (type & FAPPTYP_DLL) { + if (type & FAPPTYP_PROTDLL) + ckfputs("protected ", stdout); + ckfputs("DLL", stdout); + } + else if (type & (FAPPTYP_WINDOWSREAL|FAPPTYP_WINDOWSPROT)) { + ckfputs("Windows executable", stdout); + } + else if (type & FAPPTYP_DOS) { + /* The API routine is partially broken on filenames ending ".com". */ + if (stricmp(ext, ".com") == 0) + if (strncmp(buf, "MZ", 2)) return(0); + ckfputs("DOS executable", stdout); + /* ---------------------------------------- */ + /* Might learn more from the magic(4) entry */ + ckfputs(", magic(4)-> ", stdout); + return(0); + /* ---------------------------------------- */ + } + else if (type & FAPPTYP_BOUND) { + ckfputs("bound executable", stdout); + } + else if ((type & 7) == FAPPTYP_WINDOWAPI) { + ckfputs("PM executable", stdout); + } + else + ckfputs("OS/2 executable", stdout); + + switch(type & (FAPPTYP_NOTWINDOWCOMPAT | + FAPPTYP_WINDOWCOMPAT | + FAPPTYP_WINDOWAPI)) { + case FAPPTYP_NOTWINDOWCOMPAT: + ckfputs(" [NOTWINDOWCOMPAT]", stdout); + break; + case FAPPTYP_WINDOWCOMPAT: + ckfputs(" [WINDOWCOMPAT]", stdout); + break; + case FAPPTYP_WINDOWAPI: + ckfputs(" [WINDOWAPI]", stdout); + break; + } + return (1); +} diff -ruN file-3.40.org/file.h file-3.40/file.h --- file-3.40.org/file.h Sat Feb 8 18:33:52 2003 +++ file-3.40/file.h Fri Feb 28 10:29:46 2003 @@ -77,33 +77,8 @@ uint8_t vallen; /* length of string value, if any */ uint8_t type; /* int, short, long or string. */ uint8_t in_type; /* type of indirrection */ -#define BYTE 1 -#define SHORT 2 -#define LONG 4 -#define STRING 5 -#define DATE 6 -#define BESHORT 7 -#define BELONG 8 -#define BEDATE 9 -#define LESHORT 10 -#define LELONG 11 -#define LEDATE 12 -#define PSTRING 13 -#define LDATE 14 -#define BELDATE 15 -#define LELDATE 16 -#define REGEX 17 uint8_t in_op; /* operator for indirection */ uint8_t mask_op; /* operator for mask */ -#define OPAND 1 -#define OPOR 2 -#define OPXOR 3 -#define OPADD 4 -#define OPMINUS 5 -#define OPMULTIPLY 6 -#define OPDIVIDE 7 -#define OPMODULO 8 -#define OPINVERSE 0x80 int32_t offset; /* offset to magic number */ int32_t in_offset; /* offset from indirection */ union VALUETYPE { diff -ruN file-3.40.org/Makefile.am file-3.40/Makefile.am --- file-3.40.org/Makefile.am Sat Feb 8 18:33:52 2003 +++ file-3.40/Makefile.am Fri Feb 28 14:23:12 2003 @@ -17,7 +17,7 @@ man_MANS = file.1 $(man_MAGIC) file_SOURCES = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \ - compress.c is_tar.c readelf.c print.c \ + compress.c is_tar.c readelf.c print.c apptype.c \ file.h names.h patchlevel.h readelf.h tar.h EXTRA_DIST = LEGAL.NOTICE MAINT PORTING Makefile.std magic2mime \ diff -ruN file-3.40.org/os2defs.h file-3.40/os2defs.h --- file-3.40.org/os2defs.h Thu Jan 1 00:00:00 1970 +++ file-3.40/os2defs.h Sun Feb 16 19:00:46 2003 @@ -0,0 +1,33 @@ +#ifndef __mydefs_h__ +#define __mydefs_h__ + +/* indirection types */ +#define BYTE 1 +#define SHORT 2 +#define LONG 4 +#define STRING 5 +#define DATE 6 +#define BESHORT 7 +#define BELONG 8 +#define BEDATE 9 +#define LESHORT 10 +#define LELONG 11 +#define LEDATE 12 +#define PSTRING 13 +#define LDATE 14 +#define BELDATE 15 +#define LELDATE 16 +#define REGEX 17 + +/* operator types */ +#define OPAND 1 +#define OPOR 2 +#define OPXOR 3 +#define OPADD 4 +#define OPMINUS 5 +#define OPMULTIPLY 6 +#define OPDIVIDE 7 +#define OPMODULO 8 +#define OPINVERSE 0x80 + +#endif diff -ruN file-3.40.org/print.c file-3.40/print.c --- file-3.40.org/print.c Tue Jul 9 16:46:22 2002 +++ file-3.40/print.c Fri Feb 28 10:29:46 2003 @@ -34,6 +34,7 @@ #endif #include +#include "os2defs.h" #ifndef lint FILE_RCSID("@(#)$Id: print.c,v 1.39 2002/07/09 15:46:23 christos Exp $") #endif /* lint */ diff -ruN file-3.40.org/softmagic.c file-3.40/softmagic.c --- file-3.40.org/softmagic.c Sat Feb 8 18:33:52 2003 +++ file-3.40/softmagic.c Fri Feb 28 10:29:48 2003 @@ -32,6 +32,7 @@ #include #include +#include "os2defs.h" #ifndef lint FILE_RCSID("@(#)$Id: softmagic.c,v 1.52 2003/02/08 18:33:53 christos Exp $")