Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,20 @@ if(HAVE_UNISTD_H)
endif()


# Check for missing functions: fgetln(3) is in 4.4BSD; realpath(3) is
# in 4.4BSD, POSIX.1-2001; regcomp(3) is in POSIX.1-2001,
# POSIX.1-2008.
# Check for missing functions: fgetln(3) is in 4.4BSD; mkstemp(3) is
# in 4.3BSD, POSIX.1-2001; realpath(3) is in 4.4BSD, POSIX.1-2001;
# regex(3) is in POSIX.1-2001, POSIX.1-2008.
include(CheckSymbolExists)
check_symbol_exists(fgetln "stdio.h" HAVE_FGETLN)
if(HAVE_FGETLN)
add_compile_definitions("HAVE_FGETLN")
endif()

check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP)
if(HAVE_MKSTEMP)
add_compile_definitions("HAVE_MKSTEMP")
endif()

check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
if(HAVE_REALPATH)
add_compile_definitions("HAVE_REALPATH")
Expand Down Expand Up @@ -1116,6 +1121,10 @@ add_executable(cbf2nexus
"${CBF__EXAMPLES}/cbf2nexus.c")
target_link_libraries(cbf2nexus
cbf)
if(NOT HAVE_MKSTEMP)
target_sources(cbf2nexus
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(nexus2cbf
"${CBF__EXAMPLES}/nexus2cbf.c")
Expand All @@ -1127,6 +1136,10 @@ add_executable(minicbf2nexus
"${CBF__EXAMPLES}/minicbf2nexus.c")
target_link_libraries(minicbf2nexus
cbf)
if(NOT HAVE_MKSTEMP)
target_sources(minicbf2nexus
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(adscimg2cbf
"${CBF__EXAMPLES}/adscimg2cbf.c"
Expand All @@ -1149,11 +1162,19 @@ add_executable(convert_image
"${CBF__EXAMPLES}/convert_image.c")
target_link_libraries(convert_image
cbf)
if(NOT HAVE_MKSTEMP)
target_sources(convert_image
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(convert_minicbf
"${CBF__EXAMPLES}/convert_minicbf.c")
target_link_libraries(convert_minicbf
cbf)
if(NOT HAVE_MKSTEMP)
target_sources(convert_minicbf
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(makecbf
"${CBF__EXAMPLES}/makecbf.c")
Expand Down Expand Up @@ -1190,13 +1211,30 @@ add_executable(img2cif
"${CBF__EXAMPLES}/img2cif.c")
target_link_libraries(img2cif
cbf)
if(NOT HAVE_MKSTEMP)
target_sources(img2cif
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(cif2c
"${CBF__EXAMPLES}/cif2c.c")
target_link_libraries(cif2c
cbf)
if(NOT HAVE_MKSTEMP)
target_sources(cif2c
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(cif2cbf
"${CBF__EXAMPLES}/cif2cbf.c")
target_link_libraries(cif2cbf
cbf
CQR
"${libm}")
if(NOT HAVE_MKSTEMP)
target_sources(cif2cbf
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(cbf_template_t
"${CBF__DECTRIS_EXAMPLES}/cbf_template_t.c")
Expand Down Expand Up @@ -1224,6 +1262,10 @@ add_executable(sequence_match
"${CBF__EXAMPLES}/sequence_match.c")
target_link_libraries(sequence_match
cbf)
if(NOT HAVE_MKSTEMP)
target_sources(sequence_match
PRIVATE "${CBF__SRC}/mkstemp.c")
endif()

add_executable(test_cbf_airy_disk
"${CBF__EXAMPLES}/test_cbf_airy_disk.c")
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -731,9 +731,9 @@ endif
CC = gcc
C++ = g++
ifneq ($(CBFDEBUG),)
CFLAGS = -g -O0 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_REALPATH -DCBFDEBUG=1 -DHAVE_UNISTD_H $(HDF5CFLAGS)
CFLAGS = -g -O0 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DCBFDEBUG=1 -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
else
CFLAGS = -g -O3 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
CFLAGS = -g -O3 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
endif
LDFLAGS =
F90C = gfortran
Expand Down
2 changes: 1 addition & 1 deletion Makefile_LINUX
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ endif
#########################################################
CC = gcc
C++ = g++
CFLAGS = -g -O2 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
CFLAGS = -g -O2 -Wall -D_USE_XOPEN_EXTENDED -fno-strict-aliasing -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
LDFLAGS =
F90C = gfortran
#F90FLAGS = -g -fno-range-check -fallow-invalid-boz
Expand Down
4 changes: 2 additions & 2 deletions Makefile_MSYS2
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ endif
CC = gcc
C++ = g++
CFLAGS = -g -O2 -Wall -D_USE_XOPEN_EXTENDED -DH5_HAVE_WIN32_API \
-DH5_HAVE_MINGW -DH5_USE_110_API -fno-strict-aliasing -DHAVE_UNISTD_H \
$(HDF5CFLAGS)
-DH5_HAVE_MINGW -DH5_USE_110_API -fno-strict-aliasing -DHAVE_MKSTEMP \
-DHAVE_UNISTD_H $(HDF5CFLAGS)
LDFLAGS =
F90C = gfortran
#F90FLAGS = -g -fno-range-check -fallow-invalid-boz
Expand Down
2 changes: 1 addition & 1 deletion Makefile_OSX
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ endif
#########################################################
CC = gcc
C++ = g++
CFLAGS = -g -O2 -Wall -std=c99 -pedantic -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
CFLAGS = -g -O2 -Wall -std=c99 -pedantic -DHAVE_MKSTEMP -DHAVE_REALPATH -DHAVE_UNISTD_H $(HDF5CFLAGS)
LDFLAGS =
F90C = gfortran
#F90FLAGS = -g -fno-range-check -fallow-invalid-boz
Expand Down
21 changes: 4 additions & 17 deletions examples/cbf2nexus.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@

#define C2CBUFSIZ 8192

#ifdef __MINGW32__
#define NOMKSTEMP
#define NOTMPDIR
#ifndef HAVE_MKSTEMP
#define mkstemp _cbf_mkstemp
int
_cbf_mkstemp(char *templ);
#endif

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

for (f = 0; CBF_SUCCESS == error && f != cifid; ++f) {
cbf_handle cif = NULL;
#ifdef NOTMPDIR
char ciftmp[] = "cif2cbfXXXXXX";
#else
char ciftmp[] = "/tmp/cif2cbfXXXXXX";
int ciftmpfd;
#endif
/* Get suitable file - reading from stdin to a temporary file if needed */
if (!(cifin[f]) || strcmp(cifin[f]?cifin[f]:"","-") == 0) {
FILE *file = NULL;
int nbytes;
char buf[C2CBUFSIZ];
#ifdef NOMKSTEMP
if (mktemp(ciftmp) == NULL ) {
fprintf(stderr,"%s: Can't create temporary file name %s.\n%s\n", argv[0], ciftmp,strerror(errno));
error |= CBF_FILEOPEN;
} else if ((file = fopen(ciftmp,"wb+")) == NULL) {
fprintf(stderr,"Can't open temporary file %s.\n%s\n", ciftmp,strerror(errno));
error |= CBF_FILEOPEN;
}
#else
if ((ciftmpfd = mkstemp(ciftmp)) == -1 ) {
fprintf(stderr,"%s: Can't create temporary file %s.\n%s\n", argv[0], ciftmp,strerror(errno));
error |= CBF_FILEOPEN;
} else if ((file = fdopen(ciftmpfd, "w+")) == NULL) {
fprintf(stderr,"Can't open temporary file %s.\n%s\n", ciftmp,strerror(errno));
error |= CBF_FILEOPEN;
}
#endif
while ((nbytes = fread(buf, 1, C2CBUFSIZ, stdin))) {
if((size_t)nbytes != fwrite(buf, 1, nbytes, file)) {
fprintf(stderr,"Failed to write %s.\n", ciftmp);
Expand Down
29 changes: 4 additions & 25 deletions examples/cif2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@

#define C2CBUFSIZ 8192

#ifdef __MINGW32__
#define NOMKSTEMP
#define NOTMPDIR
#ifndef HAVE_MKSTEMP
# define mkstemp _cbf_mkstemp
int
_cbf_mkstemp(char *templ);
#endif


Expand Down Expand Up @@ -340,12 +341,7 @@ int main (int argc, char *argv [])
int errflg = 0;
const char *cifin, *codeout, *function_name;
char ciftmp[19];
#ifdef NOMKSTEMP
char *xciftmp;
#endif
#ifndef NOMKSTEMP
int ciftmpfd;
#endif
int ciftmpused;
unsigned int nbytes;
char buf[C2CBUFSIZ];
Expand Down Expand Up @@ -434,23 +430,7 @@ int main (int argc, char *argv [])
/* Read the cif */

if (!cifin || strcmp(cifin?cifin:"","-") == 0) {
#ifdef NOTMPDIR
strcpy(ciftmp, "cif2cXXXXXX");
#else
strcpy(ciftmp, "/tmp/cif2cXXXXXX");
#endif
#ifdef NOMKSTEMP
if ((xciftmp=mktemp(ciftmp)) == NULL ) {
fprintf(stderr,"\n cif2c: Can't create temporary file name %s.\n", ciftmp);
fprintf(stderr,"%s\n",strerror(errno));
exit(1);
}
if ( (file = fopen(ciftmp,"wb+")) == NULL) {
fprintf(stderr,"Can't open temporary file %s.\n", ciftmp);
fprintf(stderr,"%s\n",strerror(errno));
exit(1);
}
#else
if ((ciftmpfd = mkstemp(ciftmp)) == -1 ) {
fprintf(stderr,"Can't create temporary file %s.\n", ciftmp);
fprintf(stderr,"%s\n",strerror(errno));
Expand All @@ -461,7 +441,6 @@ int main (int argc, char *argv [])
fprintf(stderr,"%s\n",strerror(errno));
exit(1);
}
#endif
while ((nbytes = fread(buf, 1, C2CBUFSIZ, stdin))) {
if(nbytes != fwrite(buf, 1, nbytes, file)) {
fprintf(stderr,"Failed to write %s.\n", ciftmp);
Expand Down
26 changes: 4 additions & 22 deletions examples/cif2cbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,10 @@
#define C2CBUFSIZ 8192
#define NUMDICTS 50

#ifdef __MINGW32__
#define NOMKSTEMP
#define NOTMPDIR
#ifndef HAVE_MKSTEMP
#define mkstemp _cbf_mkstemp
int
_cbf_mkstemp(char *templ);
#endif

#define HDR_FINDDIMS 0x0040 /* On read, find header dims */
Expand Down Expand Up @@ -826,9 +827,7 @@ int main (int argc, char *argv [])
const char *dictionary[NUMDICTS];
int dqrflags[NUMDICTS];
char *ciftmp=NULL;
#ifndef NOMKSTEMP
int ciftmpfd;
#endif
int ciftmpused;
int padflag;
int dimflag;
Expand Down Expand Up @@ -1697,23 +1696,7 @@ int main (int argc, char *argv [])

if (!cifin || strcmp(cifin?cifin:"","-") == 0) {
ciftmp = (char *)malloc(strlen("/tmp/cif2cbfXXXXXX")+1);
#ifdef NOTMPDIR
strcpy(ciftmp, "cif2cbfXXXXXX");
#else
strcpy(ciftmp, "/tmp/cif2cbfXXXXXX");
#endif
#ifdef NOMKSTEMP
if ((ciftmp = mktemp(ciftmp)) == NULL ) {
fprintf(stderr,"\n cif2cbf: Can't create temporary file name %s.\n", ciftmp);
fprintf(stderr,"%s\n",strerror(errno));
exit(1);
}
if ( (file = fopen(ciftmp,"wb+")) == NULL) {
fprintf(stderr,"Can't open temporary file %s.\n", ciftmp);
fprintf(stderr,"%s\n",strerror(errno));
exit(1);
}
#else
if ((ciftmpfd = mkstemp(ciftmp)) == -1 ) {
fprintf(stderr,"\n cif2cbf: Can't create temporary file %s.\n", ciftmp);
fprintf(stderr,"%s\n",strerror(errno));
Expand All @@ -1724,7 +1707,6 @@ int main (int argc, char *argv [])
fprintf(stderr,"%s\n",strerror(errno));
exit(1);
}
#endif
while ((nbytes = fread(buf, 1, C2CBUFSIZ, stdin))) {
if(nbytes != fwrite(buf, 1, nbytes, file)) {
fprintf(stderr,"Failed to write %s.\n", ciftmp);
Expand Down
14 changes: 10 additions & 4 deletions examples/convert_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@
# include <unistd.h>
#endif

#ifndef HAVE_MKSTEMP
# define mkstemp _cbf_mkstemp
int
_cbf_mkstemp(char *templ);
#endif


double rint(double);
Expand Down Expand Up @@ -526,7 +531,7 @@ int main (int argc, char *argv [])
int copt;
int errflg = 0;
char * imgtmp=NULL;
int imgtmpused = 0;
int imgtmpfd = -1;
const char *imgin, *cbfout, *template, *distancestr, *alias;
cbf_detector detector;
char *tag, *data, *root;
Expand Down Expand Up @@ -671,12 +676,13 @@ int main (int argc, char *argv [])
if (!imgin || strcmp(imgin?imgin:"","-") == 0) {
imgtmp = (char *)malloc(strlen("/tmp/cvt_imgXXXXXX")+1);
strcpy(imgtmp, "/tmp/cvt_imgXXXXXX");
if ((imgin = mktemp(imgtmp)) == NULL ) {
if ((imgtmpfd = mkstemp(imgtmp)) == -1 ) {
fprintf(stderr,"\n convert_image: Can't create temporary file name %s.\n", imgtmp);
fprintf(stderr,"%s\n",strerror(errno));
exit(1);
}
imgtmpused = 1;
close(imgtmpfd);
imgin = imgtmp;
}

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

cbf_failnez (img_read (img, imgin))

if (imgtmpused)
if (imgtmpfd != -1)
{
if (unlink(imgtmp) != 0 ) {
fprintf(stderr," convert_image: Can't unlink temporary file %s.\n", imgtmp);
Expand Down
Loading