follow-up: make the ifdef logic a bit clearer

This commit is contained in:
nhmall
2022-12-12 14:37:40 -05:00
parent 9e91064659
commit 71c26361ff

View File

@@ -379,41 +379,41 @@ getfp(const char* template, const char* tag, const char* mode, int flg)
char *name = name_file(template, tag); char *name = name_file(template, tag);
FILE *rv = (FILE *) 0; FILE *rv = (FILE *) 0;
boolean istemp = (flg & FLG_TEMPFILE) != 0; boolean istemp = (flg & FLG_TEMPFILE) != 0;
#ifdef MD_USE_TMPFILE_S
errno_t err;
#endif
#if !defined(HAS_NO_MKSTEMP) && !defined(MD_USE_TMPFILE_S) #if !defined(HAS_NO_MKSTEMP) && !defined(MD_USE_TMPFILE_S)
char tmpfbuf[MAXFNAMELEN]; char tmpfbuf[MAXFNAMELEN];
int tmpfd; int tmpfd;
#endif #endif
#if !defined(HAS_NO_MKSTEMP) || defined(MD_USE_TMPFILE_S)
if (istemp) {
#ifdef MD_USE_TMPFILE_S #ifdef MD_USE_TMPFILE_S
errno_t err;
#endif
#if defined(MD_USE_TMPFILE_S)
if (istemp) {
err = tmpfile_s(&rv); err = tmpfile_s(&rv);
#if defined(MSDOS) || defined(WIN32) #if defined(MSDOS) || defined(WIN32)
if (!err && (!strcmp(mode, WRTMODE) || !strcmp(mode, RDTMODE))) { if (!err && (!strcmp(mode, WRTMODE) || !strcmp(mode, RDTMODE))) {
_setmode(fileno(rv), O_TEXT); _setmode(fileno(rv), O_TEXT);
} }
#endif #endif
#else /* !MD_USE_TMPFILE_S */ } else
#else /* MD_USE_TMPFILE_S */
#ifndef HAS_NO_MKSTEMP
if (istemp) {
(void) snprintf(tmpfbuf, sizeof tmpfbuf, DATA_TEMPLATE, "mdXXXXXX"); (void) snprintf(tmpfbuf, sizeof tmpfbuf, DATA_TEMPLATE, "mdXXXXXX");
tmpfd = mkstemp(tmpfbuf); tmpfd = mkstemp(tmpfbuf);
if (tmpfd >= 0) { if (tmpfd >= 0) {
rv = fdopen(tmpfd, WRTMODE); /* temp file is always read+write */ rv = fdopen(tmpfd, WRTMODE); /* temp file is always read+write */
Unlink(tmpfbuf); Unlink(tmpfbuf);
} }
#endif /* ?MD_USE_TMPFILE_S */
} else } else
#endif /* !HAS_NO_MKSTEMP || MD_USE_TMPFILE_S */ #endif
rv = fopen(name, mode); #endif /* MD_USE_TMPFILE_S */
rv = fopen(name, mode);
if (!rv) { if (!rv) {
Fprintf(stderr, "Can't open '%s' (mode=%s).\n", Fprintf(stderr, "Can't open '%s' (mode=%s).\n",
#ifndef HAS_NO_MKSTEMP #if !defined(HAS_NO_MKSTEMP) && !defined(MD_USE_TMPFILE_S)
#if !defined(MD_USE_TMPFILE_S)
istemp ? tmpfbuf : istemp ? tmpfbuf :
#endif
#endif #endif
name, mode); name, mode);
makedefs_exit(EXIT_FAILURE); makedefs_exit(EXIT_FAILURE);