| 366 | } |
| 367 | |
| 368 | static FILE *open_stub(void) |
| 369 | { |
| 370 | if (g_inline) |
| 371 | { |
| 372 | if (!g_stubstream) |
| 373 | { |
| 374 | g_stubstream = fopen("STUB.h", "w"); |
| 375 | if (g_stubstream == NULL) |
| 376 | { |
| 377 | fprintf(stderr, "Failed to open STUB.h: %s\n", |
| 378 | strerror(errno)); |
| 379 | exit(9); |
| 380 | } |
| 381 | |
| 382 | fprintf(g_stubstream, "/* Autogenerated STUB header file */\n\n"); |
| 383 | fprintf(g_stubstream, "#ifndef __STUB_H\n"); |
| 384 | fprintf(g_stubstream, "#define __STUB_H\n\n"); |
| 385 | } |
| 386 | |
| 387 | return g_stubstream; |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | char filename[MAX_PARMSIZE + 8]; |
| 392 | FILE *stream; |
| 393 | |
| 394 | snprintf(filename, MAX_PARMSIZE + 7, "STUB_%s.c", g_parm[NAME_INDEX]); |
| 395 | filename[MAX_PARMSIZE + 7] = '\0'; |
| 396 | |
| 397 | stream = fopen(filename, "w"); |
| 398 | |
| 399 | if (stream == NULL) |
| 400 | { |
| 401 | fprintf(stderr, "Failed to open %s: %s\n", filename, |
| 402 | strerror(errno)); |
| 403 | exit(9); |
| 404 | } |
| 405 | |
| 406 | return stream; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | static void stub_close(FILE *stream) |
| 411 | { |