Mail Archives: djgpp-workers/1997/06/19/09:32:33
--- src/libc/dos/process/chkv2prg.tx~ Wed Jun 18 16:26:32 1997
+++ src/libc/dos/process/chkv2prg.txh Wed Jun 18 16:01:36 1997
@@ -0,0 +1,129 @@
+@node _check_v2_prog, process
+@subheading Syntax
+
+@example
+#include <stdlib.h>
+
+const _v2_prog_type *_check_v2_prog(const char *program, int fd);
+
+@end example
+
+@subheading Description
+
+This function checks a given program for various known types of
+executables and/or other things. This function povides two differnt
+entry points. One is to call the function with a not @code{NULL}
+pointer as @code{program} (in this case @code{fd} is ignored),
+then the file named by @code{program} is opened and closed by
+@code{_check_v2_prog}.
+
+When you pass @code{NULL} as @code{program}, then you have to pass
+a valid file handle in @code{fd} and @code{_check_v2_prog} uses
+that handle and does also not close the file on return.
+
+@subheading Return Value
+@code{_v2_prog_type} is defined in @file{stdlib.h} like the following:
+
+@example
+
+typedef struct @{
+ char magic[16];
+ int struct_length;
+ char go32[16];
+ unsigned char buffer[0];
+@} _v1_stubinfo;
+
+
+typedef struct @{
+ union @{
+ unsigned version:8; /* The version of DJGPP created that COFF exe */
+ struct @{
+ unsigned minor:4; /* The minor version of DJGPP */
+ unsigned major:4; /* The major version of DJGPP */
+ @} v;
+ @} version;
+
+ unsigned object_format:4; /* What an object format */
+# define _V2_OBJECT_FORMAT_UNKNOWN 0x00
+# define _V2_OBJECT_FORMAT_COFF 0x01
+
+ unsigned exec_format:4; /* What an executable format */
+# define _V2_EXEC_FORMAT_UNKNOWN 0x00
+# define _V2_EXEC_FORMAT_COFF 0x01
+# define _V2_EXEC_FORMAT_STUBCOFF 0x02
+# define _V2_EXEC_FORMAT_EXE 0x03
+# define _V2_EXEC_FORMAT_UNIXSCRIPT 0x04
+
+ unsigned valid:1; /* Only when nonzero all the information is valid */
+
+ unsigned has_stubinfo:1; /* When nonzero the stubinfo info is valid */
+
+ unsigned unused:14;
+
+ _v1_stubinfo *stubinfo;
+@} _v2_prog_type;
+
+@end example
+
+The macros shown above can be used to test the different members of that
+structure for known values.
+
+@strong{Warning:} Do not modify any of the data in this structure.
+
+After calling @code{_check_v2_prog} you should check at first the member
+@code{valid}. Only if this is nonzero you can be sure that all the other
+information in the struct is valid.
+
+The same is for the @code{stubinfo} member of the above struct, it is
+valid only, when @code{has_stubinfo} is nonzero.
+
+
+@subheading Example
+
+To use the information returned in the struct you can use code like
+the following:
+
+@example
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+@{
+ const _v2_prog_type *type;
+ /* Since we pass a valid name, we can use -1 as the second argument */
+ type = _check_v2_prog ("foo", -1);
+
+ /* There was something wrong */
+ if (!type->valid)
+ @{
+ fprintf(stderr, "Could not check the file 'foo'. Giving up.\\n");
+ return 1;
+ @}
+
+ /* Currently only the COFF format is valid to be a V2 executable */
+ if (type->object_format != _V2_OBJECT_FORMAT_COFF)
+ @{
+ fprintf(stderr, "File 'foo' is not in COFF format\\n");
+ return 2;
+ @}
+
+ /* The major version is not 2 */
+ if (type->version.v.major != 2)
+ @{
+ fprintf(stderr, "File 'foo' is not from DJGPP 2.xx\\n");
+ return 3;
+ @}
+
+ fprintf(stdout, "File 'foo' is a valid DJGPP 2.xx executable\\n");
+
+ if (type->exec_format == _V2_EXEC_FORMAT_STUBCOFF)
+ @{
+ fprintf(stdout, "File 'foo' has a stub loader prepended\\n");
+ @}
+
+ return 0;
+@}
+
+@end example
+
- Raw text -