Skip to content

Commit 81f912d

Browse files
committed
Revert "Merge pull request #95 from hattne/mkstemp"
This reverts commit feeac19, reversing changes made to 2cb404e.
1 parent 972a2b4 commit 81f912d

File tree

16 files changed

+194
-142
lines changed

16 files changed

+194
-142
lines changed

CMakeLists.txt

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,15 @@ if(HAVE_UNISTD_H)
345345
endif()
346346

347347

348-
# Check for missing functions: fgetln(3) is in 4.4BSD; mkstemp(3) is
349-
# in 4.3BSD, POSIX.1-2001; realpath(3) is in 4.4BSD, POSIX.1-2001;
350-
# regex(3) is in POSIX.1-2001, POSIX.1-2008.
348+
# Check for missing functions: fgetln(3) is in 4.4BSD; realpath(3) is
349+
# in 4.4BSD, POSIX.1-2001; regcomp(3) is in POSIX.1-2001,
350+
# POSIX.1-2008.
351351
include(CheckSymbolExists)
352352
check_symbol_exists(fgetln "stdio.h" HAVE_FGETLN)
353353
if(HAVE_FGETLN)
354354
add_compile_definitions("HAVE_FGETLN")
355355
endif()
356356

357-
check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP)
358-
if(HAVE_MKSTEMP)
359-
add_compile_definitions("HAVE_MKSTEMP")
360-
endif()
361-
362357
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
363358
if(HAVE_REALPATH)
364359
add_compile_definitions("HAVE_REALPATH")
@@ -1121,10 +1116,6 @@ add_executable(cbf2nexus
11211116
"${CBF__EXAMPLES}/cbf2nexus.c")
11221117
target_link_libraries(cbf2nexus
11231118
cbf)
1124-
if(NOT HAVE_MKSTEMP)
1125-
target_sources(cbf2nexus
1126-
PRIVATE "${CBF__SRC}/mkstemp.c")
1127-
endif()
11281119

11291120
add_executable(nexus2cbf
11301121
"${CBF__EXAMPLES}/nexus2cbf.c")
@@ -1136,10 +1127,6 @@ add_executable(minicbf2nexus
11361127
"${CBF__EXAMPLES}/minicbf2nexus.c")
11371128
target_link_libraries(minicbf2nexus
11381129
cbf)
1139-
if(NOT HAVE_MKSTEMP)
1140-
target_sources(minicbf2nexus
1141-
PRIVATE "${CBF__SRC}/mkstemp.c")
1142-
endif()
11431130

