Changeset 104480 in vbox
- Timestamp:
- May 2, 2024 2:17:45 PM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/VBoxBs3Obj2Hdr.cpp
r104470 r104480 241 241 242 242 243 int main(int argc, char **argv)243 static RTEXITCODE makeParfaitHappy(int argc, char **argv, FILE **ppOutput, const char **ppszOutput) 244 244 { 245 245 /* … … 247 247 */ 248 248 bool fDashDash = false; 249 const char *pszOutput = NULL;250 FILE *pOutput = NULL;249 *ppszOutput = NULL; 250 *ppOutput = NULL; 251 251 for (int i = 1; i < argc; i++) 252 252 { … … 306 306 307 307 case 'o': 308 if (pOutput && pOutput != stdout) 309 fclose(pOutput); /** @todo check status. */ 310 pOutput = NULL; 311 pszOutput = pszValue; 308 { 309 FILE * const pOldOutput = *ppOutput; 310 *ppOutput = NULL; 311 if (pOldOutput && pOldOutput != stdout) 312 { 313 if (fclose(pOldOutput)) 314 { 315 fprintf(stderr, "error: Write/close error on '%s'\n", *ppszOutput); 316 return RTEXITCODE_FAILURE; 317 } 318 } 319 *ppszOutput = pszValue; 312 320 continue; 321 } 313 322 314 323 case 'q': … … 338 347 { 339 348 /* Make sure we've got an output file. */ 340 if (! pOutput)341 { 342 if (! pszOutput || strcmp(pszOutput, "-") == 0)343 pOutput = stdout;349 if (!*ppOutput) 350 { 351 if (!*ppszOutput || strcmp(*ppszOutput, "-") == 0) 352 *ppOutput = stdout; 344 353 else 345 354 { 346 pOutput = fopen(pszOutput, "w");347 if (! pOutput)348 { 349 fprintf(stderr, "error: Failed to open '%s' for writing!\n", pszOutput);355 *ppOutput = fopen(*ppszOutput, "w"); 356 if (!*ppOutput) 357 { 358 fprintf(stderr, "error: Failed to open '%s' for writing!\n", *ppszOutput); 350 359 return RTEXITCODE_FAILURE; 351 360 } … … 357 366 void *pvFile; 358 367 if (!readfile(pszArg, &pvFile, &cbFile)) 359 {360 if (pOutput)361 fclose(pOutput);362 368 return RTEXITCODE_FAILURE; 363 } 364 365 RTEXITCODE rcExit = ProcessObjectFile(pOutput, (uint8_t const *)pvFile, cbFile, pszArg); 369 370 RTEXITCODE rcExit = ProcessObjectFile(*ppOutput, (uint8_t const *)pvFile, cbFile, pszArg); 366 371 367 372 free(pvFile); 368 373 if (rcExit != RTEXITCODE_SUCCESS) 369 {370 if (pOutput)371 fclose(pOutput);372 374 return rcExit; 373 }374 375 } 375 376 } 376 377 378 return RTEXITCODE_SUCCESS; 379 } 380 381 382 int main(int argc, char **argv) 383 { 377 384 /* 378 * Flush+close output exit. 385 * Use helper function to do the actual main work so we can perform 386 * cleanup to make pedantic static analysers happy. 387 */ 388 const char *pszOutput = NULL; 389 FILE *pOutput = NULL; 390 RTEXITCODE rcExit = makeParfaitHappy(argc, argv, &pOutput, &pszOutput); 391 392 /* 393 * Flush+close output before we exit. 379 394 */ 380 395 if (pOutput) … … 384 399 { 385 400 fprintf(stderr, "error: Write error on '%s'\n", pszOutput ? pszOutput : "-"); 386 r eturnRTEXITCODE_FAILURE;401 rcExit = RTEXITCODE_FAILURE; 387 402 } 388 403 } 389 390 return RTEXITCODE_SUCCESS; 404 return rcExit; 391 405 } 392 406
Note:
See TracChangeset
for help on using the changeset viewer.