home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c496 / 1.img / WSTUBSRC.WPK / WSTUB.C
Encoding:
C/C++ Source or Header  |  1991-08-20  |  1.2 KB  |  48 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <process.h>
  4. #include <errno.h>
  5. #include <string.h>
  6.  
  7. /* Add environment strings to be searched here */
  8. char *paths_to_check[] = {
  9.     "DOS4GPATH",
  10.     "PATH"};
  11.  
  12. char *dos4g_path()
  13. {
  14.     static char fullpath[80];
  15.     int i;
  16.     
  17.     for( i = 0;
  18.          i < sizeof( paths_to_check ) / sizeof( paths_to_check[0] ); i++ ) {
  19.     _searchenv( "dos4gw.exe", paths_to_check[i], fullpath );
  20.     if( fullpath[0] ) return( &fullpath );
  21.     }    
  22.     return( "\dos4gw.exe" );
  23. }
  24.  
  25. main(int argc, char **argv)
  26. {
  27.     /* Allocate arg vector with room for new av[0] and terminal NULL */
  28.     char **av = malloc( sizeof( char* ) * ( argc + 2 ) );
  29.     int ac;
  30.     
  31.     if( !av ) {
  32.     puts( "Stub failed to allocate argv" );
  33.     exit( 1 );
  34.     }
  35.     av[0] = dos4g_path();        /* Locate the DOS/4G loader */
  36.     /* Copy arguments */
  37.     for( ac = 0; ac < argc; ac++ ) av[ac+1] = argv[ac];
  38.     av[ac+1] = (void *)0;        /* Terminate list */
  39. #ifdef QUIET
  40.     putenv( "DOS4G=QUIET" );    /* disables DOS/4G Copyright banner */
  41. #endif
  42.     execvp( av[0], av );
  43.     puts( "Stub exec failed:" );
  44.     puts( av[0] );
  45.     puts( strerror( errno ) );
  46.     exit( 1 );            /* indicate error */
  47. }
  48.