11441131
add_executable(adscimg2cbf
11451132
"${CBF__EXAMPLES}/adscimg2cbf.c"
@@ -1162,19 +1149,11 @@ add_executable(convert_image
11621149
"${CBF__EXAMPLES}/convert_image.c")
11631150
target_link_libraries(convert_image
11641151
cbf)
1165-
if(NOT HAVE_MKSTEMP)
1166-
target_sources(convert_image
1167-
PRIVATE "${CBF__SRC}/mkstemp.c")
1168-
endif()
11691152

11701153
add_executable(convert_minicbf
11711154
"${CBF__EXAMPLES}/convert_minicbf.c")
11721155
target_link_libraries(convert_minicbf
11731156
cbf)
1174-
if(NOT HAVE_MKSTEMP)
1175-
target_sources(convert_minicbf
1176-
PRIVATE "${CBF__SRC}/mkstemp.c")
1177-
endif()
11781157

11791158
add_executable(makecbf
11801159
"${CBF__EXAMPLES}/makecbf.c")
@@ -1211,30 +1190,13 @@ add_executable(img2cif
12111190
"${CBF__EXAMPLES}/img2cif.c")
12121191
target_link_libraries(img2cif
12131192
cbf)
1214-
if(NOT HAVE_MKSTEMP)
1215-
target_sources(img2cif
1216-
PRIVATE "${CBF__SRC}/mkstemp.c")
1217-
endif()
1218-
1219-
add_executable(cif2c
1220-
"${CBF__EXAMPLES}/cif2c.c")
1221-
target_link_libraries(cif2c
1222-
cbf)
1223-
if(NOT HAVE_MKSTEMP)
1224-
target_sources(cif2c
1225-
PRIVATE "${CBF__SRC}/mkstemp.c")
1226-
endif()
12271193

12281194
add_executable(cif2cbf
12291195
"${CBF__EXAMPLES}/cif2cbf.c")
12301196
target_link_libraries(cif2cbf
12311197
cbf
12321198
CQR
12331199
"${libm}")
1234-
if(NOT HAVE_MKSTEMP)
1235-
target_sources(cif2cbf
1236-
PRIVATE "${CBF__SRC}/mkstemp.c")
1237-
endif()
12381200

12391201
add_executable(cbf_template_t
12401202
"${CBF__DECTRIS_EXAMPLES}/cbf_template_t.c")
@@ -1262,10 +1224,6 @@ add_executable(sequence_match
12621224
"${CBF__EXAMPLES}/sequence_match.c")
12631225
target_link_libraries(sequence_match
12641226
cbf)
1265-
if(NOT HAVE_MKSTEMP)
1266-
target_sources(sequence_match
1267-
PRIVATE "${CBF__SRC}/mkstemp.c")
1268-
endif()
12691227

12701228
add_executable(test_cbf_airy_disk
12711229
"${CBF__EXAMPLES}/test_cbf_airy_disk.c")

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,9 @@ endif
733733
CC = gcc
734734
C++ = g++
735735
ifneq ($(CBFDEBUG),)
736-
CFLAGS = -g -O0 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DCBFDEBUG=1 -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
736+
CFLAGS = -g -O0 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_REALPATH -DCBFDEBUG=1 -DHAVE_UNISTD_H $(HDF5CFLAGS)
737737
else
738-
CFLAGS = -g -O3 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
738+
CFLAGS = -g -O3 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
739739
endif
740740
LDFLAGS =
741741
F90C = gfortran

Makefile_LINUX

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ endif
732732
#########################################################
733733
CC = gcc
734734
C++ = g++
735-
CFLAGS = -g -O2 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
735+
CFLAGS = -g -O2 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
736736
LDFLAGS =
737737
F90C = gfortran
738738
#F90FLAGS = -g -fno-range-check -fallow-invalid-boz

Makefile_MSYS2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,8 @@ endif
733733
CC = gcc
734734
C++ = g++
735735
CFLAGS = -g -O2 -Wall -D_USE_XOPEN_EXTENDED -DH5_HAVE_WIN32_API \
736-
-DH5_HAVE_MINGW -DH5_USE_110_API -fno-strict-aliasing -DHAVE_MKSTEMP \
737-
-DHAVE_UNISTD_H $(HDF5CFLAGS)
736+
-DH5_HAVE_MINGW -DH5_USE_110_API -fno-strict-aliasing -DHAVE_UNISTD_H \
737+
$(HDF5CFLAGS)
738738
LDFLAGS =
739739
F90C = gfortran
740740
#F90FLAGS = -g -fno-range-check -fallow-invalid-boz

Makefile_OSX

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ endif
732732
#########################################################
733733
CC = gcc
734734
C++ = g++
735-
CFLAGS = -g -O2 -Wall -std=c99 -pedantic -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
735+
CFLAGS = -g -O2 -Wall -std=c99 -pedantic -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
736736
LDFLAGS =
737737
F90C = gfortran
738738
#F90FLAGS = -g -fno-range-check -fallow-invalid-boz

examples/cbf2nexus.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@
259259

260260
#define C2CBUFSIZ 8192
261261

262-
#ifndef HAVE_MKSTEMP
263-
#define mkstemp _cbf_mkstemp
264-
int
265-
_cbf_mkstemp(char *templ);
262+
#ifdef __MINGW32__
263+
#define NOMKSTEMP
264+
#define NOTMPDIR
266265
#endif
267266

268267
int local_exit (int status);
@@ -651,20 +650,34 @@ int main (int argc, char *argv [])
651650

652651
for (f = 0; CBF_SUCCESS == error && f != cifid; ++f) {
653652
cbf_handle cif = NULL;
653+
#ifdef NOTMPDIR
654+
char ciftmp[] = "cif2cbfXXXXXX";
655+
#else
654656
char ciftmp[] = "/tmp/cif2cbfXXXXXX";
655657
int ciftmpfd;
658+
#endif
656659
/* Get suitable file - reading from stdin to a temporary file if needed */
657660
if (!(cifin[f]) || strcmp(cifin[f]?cifin[f]:"","-") == 0) {
658661
FILE *file = NULL;
659662
int nbytes;
660663
char buf[C2CBUFSIZ];
664+
#ifdef NOMKSTEMP
665+
if (mktemp(ciftmp) == NULL ) {
666+
fprintf(stderr,"%s: Can't create temporary file name %s.\n%s\n", argv[0], ciftmp,strerror(errno));
667+
error |= CBF_FILEOPEN;
668+
} else if ((file = fopen(ciftmp,"wb+")) == NULL) {
669+
fprintf(stderr,"Can't open temporary file %s.\n%s\n", ciftmp,strerror(errno));
670+
error |= CBF_FILEOPEN;
671+
}
672+
#else
661673
if ((ciftmpfd = mkstemp(ciftmp)) == -1 ) {
662674
fprintf(stderr,"%s: Can't create temporary file %s.\n%s\n", argv[0], ciftmp,strerror(errno));
663675
error |= CBF_FILEOPEN;
664676
} else if ((file = fdopen(ciftmpfd, "w+")) == NULL) {
665677
fprintf(stderr,"Can't open temporary file %s.\n%s\n", ciftmp,strerror(errno));
666678
error |= CBF_FILEOPEN;
667679
}
680+
#endif
668681
while ((nbytes = fread(buf, 1, C2CBUFSIZ, stdin))) {
669682
if((size_t)nbytes != fwrite(buf, 1, nbytes, file)) {
670683
fprintf(stderr,"Failed to write %s.\n", ciftmp);

examples/cif2c.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,9 @@
309309

310310
#define C2CBUFSIZ 8192
311311

312-
#ifndef HAVE_MKSTEMP
313-
# define mkstemp _cbf_mkstemp
314-
int
315-
_cbf_mkstemp(char *templ);
312+
#ifdef __MINGW32__
313+
#define NOMKSTEMP
314+
#define NOTMPDIR
316315
#endif
317316

318317

@@ -341,7 +340,12 @@ int main (int argc, char *argv [])
341340
int errflg = 0;
342341
const char *cifin, *codeout, *function_name;
343342
char ciftmp[19];
343+
#ifdef NOMKSTEMP
344+
char *xciftmp;
345+
#endif
346+
#ifndef NOMKSTEMP
344347
int ciftmpfd;
348+
#endif
345349
int ciftmpused;
346350
unsigned int nbytes;
347351
char buf[C2CBUFSIZ];
@@ -430,7 +434,23 @@ int main (int argc, char *argv [])
430434
/* Read the cif */
431435

432436
if (!cifin || strcmp(cifin?cifin:"","-") == 0) {
437+
#ifdef NOTMPDIR
438+
strcpy(ciftmp, "cif2cXXXXXX");
439+
#else
433440
strcpy(ciftmp, "/tmp/cif2cXXXXXX");
441+
#endif
442+
#ifdef NOMKSTEMP
443+
if ((xciftmp=mktemp(ciftmp)) == NULL ) {
444+
fprintf(stderr,"\n cif2c: Can't create temporary file name %s.\n", ciftmp);
445+
fprintf(stderr,"%s\n",strerror(errno));
446+
exit(1);
447+
}
448+
if ( (file = fopen(ciftmp,"wb+")) == NULL) {
449+
fprintf(stderr,"Can't open temporary file %s.\n", ciftmp);
450+
fprintf(stderr,"%s\n",strerror(errno));
451+
exit(1);
452+
}
453+
#else
434454
if ((ciftmpfd = mkstemp(ciftmp)) == -1 ) {
435455
fprintf(stderr,"Can't create temporary file %s.\n", ciftmp);
436456
fprintf(stderr,"%s\n",strerror(errno));
@@ -441,6 +461,7 @@ int main (int argc, char *argv [])
441461
fprintf(stderr,"%s\n",strerror(errno));
442462
exit(1);
443463
}
464+
#endif
444465
while ((nbytes = fread(buf, 1, C2CBUFSIZ, stdin))) {
445466
if(nbytes != fwrite(buf, 1, nbytes, file)) {
446467
fprintf(stderr,"Failed to write %s.\n", ciftmp);

examples/cif2cbf.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,9 @@
505505
#define C2CBUFSIZ 8192
506506
#define NUMDICTS 50
507507

508-
#ifndef HAVE_MKSTEMP
509-
#define mkstemp _cbf_mkstemp
510-
int
511-
_cbf_mkstemp(char *templ);
508+
#ifdef __MINGW32__
509+
#define NOMKSTEMP
510+
#define NOTMPDIR
512511
#endif
513512

514513
#define HDR_FINDDIMS 0x0040 /* On read, find header dims */
@@ -827,7 +826,9 @@ int main (int argc, char *argv [])
827826
const char *dictionary[NUMDICTS];
828827
int dqrflags[NUMDICTS];
829828
char *ciftmp=NULL;
829+
#ifndef NOMKSTEMP
830830
int ciftmpfd;
831+
#endif
831832
int ciftmpused;
832833
int padflag;
833834
int dimflag;
@@ -1696,7 +1697,23 @@ int main (int argc, char *argv [])
16961697

16971698
if (!cifin || strcmp(cifin?cifin:"","-") == 0) {
16981699
ciftmp = (char *)malloc(strlen("/tmp/cif2cbfXXXXXX")+1);
1700+
#ifdef NOTMPDIR
1701+
strcpy(ciftmp, "cif2cbfXXXXXX");
1702+
#else
16991703
strcpy(ciftmp, "/tmp/cif2cbfXXXXXX");
1704+
#endif
1705+
#ifdef NOMKSTEMP
1706+
if ((ciftmp = mktemp(ciftmp)) == NULL ) {
1707+
fprintf(stderr,"\n cif2cbf: Can't create temporary file name %s.\n", ciftmp);
1708+
fprintf(stderr,"%s\n",strerror(errno));
1709+
exit(1);
1710+
}
1711+
if ( (file = fopen(ciftmp,"wb+")) == NULL) {
1712+
fprintf(stderr,"Can't open temporary file %s.\n", ciftmp);
1713+
fprintf(stderr,"%s\n",strerror(errno));
1714+
exit(1);
1715+
}
1716+
#else
17001717
if ((ciftmpfd = mkstemp(ciftmp)) == -1 ) {
17011718
fprintf(stderr,"\n cif2cbf: Can't create temporary file %s.\n", ciftmp);
17021719
fprintf(stderr,"%s\n",strerror(errno));
@@ -1707,6 +1724,7 @@ int main (int argc, char *argv [])
17071724
fprintf(stderr,"%s\n",strerror(errno));
17081725
exit(1);
17091726
}
1727+
#endif
17101728
while ((nbytes = fread(buf, 1, C2CBUFSIZ, stdin))) {
17111729
if(nbytes != fwrite(buf, 1, nbytes, file)) {
17121730
fprintf(stderr,"Failed to write %s.\n", ciftmp);

examples/convert_image.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@
309309
# include <unistd.h>
310310
#endif
311311

312-
#ifndef HAVE_MKSTEMP
313-
# define mkstemp _cbf_mkstemp
314-
int
315-
_cbf_mkstemp(char *templ);
316-
#endif
317312

318313

319314
double rint(double);
@@ -531,7 +526,7 @@ int main (int argc, char *argv [])
531526
int copt;
532527
int errflg = 0;
533528
char * imgtmp=NULL;
534-
int imgtmpfd = -1;
529+
int imgtmpused = 0;
535530
const char *imgin, *cbfout, *template, *distancestr, *alias;
536531
cbf_detector detector;
537532
char *tag, *data, *root;
@@ -676,13 +671,12 @@ int main (int argc, char *argv [])
676671
if (!imgin || strcmp(imgin?imgin:"","-") == 0) {
677672
imgtmp = (char *)malloc(strlen("/tmp/cvt_imgXXXXXX")+1);
678673
strcpy(imgtmp, "/tmp/cvt_imgXXXXXX");
679-
if ((imgtmpfd = mkstemp(imgtmp)) == -1 ) {
674+
if ((imgin = mktemp(imgtmp)) == NULL ) {
680675
fprintf(stderr,"\n convert_image: Can't create temporary file name %s.\n", imgtmp);
681676
fprintf(stderr,"%s\n",strerror(errno));
682677
exit(1);
683678
}
684-
close(imgtmpfd);
685-
imgin = imgtmp;
679+
imgtmpused = 1;
686680
}
687681

688682
/* Read the image */
@@ -691,7 +685,7 @@ int main (int argc, char *argv [])
691685

692686
cbf_failnez (img_read (img, imgin))
693687

694-
if (imgtmpfd != -1)
688+
if (imgtmpused)
695689
{
696690
if (unlink(imgtmp) != 0 ) {
697691
fprintf(stderr," convert_image: Can't unlink temporary file %s.\n", imgtmp);

0 commit comments

Comments
 (0)