MCPcopy Create free account
hub / github.com/boostorg/build / open_command_file

Function open_command_file

src/engine/execnt.c:1228–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1226 */
1227
1228static FILE * open_command_file( int const slot )
1229{
1230 string * const command_file = cmdtab[ slot ].command_file;
1231
1232 /* If the temporary command file name has not already been prepared for this
1233 * slot number, prepare a new one containing a '##' place holder that will
1234 * be changed later and needs to be located at a fixed distance from the
1235 * end.
1236 */
1237 if ( !command_file->value )
1238 {
1239 DWORD const procID = GetCurrentProcessId();
1240 string const * const tmpdir = path_tmpdir();
1241 string_new( command_file );
1242 string_reserve( command_file, tmpdir->size + 64 );
1243 command_file->size = sprintf( command_file->value,
1244 "%s\\jam%d-%02d-##.bat", tmpdir->value, procID, slot );
1245 }
1246
1247 /* For some reason opening a command file can fail intermittently. But doing
1248 * some retries works. Most likely this is due to a previously existing file
1249 * of the same name that happens to still be opened by an active virus
1250 * scanner. Originally pointed out and fixed by Bronek Kozicki.
1251 *
1252 * We first try to open several differently named files to avoid having to
1253 * wait idly if not absolutely necessary. Our temporary command file names
1254 * contain a fixed position place holder we use for generating different
1255 * file names.
1256 */
1257 {
1258 char * const index1 = command_file->value + command_file->size - 6;
1259 char * const index2 = index1 + 1;
1260 int waits_remaining;
1261 assert( command_file->value < index1 );
1262 assert( index2 + 1 < command_file->value + command_file->size );
1263 assert( index2[ 1 ] == '.' );
1264 for ( waits_remaining = 3; ; --waits_remaining )
1265 {
1266 int index;
1267 for ( index = 0; index != 20; ++index )
1268 {
1269 FILE * f;
1270 *index1 = '0' + index / 10;
1271 *index2 = '0' + index % 10;
1272 f = fopen( command_file->value, "w" );
1273 if ( f ) return f;
1274 }
1275 if ( !waits_remaining ) break;
1276 Sleep( 250 );
1277 }
1278 }
1279
1280 return 0;
1281}
1282
1283
1284/*

Callers 1

prepare_command_fileFunction · 0.85

Calls 3

path_tmpdirFunction · 0.85
string_newFunction · 0.85
string_reserveFunction · 0.85

Tested by

no test coverage detected