long MySpawn( const char *cmd ) { bool cp; long rc; exec_block exeparm; _fcb fcb1, fcb2; cmd_struct cmds; char path[_MAX_PATH], file[_MAX_PATH]; tiny_ret_t ret; int i; char chkfname[L_tmpnam]; minMemoryLeft = MaxMemFree & ~((long)MAX_IO_BUFFER - 1); chkSwapSize = 1 + (unsigned short) (((minMemoryLeft + ((long)MAX_IO_BUFFER - 1)) & ~((long)MAX_IO_BUFFER - 1)) / (long)MAX_IO_BUFFER); /* * set up checkpoint file stuff: */ #ifndef NOEMS if( !EMSBlockTest( chkSwapSize ) ) { xHandle = alloca( chkSwapSize * sizeof( long ) ); xSize = alloca( chkSwapSize * sizeof( short ) ); for( i = 0; i < chkSwapSize; i++ ) { EMSGetBlock( &xHandle[i] ); } isWhere = IN_EMS; currMem = 0; goto evil_goto; } #endif #ifndef NOXMS if( !XMSBlockTest( chkSwapSize ) ) { xHandle = alloca( chkSwapSize * sizeof( long ) ); xSize = alloca( chkSwapSize * sizeof( short ) ); for( i = 0; i < chkSwapSize; i++ ) { XMSGetBlock( &xHandle[i] ); } isWhere = IN_XMS; currMem = 0; goto evil_goto; } #endif file[0] = 0; tmpnam( chkfname ); StrMerge( 3, file, TmpDir, FILE_SEP_STR, chkfname ); fullName = file; ret = TinyCreate( fullName, TIO_NORMAL ); if( ret < 0 ) { return( 0 ); } fileHandle = ret; isWhere = ON_DISK; /* * build command line */ evil_goto: GetSpawnCommandLine( path, cmd, &cmds ); /* * set up parm block */ exeparm.envp = 0; exeparm.cmdline = &cmds; exeparm.fcb1 = fcb1; exeparm.fcb2 = fcb2; GetFcb( &cmds.cmd, &fcb1 ); GetFcb( &cmds.cmd, &fcb2 ); /* * spawn the command */ cp = checkPointMem( minMemoryLeft / 16 ); rc = DoSpawn( path, &exeparm ); if( cp ) { CheckPointRestore(); } return( rc ); }
long MySpawn( const char *cmd ) { bool cp; long rc; exec_block exeparm; _fcb fcb1, fcb2; cmd_struct cmds; char path[_MAX_PATH], f_buff[_MAX_PATH]; int i; where_parm where; long minMemoryLeft; #if defined( USE_XMS ) || defined( USE_EMS ) int chkSwapSize; long *xHandle; unsigned short *xSize; #endif minMemoryLeft = MaxMemFree & ~((long)MAX_IO_BUFFER - 1); #if defined( USE_XMS ) || defined( USE_EMS ) chkSwapSize = 1 + (unsigned short) (((minMemoryLeft + ((long)MAX_IO_BUFFER - 1)) & ~((long)MAX_IO_BUFFER - 1)) / (long)MAX_IO_BUFFER); /* * set up checkpoint file stuff: */ #if defined( USE_EMS ) if( !EMSBlockTest( chkSwapSize ) ) { xHandle = alloca( chkSwapSize * sizeof( long ) ); xSize = alloca( chkSwapSize * sizeof( short ) ); for( i = 0; i < chkSwapSize; i++ ) { EMSGetBlock( &xHandle[i] ); } XSwapInit( chkSwapSize, xHandle, xSize ); where = IN_EMS; goto evil_goto; } #endif #if defined( USE_XMS ) if( !XMSBlockTest( chkSwapSize ) ) { xHandle = alloca( chkSwapSize * sizeof( long ) ); xSize = alloca( chkSwapSize * sizeof( short ) ); for( i = 0; i < chkSwapSize; i++ ) { XMSGetBlock( &xHandle[i] ); } XSwapInit( chkSwapSize, xHandle, xSize ); where = IN_XMS; goto evil_goto; } #endif #endif where = ON_DISK; /* * build command line */ evil_goto: GetSpawnCommandLine( path, cmd, &cmds ); /* * set up parm block */ exeparm.envp = 0; exeparm.cmdline = &cmds; exeparm.fcb1 = fcb1; exeparm.fcb2 = fcb2; GetFcb( &cmds.cmd, &fcb1 ); GetFcb( &cmds.cmd, &fcb2 ); /* * spawn the command */ cp = CheckPointMem( where, minMemoryLeft / 16, f_buff ); rc = DoSpawn( path, &exeparm ); if( cp ) { CheckPointRestore( where ); } return( rc ); }