| 1 | /* $Id: clfix.c,v 1.2 2000-11-09 20:42:43 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * A wrapper program for cl.exe fix will try fix some of the problems | 
|---|
| 4 | * we have seen. | 
|---|
| 5 | * | 
|---|
| 6 | *   syntax: clfix.exe <cl> [cl arguments] | 
|---|
| 7 | * | 
|---|
| 8 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 9 | * | 
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 11 | * | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | /******************************************************************************* | 
|---|
| 15 | *   Defined Constants And Macros                                               * | 
|---|
| 16 | *******************************************************************************/ | 
|---|
| 17 | #define INCL_BASE | 
|---|
| 18 |  | 
|---|
| 19 | /******************************************************************************* | 
|---|
| 20 | *   Header Files                                                               * | 
|---|
| 21 | *******************************************************************************/ | 
|---|
| 22 | #include <os2.h> | 
|---|
| 23 | #include <string.h> | 
|---|
| 24 | #include <stdio.h> | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | int main(int argc, char **argv) | 
|---|
| 28 | { | 
|---|
| 29 | static char     szArgBuffer[32768]; | 
|---|
| 30 | RESULTCODES     resc; | 
|---|
| 31 | int             argi; | 
|---|
| 32 | char *          psz; | 
|---|
| 33 | HFILE           hFile; | 
|---|
| 34 | APIRET          rc; | 
|---|
| 35 |  | 
|---|
| 36 |  | 
|---|
| 37 | /* | 
|---|
| 38 | * Check that we have cl.exe at least passed in. | 
|---|
| 39 | */ | 
|---|
| 40 | if (argc < 2) | 
|---|
| 41 | { | 
|---|
| 42 | PSZ psz = | 
|---|
| 43 | "A wrapper program for cl.exe fix will try fix some of the problems\r\n" | 
|---|
| 44 | "we have seen.\r\n" | 
|---|
| 45 | "\r\n" | 
|---|
| 46 | "  syntax: clfix.exe <drive:fullpath\\cl.exe> [cl arguments]\r\n"; | 
|---|
| 47 | ULONG cch = strlen(psz); | 
|---|
| 48 | DosWrite(0, psz, cch, &cch); | 
|---|
| 49 | return -1; | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | /* | 
|---|
| 54 | * First argument | 
|---|
| 55 | */ | 
|---|
| 56 | psz = strcpy(szArgBuffer, argv[1]); | 
|---|
| 57 | psz += strlen(psz); | 
|---|
| 58 | psz++; | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | /* The other arguments. */ | 
|---|
| 62 | if (argc > 2) | 
|---|
| 63 | { | 
|---|
| 64 | argi = 2; | 
|---|
| 65 | while (argi < argc) | 
|---|
| 66 | { | 
|---|
| 67 | strcpy(psz, argv[argi]); | 
|---|
| 68 | psz += strlen(psz); | 
|---|
| 69 | *psz++ = ' '; | 
|---|
| 70 | argi++; | 
|---|
| 71 | } | 
|---|
| 72 | psz[-1] = '\0'; | 
|---|
| 73 | } | 
|---|
| 74 | *psz = '\0'; | 
|---|
| 75 |  | 
|---|
| 76 |  | 
|---|
| 77 | /* | 
|---|
| 78 | * Set max filehandles | 
|---|
| 79 | * ú Is this inherited? | 
|---|
| 80 | * - Probably not. So we'll have exploit handle inheritance | 
|---|
| 81 | *   to fix this. | 
|---|
| 82 | */ | 
|---|
| 83 | DosSetMaxFH(100); | 
|---|
| 84 |  | 
|---|
| 85 | /* | 
|---|
| 86 | * Let us open a high handle number which makes the | 
|---|
| 87 | * child process to inherit the maximum number of open files. | 
|---|
| 88 | */ | 
|---|
| 89 | hFile = 99; /* suggest handle number. */ | 
|---|
| 90 | rc = DosDupHandle(1, &hFile); | 
|---|
| 91 | if (rc) | 
|---|
| 92 | printf("clfix: DosDupHandle failed with rc=%d\n\n", rc); | 
|---|
| 93 |  | 
|---|
| 94 |  | 
|---|
| 95 | /* | 
|---|
| 96 | * Execute argument without any environment. | 
|---|
| 97 | *  Some of the internal errors which has occured might be caused by long variables or | 
|---|
| 98 | *  generally a big environment block. We'll send in an empty environment block and hope | 
|---|
| 99 | *  this will solve the problems. | 
|---|
| 100 | */ | 
|---|
| 101 | if (DosExecPgm(NULL, 0, EXEC_SYNC, szArgBuffer, "\0\0", &resc, szArgBuffer) != NO_ERROR) | 
|---|
| 102 | { | 
|---|
| 103 | /*complain*/ | 
|---|
| 104 | return -1; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 |  | 
|---|
| 108 | /* | 
|---|
| 109 | * return result code from cl.exe. | 
|---|
| 110 | */ | 
|---|
| 111 | return resc.codeResult; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|