ftp.delorie.com/djgpp/doc/libc/libc_93.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

_check_v2_prog

Syntax

 
#include <sys/system.h>

const _v2_prog_type *_check_v2_prog(const char *program, int fd);

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 NULL pointer as program (in this case fd is ignored), then the file named by program is opened and closed by _check_v2_prog.

When you pass NULL as program, then you have to pass a valid file handle in fd and _check_v2_prog uses that handle and does also not close the file on return.

Return Value

_v2_prog_type is defined in `sys/system.h' like the following:

 
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
# define _V2_OBJECT_FORMAT_PE_COFF 0x02

  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;

The macros shown above can be used to test the different members of that structure for known values.

Warning: Do not modify any of the data in this structure.

After calling _check_v2_prog you should check at first the member 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 stubinfo member of the above struct, it is valid only, when has_stubinfo is nonzero.

Portability

ANSI/ISO C No
POSIX No

Example

To use the information returned in the struct you can use code like the following:

 
#include <stdio.h>
#include <sys/system.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;
}


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004