Ticket #303: envtest.c

File envtest.c, 1.8 KB (added by KO Myung-Hun, 10 years ago)

main program of testcase

Line 
1#define INCL_DOS
2#include <os2.h>
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <process.h>
8
9#define MAX_ENV_SIZE (32 * 1024)
10
11int main( int _argc, char *_argv[], char *_envp[])
12{
13 const char *name = "envtest2.exe";
14 const char *argv[ 100 ];
15 const char *envp[ 1024 ];
16 int totallen;
17 char *env;
18 int envpos;
19 int envsize;
20 int i;
21 int rc = -1;
22
23 for( i = 0; _envp[ i ]; i++ )
24 envp[ i ] = _envp[ i ];
25
26 envpos = i;
27 envp[ envpos + 1 ] = NULL;
28
29 for( envsize = MAX_ENV_SIZE; rc == -1; --envsize )
30 {
31 env = calloc( 1, envsize + 1 );
32
33 memset( env, 'K', envsize );
34
35 envp[ envpos ] = env;
36
37#if 1
38 argv[ 0 ] = "envtest2.exe";
39 argv[ 1 ] = NULL;
40 rc = spawnvpe( P_WAIT, argv[0], argv, envp );
41#else
42{
43 RESULTCODES res;
44 char *envz;
45 char *p;
46
47 envz = calloc( 1, 64 * 1024 );
48 for( p = envz, i = 0; envp[ i ]; i++ )
49 {
50 strcpy( p, envp[ i ]);
51 p += strlen( envp[ i ]) + 1;
52 }
53
54 rc = DosExecPgm( NULL, 0, EXEC_SYNC, "envtest2.exe\0", envz, &res,
55 name );
56 if( rc != 0 )
57 rc = -1;
58
59 free( envz );
60}
61#endif
62 for( totallen = 0, i = 0; envp[ i ]; ++i )
63 totallen += strlen( envp[ i ]) + 1;
64
65 printf("total len = %d, envsize = %d, rc = %d\n",
66 totallen, envsize, rc );
67
68 if( rc != -1 )
69 {
70 FILE *fp;
71
72 fp = fopen("envtest.log", "wt");
73
74 for( i = 0; envp[ i ]; i++ )
75 {
76 fprintf( fp, "%s\n", envp[ i ]);
77 }
78
79 fclose( fp );
80 }
81
82 free( env );
83 }
84
85 return 0;
86}