home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c500 / 1.ddi / WSTUBSRC.WPK / WSTUB.C
Encoding:
C/C++ Source or Header  |  1992-05-28  |  984 b   |  44 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.     for (i = 0; i < sizeof(paths_to_check)/sizeof(paths_to_check[0]); i++)
  17.     {
  18.         _searchenv("dos4gw.exe",paths_to_check[i],fullpath);
  19.         if(fullpath[0]) return(&fullpath);
  20.     }    
  21.     return("\\dos4gw.exe");
  22. }
  23.  
  24. main(int argc, char **argv)
  25. {
  26.     /* Allocate arg vector with room for new av[0] and terminal NULL */
  27.     char **av = malloc(sizeof(char*) * (argc+2));
  28.     int ac;
  29.     if(!av)
  30.     {
  31.         puts("Stub failed to allocate argv");
  32.         exit(1);
  33.     }
  34.     av[0] = dos4g_path();        /* Locate the DOS/4G loader */
  35.     /* Copy arguments */
  36.     for(ac = 0; ac < argc; ac++)
  37.         av[ac+1] = argv[ac];
  38.     av[ac+1] = (void *)0;        /* Terminate list */
  39.     execvp(av[0], av);
  40.     puts("Stub exec failed:");
  41.     puts(av[0]);
  42.     puts(strerror(errno));
  43. }
  44.