Commit b09f3ac6db8416e10b0174e0a477c9f7ac7355a1
1 parent
28325580
Exists in
master
and in
3 other branches
Testando no MinGW64
Showing
1 changed file
with
58 additions
and
0 deletions
Show diff stats
mkfb.c
| ... | ... | @@ -38,6 +38,14 @@ |
| 38 | 38 | |
| 39 | 39 | #include "../include/lib3270/config.h" |
| 40 | 40 | |
| 41 | + | |
| 42 | +#ifdef _WIN32 | |
| 43 | + #include <windows.h> | |
| 44 | + #include <sys/stat.h> | |
| 45 | + #include <fcntl.h> | |
| 46 | + #define tmpfile w32_tmpfile | |
| 47 | +#endif // _WIN32 | |
| 48 | + | |
| 41 | 49 | #include <stdio.h> |
| 42 | 50 | #include <string.h> |
| 43 | 51 | #include <ctype.h> |
| ... | ... | @@ -575,3 +583,53 @@ emit(FILE *t, int ix, char c) |
| 575 | 583 | fprintf(t, "%3d,", (unsigned char)c); |
| 576 | 584 | n_out[ix]++; |
| 577 | 585 | } |
| 586 | + | |
| 587 | +#if defined(_WIN32) | |
| 588 | +FILE * w32_tmpfile( void ) | |
| 589 | +{ | |
| 590 | + char *dir; | |
| 591 | + char *xtemplate; | |
| 592 | + DWORD retval; | |
| 593 | + size_t len; | |
| 594 | + int fd; | |
| 595 | + FILE *file = NULL; | |
| 596 | + | |
| 597 | + dir = (char *) malloc(PATH_MAX); | |
| 598 | + xtemplate = (char *) malloc(PATH_MAX); | |
| 599 | + | |
| 600 | + /* Find Windows temporary file directory. | |
| 601 | + We provide this as the directory argument to path_search | |
| 602 | + because Windows defines P_tmpdir to "\\" and will therefore | |
| 603 | + try to put all temporary files in the root (unless $TMPDIR | |
| 604 | + is set). */ | |
| 605 | + retval = GetTempPath (PATH_MAX, dir); | |
| 606 | + if (retval == 0 || retval >= PATH_MAX - 1) | |
| 607 | + goto done; | |
| 608 | + | |
| 609 | + do | |
| 610 | + { | |
| 611 | + char *tempname = tempnam(dir,"XXXXXX"); | |
| 612 | + if(!tempname) | |
| 613 | + goto done; | |
| 614 | + | |
| 615 | + fd = _open (tempname,_O_BINARY | _O_CREAT | _O_TEMPORARY | _O_EXCL | _O_RDWR,_S_IREAD | _S_IWRITE); | |
| 616 | + } | |
| 617 | + while (fd < 0 && errno == EEXIST); | |
| 618 | + | |
| 619 | + if (fd < 0) | |
| 620 | + goto done; | |
| 621 | + | |
| 622 | + file = _fdopen (fd, "w+b"); | |
| 623 | + if (file == NULL) | |
| 624 | + { | |
| 625 | + int save_errno = errno; | |
| 626 | + _close (fd); | |
| 627 | + errno = save_errno; | |
| 628 | + } | |
| 629 | + | |
| 630 | + done: | |
| 631 | + free(xtemplate); | |
| 632 | + free(dir); | |
| 633 | + return file; | |
| 634 | +} | |
| 635 | +#endif // _WIN32 | ... | ... |