diff --git a/ChangeLog b/ChangeLog index 5c6a6fdac25..2231adb90b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,120 @@ +2020-05-05 18:39 starseeker + + * [r75697] src/other/libregex/regex.h: + libregex doesn't appear to use lseek and it's making VS2019 + unhappy to redefine it. + +2020-05-04 17:35 starseeker + + * [r75687] include/bu/vls.h: + don't need stdio.h here + +2020-05-04 16:11 starseeker + + * [r75685] misc/attributes/gen-attributes-file.cpp: + ditto gen-attributes-file.cpp - needs off_t update + +2020-05-04 16:09 starseeker + + * [r75684] src/other/stepcode/src/clstepcore/complexSupport.h: + stepcode needs the same off_t bit + +2020-05-04 15:52 starseeker + + * [r75682] src/libpkg/pkg.c: + Use bio.h here + +2020-05-04 15:45 starseeker + + * [r75681] src/other/libregex/regex.h: + ws + +2020-05-04 15:44 starseeker + + * [r75680] src/other/libregex/regex.h: + Update our bundled regex.h to use the same type of off_t + definition as bio.h + +2020-05-04 15:23 starseeker + + * [r75679] ., include/bu/glob.h, include/bu/vls.h: + Cherrypick r75678 + +2020-05-04 14:08 starseeker + + * [r75677] ., include/bio.h, include/config_win.h.in, + src/conv/intaval/tgf-g.cpp, src/conv/k-g.cpp, + src/conv/raw/raw-g.cpp, src/libanalyze/nirt.cpp, + src/libgcv/plugins/fastgen4/fastgen4_write.cpp, + src/libgcv/plugins/vrml/vrml_read/file_util.cpp, + src/nirt/main.cpp: + Cherrypick r75077, r75078 and r75084 - off_t fixes + +2020-05-04 13:34 starseeker + + * [r75676] ., src/gtools/gchecker.cpp: + Cherrypick r75675 + +2020-05-04 13:07 starseeker + + * [r75674] ., bench/pixcmp.c, include/bio.h, include/bu/file.h, + include/bu/ptbl.h, include/bu/time.h, include/common.h, + include/rt/db_fullpath.h, include/rt/db_instance.h, + include/rt/db_io.h, include/rt/directory.h, include/rt/mater.h, + include/rt/mem.h, src/conv/asc/asc2g.c, src/conv/conv-vg2g.c, + src/conv/dxf/dxf-g.c, src/conv/fast4-g.c, src/conv/g-acad.c, + src/conv/g-obj.c, src/conv/iges/findp.c, src/conv/iges/g-iges.c, + src/conv/iges/readrec.c, src/conv/iges/recsize.c, + src/conv/intaval/tgf-g.cpp, src/conv/k-g.cpp, + src/conv/nastran-g.c, src/conv/raw/raw-g.cpp, + src/conv/vdeck/vdeck.c, src/conv/vdeck/vextern.h, src/fb/bw-fb.c, + src/fb/pix-fb.c, src/fb/tests/fbthreadtest.c, + src/gtools/gdiff/gdiff.c, src/libanalyze/nirt.cpp, src/libbu, + src/libbu/file.c, src/libbu/mappedfile.c, src/libbu/vfont.c, + src/libbu/vfont.h, src/libbu/vls.c, src/libfb/fb_generic.c, + src/libfb/if_X24.c, src/libfb/if_disk.c, + src/libgcv/plugins/fastgen4/fastgen4_read.c, + src/libgcv/plugins/fastgen4/fastgen4_write.cpp, + src/libgcv/plugins/obj/obj_write.c, + src/libgcv/plugins/vrml/vrml_read/file_util.cpp, + src/libged/dup.c, src/libged/ged.c, src/libged/tables.c, + src/libicv/rot.c, src/liboptical/oslexec_pvt.h, + src/librt/db5_alloc.c, src/librt/db5_scan.c, + src/librt/db_alloc.c, src/librt/db_corrupt.c, + src/librt/db_fullpath.c, src/librt/db_inmem.c, src/librt/db_io.c, + src/librt/db_lookup.c, src/librt/db_open.c, src/librt/db_scan.c, + src/librt/librt_private.h, src/librt/mater.c, + src/librt/memalloc.c, src/librt/primitives/primitive_util.c, + src/mged/edsol.c, src/mged/wdb_obj.c, src/nirt/main.cpp, + src/rt/do.c, src/rt/view.c, src/util/ap-pix.c, src/util/bwcrop.c, + src/util/bwhisteq.c, src/util/bwrot.c, src/util/bwscale.c, + src/util/pixbustup.c, src/util/pixcrop.c, src/util/pixrot.c, + src/util/pixscale.c, src/util/plot3rot.c: + Cherrypick r75063 - switch to b_off_t for newer MSVC 64 bit + offsets. + +2020-05-04 12:59 starseeker + + * [r75673] ., regress/gchecker/CMakeLists.txt: + Cherrypick r75672 - dependencies for regress-gchecker + +2020-05-04 12:52 starseeker + + * [r75671] ., NEWS, regress/CMakeLists.txt, regress/gchecker, + src/gtools/CMakeLists.txt, src/gtools/gchecker.cpp: + Cherrypick cross-platform generator of overlap outputs from trunk + +2020-05-04 12:50 starseeker + + * [r75670] src/libbu, src/libbu/dir.c: + Cherrypick r75000 from trunk - bu_dir fix for ext and libext + +2020-04-22 20:02 starseeker + + * [r75551] ChangeLog: + update changelog + + 2020-04-22 20:01 starseeker * [r75550] ., src/libged/draw.c, src/libged/vdraw.c, diff --git a/NEWS b/NEWS index b00d054b2f3..6edd4e683a8 100644 --- a/NEWS +++ b/NEWS @@ -10,9 +10,10 @@ descriptive text that emphasizes or further describes significant changes made. See document footer for additional details. ---------------------------------------------------------------------- ---- 2020-04-22 Release 7.30.8 --- +--- 2020-05-08 Release 7.30.8 --- ---------------------------------------------------------------------- +* added gchecker tool to generate MGED overlap inputs - Cliff Yapp * improved behavior of MGED overlap checker GUI - Nick Reed * fixed startup dimensions of overlap checker window - Nick Reed * fixed rtedge line drawing color when using -W flag - Cliff Yapp diff --git a/bench/pixcmp.c b/bench/pixcmp.c index d69279eef16..74617c26fe8 100644 --- a/bench/pixcmp.c +++ b/bench/pixcmp.c @@ -214,7 +214,7 @@ main(int argc, char *argv[]) } /* skip requested pixels/bytes in FILE1 */ - if (f1_skip && bu_fseek(f1, f1_skip, SEEK_SET)) { + if (f1_skip && fseek(f1, f1_skip, SEEK_SET)) { bu_log("ERROR: Unable to seek %zd %s%s in FILE1\n", f1_skip, print_bytes?"byte":"pixel", @@ -224,7 +224,7 @@ main(int argc, char *argv[]) } /* skip requested pixels in FILE2 */ - if (f2_skip && bu_fseek(f2, f2_skip, SEEK_SET)) { + if (f2_skip && fseek(f2, f2_skip, SEEK_SET)) { bu_log("ERROR: Unable to seek %zd %s%s in FILE2\n", f1_skip, print_bytes?"byte":"pixel", diff --git a/include/bio.h b/include/bio.h index 644d0862979..a2f8aa3291e 100644 --- a/include/bio.h +++ b/include/bio.h @@ -95,6 +95,35 @@ extern int fileno(FILE *stream); # define S_ISDIR(_st_mode) (((_st_mode) & S_IFMT) == S_IFDIR) #endif +/* We want 64 bit (large file) I/O capabilities whenever they are available. + * Always define this before we include sys/types.h */ +#ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +#endif +#include + +/* off_t is 32 bit size even on 64 bit Windows. In the past we have tried to + * force off_t to be 64 bit but this is failing on newer Windows/Visual Studio + * verions in 2020 - therefore, we instead introduce the b_off_t define to + * properly substitute the correct numerical type for the correct platform. */ +#if defined(_WIN64) +# include +# define b_off_t __int64 +# define fseek _fseeki64 +# define ftell _ftelli64 +# define fstat _fstati64 +# define lseek _lseeki64 +# define stat _stati64 +#elif defined (_WIN32) +# include +# define b_off_t _off_t +# define fstat _fstat +# define lseek _lseek +# define stat _stat +#else +# define b_off_t off_t +#endif + #endif /* BIO_H */ /** @} */ diff --git a/include/bu/file.h b/include/bu/file.h index b7d9abdda1b..cb2b0ad7ab5 100644 --- a/include/bu/file.h +++ b/include/bu/file.h @@ -24,7 +24,6 @@ #include "common.h" #include /* for FILE */ -#include /* for off_t */ #include /* for size_t */ #include /* for getenv */ @@ -165,23 +164,6 @@ BU_EXPORT extern size_t bu_file_list(const char *path, const char *pattern, char */ BU_EXPORT extern char *bu_file_realpath(const char *path, char *resolved_path); - -/** - * This wrapper appears to be necessary (at least on Visual Studio) to handle - * situations where 32 and 64 bit versions of this function have different - * function signatures (a simple define of the 32 bit version to the 64 bit - * version will produce compile errors.) - */ -BU_EXPORT extern int bu_fseek(FILE *stream, off_t offset, int origin); - -/** - * This wrapper appears to be necessary (at least on Visual Studio) to handle - * situations where 32 and 64 bit versions of this function have different - * function signatures (a simple define of the 32 bit version to the 64 bit - * version will produce compile errors.) - */ -BU_EXPORT extern off_t bu_ftell(FILE *stream); - /** @} */ __END_DECLS diff --git a/include/bu/glob.h b/include/bu/glob.h index 942ae8e97d6..261108529d4 100644 --- a/include/bu/glob.h +++ b/include/bu/glob.h @@ -23,7 +23,7 @@ #include "common.h" -#include /* for off_t */ +#include "bio.h" /* for b_off_t */ #include "bu/defines.h" #include "bu/vls.h" @@ -58,7 +58,7 @@ struct bu_dirent { */ struct bu_stat { struct bu_vls name; - off_t size; + b_off_t size; void *data; }; diff --git a/include/bu/ptbl.h b/include/bu/ptbl.h index 58486b68fcc..5a4fe639986 100644 --- a/include/bu/ptbl.h +++ b/include/bu/ptbl.h @@ -24,7 +24,7 @@ #include "common.h" #include /* for size_t */ -#include /* for off_t */ +#include "bio.h" /* for b_off_t */ #include "bu/defines.h" #include "bu/magic.h" diff --git a/include/bu/time.h b/include/bu/time.h index dcfb89d2bd4..bd595159d93 100644 --- a/include/bu/time.h +++ b/include/bu/time.h @@ -23,10 +23,9 @@ #include "common.h" -#include /* For FILE */ -#include /* for off_t */ #include /* for size_t */ #include /* for getenv */ +#include "bio.h" /* for b_off_t */ #include "bu/defines.h" #include "bu/vls.h" diff --git a/include/bu/vls.h b/include/bu/vls.h index b9a4a83ea30..bb291c2f1fe 100644 --- a/include/bu/vls.h +++ b/include/bu/vls.h @@ -22,11 +22,11 @@ #define BU_VLS_H #include "common.h" -#include /* For FILE */ -#include /* for off_t */ #include /* for size_t */ #include /* For va_list */ +#include "bio.h" /* for FILE and off_t */ + #include "bu/defines.h" #include "bu/magic.h" @@ -166,7 +166,7 @@ BU_EXPORT extern void bu_vls_trunc(struct bu_vls *vp, * un-nibbled. */ BU_EXPORT extern void bu_vls_nibble(struct bu_vls *vp, - off_t len); + b_off_t len); /** * Releases the memory used for the string buffer. diff --git a/include/common.h b/include/common.h index d0b3d75958c..57e0ac9006c 100644 --- a/include/common.h +++ b/include/common.h @@ -150,22 +150,6 @@ extern int snprintf(char *str, size_t size, const char *format, ...); # define FMIN(a, b) (((a)<(b))?(a):(b)) #endif -/* If we've got the wrong off_t size, do something about it (*before* - we include sys/types.h, which can hold the incorrect definition.) - Also set any other related defines that might be needed. */ -#if defined(OFF_T_SIZE_MISMATCH) -/*# pragma message("Fixing off_t definition")*/ -# ifdef off_t -# undef off_t -# endif -typedef ptrdiff_t off_t; -# ifdef _off_t -# undef _off_t -# endif -typedef ptrdiff_t _off_t; -# define _OFF_T_DEFINED -#endif - /* make sure the old bsd types are defined for portability */ #if !defined(HAVE_U_TYPES) typedef unsigned char u_char; diff --git a/include/config_win.h.in b/include/config_win.h.in index 88ed3eff210..06fc9ba6777 100644 --- a/include/config_win.h.in +++ b/include/config_win.h.in @@ -202,29 +202,6 @@ # define strtoll _strtoi64 #endif -/* set up stat */ -#if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8 -# define stat _stati64 -#else -# define stat _stat -#endif - -/* set up fstat */ -#if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8 -# define fstat _fstati64 -#else -# define fstat _fstat -#endif - -/* set up lseek */ -#ifndef HAVE_LSEEK -# if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8 -# define lseek _lseeki64 -# else -# define lseek _lseek -# endif -#endif - #cmakedefine fmax __max #define ioctl ioctlsocket diff --git a/include/rt/db_fullpath.h b/include/rt/db_fullpath.h index 88a1500f2e7..bc6fb876dba 100644 --- a/include/rt/db_fullpath.h +++ b/include/rt/db_fullpath.h @@ -22,6 +22,7 @@ #define RT_DB_FULLPATH_H #include "common.h" +#include "bio.h" /* for b_off_t */ #include "bu/vls.h" #include "rt/defines.h" @@ -93,7 +94,7 @@ RT_EXPORT extern void db_append_full_path(struct db_full_path *dest, */ RT_EXPORT extern void db_dup_path_tail(struct db_full_path *newp, const struct db_full_path *oldp, - off_t start); + b_off_t start); /** diff --git a/include/rt/db_instance.h b/include/rt/db_instance.h index 6cae1b535bc..320cecb5fc7 100644 --- a/include/rt/db_instance.h +++ b/include/rt/db_instance.h @@ -25,6 +25,7 @@ #define RT_DB_INSTANCE_H #include "common.h" +#include "bio.h" /* for b_off_t */ /* interface headers */ #include "bu/magic.h" @@ -76,7 +77,7 @@ struct db_i { struct directory * dbi_Head[RT_DBNHASH]; /** @brief PRIVATE: object hash table */ FILE * dbi_fp; /**< @brief PRIVATE: standard file pointer */ - off_t dbi_eof; /**< @brief PRIVATE: End+1 pos after db_scan() */ + b_off_t dbi_eof; /**< @brief PRIVATE: End+1 pos after db_scan() */ size_t dbi_nrec; /**< @brief PRIVATE: # records after db_scan() */ int dbi_uses; /**< @brief PRIVATE: # of uses of this struct */ struct mem_map * dbi_freep; /**< @brief PRIVATE: map of free granules */ diff --git a/include/rt/db_io.h b/include/rt/db_io.h index 6da5644526d..56012e6b0c6 100644 --- a/include/rt/db_io.h +++ b/include/rt/db_io.h @@ -33,7 +33,7 @@ #include "rt/defines.h" /* system headers */ -#include "bio.h" /* for FILE */ +#include "bio.h" /* for FILE, b_off_t */ __BEGIN_DECLS @@ -432,7 +432,7 @@ RT_EXPORT extern void db_wrap_v4_external(struct bu_external *op, RT_EXPORT extern int db_write(struct db_i *dbip, const void * addr, size_t count, - off_t offset); + b_off_t offset); /** * Add name from dp->d_namep to external representation of solid, and @@ -486,7 +486,7 @@ RT_EXPORT extern union record *db_getmrec(const struct db_i *, RT_EXPORT extern int db_get(const struct db_i *, const struct directory *dp, union record *where, - off_t offset, + b_off_t offset, size_t len); /* put several records into db */ @@ -501,7 +501,7 @@ RT_EXPORT extern int db_get(const struct db_i *, RT_EXPORT extern int db_put(struct db_i *, const struct directory *dp, union record *where, - off_t offset, size_t len); + b_off_t offset, size_t len); /** * Obtains a object from the database, leaving it in external @@ -548,7 +548,7 @@ RT_EXPORT extern int db_put_external(struct bu_external *ep, RT_EXPORT extern int db_scan(struct db_i *, int (*handler)(struct db_i *, const char *name, - off_t addr, + b_off_t addr, size_t nrec, int flags, void *client_data), @@ -641,7 +641,7 @@ RT_EXPORT extern int db_v4_get_units_code(const char *str); RT_EXPORT extern int db_dirbuild(struct db_i *dbip); RT_EXPORT extern struct directory *db5_diradd(struct db_i *dbip, const struct db5_raw_internal *rip, - off_t laddr, + b_off_t laddr, void *client_data); /** @@ -654,7 +654,7 @@ RT_EXPORT extern struct directory *db5_diradd(struct db_i *dbip, RT_EXPORT extern int db5_scan(struct db_i *dbip, void (*handler)(struct db_i *, const struct db5_raw_internal *, - off_t addr, + b_off_t addr, void *client_data), void *client_data); @@ -805,13 +805,13 @@ RT_EXPORT extern struct directory *db_lookup(const struct db_i *, */ RT_EXPORT extern struct directory *db_diradd(struct db_i *, const char *name, - off_t laddr, + b_off_t laddr, size_t len, int flags, void *ptr); RT_EXPORT extern struct directory *db_diradd5(struct db_i *dbip, const char *name, - off_t laddr, + b_off_t laddr, unsigned char major_type, unsigned char minor_type, unsigned char name_hidden, diff --git a/include/rt/directory.h b/include/rt/directory.h index fb0e239b7f7..0375c794375 100644 --- a/include/rt/directory.h +++ b/include/rt/directory.h @@ -25,6 +25,7 @@ #define RT_DIRECTORY_H #include "common.h" +#include "bio.h" /* for b_off_T */ #include "vmath.h" #include "bu/list.h" #include "rt/anim.h" @@ -35,7 +36,7 @@ __BEGIN_DECLS * One of these structures is allocated in memory to represent each * named object in the database. * - * Note that a d_addr of RT_DIR_PHONY_ADDR ((off_t)-1) means that + * Note that a d_addr of RT_DIR_PHONY_ADDR ((b_off_t)-1) means that * database storage has not been allocated yet. * * Note that there is special handling for RT_DIR_INMEM "in memory" @@ -60,7 +61,7 @@ struct directory { uint32_t d_magic; /**< @brief Magic number */ char * d_namep; /**< @brief pointer to name string */ union { - off_t file_offset; /**< @brief disk address in obj file */ + b_off_t file_offset; /**< @brief disk address in obj file */ void *ptr; /**< @brief ptr to in-memory-only obj */ } d_un; struct directory * d_forw; /**< @brief link to next dir entry */ @@ -79,7 +80,7 @@ struct directory { #define RT_CK_DIR(_dp) BU_CKMAG(_dp, RT_DIR_MAGIC, "(librt)directory") #define d_addr d_un.file_offset -#define RT_DIR_PHONY_ADDR ((off_t)-1) /**< @brief Special marker for d_addr field */ +#define RT_DIR_PHONY_ADDR ((b_off_t)-1) /**< @brief Special marker for d_addr field */ /* flags for db_diradd() and friends */ #define RT_DIR_SOLID 0x1 /**< @brief this name is a solid */ diff --git a/include/rt/mater.h b/include/rt/mater.h index f7c37e06014..06ca34ca081 100644 --- a/include/rt/mater.h +++ b/include/rt/mater.h @@ -25,6 +25,7 @@ #define RT_MATER_H #include "common.h" +#include "bio.h" /* for b_off_t */ #include "rt/defines.h" #include "bu/vls.h" @@ -53,11 +54,11 @@ struct mater { unsigned char mt_r; /**< @brief color */ unsigned char mt_g; unsigned char mt_b; - off_t mt_daddr; /**< @brief db address, for updating */ + b_off_t mt_daddr; /**< @brief db address, for updating */ struct mater *mt_forw; /**< @brief next in chain */ }; #define MATER_NULL ((struct mater *)0) -#define MATER_NO_ADDR ((off_t)0) /**< @brief invalid mt_daddr */ +#define MATER_NO_ADDR ((b_off_t)0) /**< @brief invalid mt_daddr */ RT_EXPORT extern void rt_region_color_map(struct region *regp); @@ -68,7 +69,7 @@ RT_EXPORT extern void rt_color_addrec(int low, int r, int g, int b, - off_t addr); + b_off_t addr); RT_EXPORT extern void rt_insert_color(struct mater *newp); RT_EXPORT extern void rt_vls_color_map(struct bu_vls *str); RT_EXPORT extern struct mater *rt_material_head(void); diff --git a/include/rt/mem.h b/include/rt/mem.h index e83eade93eb..07b1a0464f8 100644 --- a/include/rt/mem.h +++ b/include/rt/mem.h @@ -25,6 +25,7 @@ #define RT_MEM_H #include "common.h" +#include "bio.h" /* for b_off_t */ #include "vmath.h" #include "rt/defines.h" @@ -37,7 +38,7 @@ __BEGIN_DECLS struct mem_map { struct mem_map *m_nxtp; /**< @brief Linking pointer to next element */ size_t m_size; /**< @brief Size of this free element */ - off_t m_addr; /**< @brief Address of start of this element */ + b_off_t m_addr; /**< @brief Address of start of this element */ }; #define MAP_NULL ((struct mem_map *) 0) @@ -80,7 +81,7 @@ RT_EXPORT extern struct mem_map * rt_memalloc_nosplit(struct mem_map **pp, */ RT_EXPORT extern void rt_memfree(struct mem_map **pp, size_t size, - off_t addr); + b_off_t addr); /** * Take everything on the current memory chain, and place it on the diff --git a/misc/attributes/gen-attributes-file.cpp b/misc/attributes/gen-attributes-file.cpp index 951a5051d9c..ca80350c12d 100644 --- a/misc/attributes/gen-attributes-file.cpp +++ b/misc/attributes/gen-attributes-file.cpp @@ -14,8 +14,9 @@ /* needed on mac in c90 mode */ #ifndef HAVE_DECL_FSEEKO -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/regress/CMakeLists.txt b/regress/CMakeLists.txt index 91c63038f11..04cb4ab2878 100644 --- a/regress/CMakeLists.txt +++ b/regress/CMakeLists.txt @@ -52,6 +52,9 @@ add_subdirectory(rtwizard) # MGED command tests add_subdirectory(mged) +# gchecker tests +add_subdirectory(gchecker) + if(SH_EXEC) macro(Sh_Regression_Test testname depends_list) CMAKE_PARSE_ARGUMENTS(${testname} "EXCLUDE_FROM_REGRESS" "" "" ${ARGN}) diff --git a/regress/gchecker/CMakeLists.txt b/regress/gchecker/CMakeLists.txt new file mode 100644 index 00000000000..1e7a820644d --- /dev/null +++ b/regress/gchecker/CMakeLists.txt @@ -0,0 +1,44 @@ +if(CMAKE_CONFIGURATION_TYPES) + set(cfg_testname "-${CMAKE_CFG_INTDIR}") +else(CMAKE_CONFIGURATION_TYPES) + set(cfg_testname "") +endif(CMAKE_CONFIGURATION_TYPES) + +set(GCHECKER_CLEAN_FILES + gchecker_test.g.ck/ck.gchecker_test.g.overlaps + gchecker.log + ) + +set(LOG_FILE "${CMAKE_CURRENT_BINARY_DIR}/regress${cfg_testname}-gchecker.log") +set(STAMP_FILE "${CMAKE_CURRENT_BINARY_DIR}/gchecker${cfg_testname}.done") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/regress-gchecker.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/regress-gchecker.cmake" @ONLY) +add_custom_command( + OUTPUT "${STAMP_FILE}" + COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/regress-gchecker.cmake" + DEPENDS ${depends_list} + ) +add_test(NAME regress-gchecker COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/regress-gchecker.cmake") +add_custom_target(regress-gchecker DEPENDS gchecker mged gqa rtcheck "${STAMP_FILE}") +set_target_properties(regress-gchecker PROPERTIES FOLDER "BRL-CAD Regression Tests") +Add_Regression_Test(gchecker "gchecker;mged;gqa;rtcheck") + +CMAKEFILES( + CMakeLists.txt + gchecker_test.g + ) + +DISTCLEAN( + ${STAMP_FILE} + ${LOG_FILE} + ${TARGET_IMAGE} + ) +foreach(GCF ${GCHECKER_CLEAN_FILES}) + DISTCLEAN("${CMAKE_CURRENT_BINARY_DIR}/${GCF}") +endforeach(GCF ${GCHECKER_CLEAN_FILES}) + +# Local Variables: +# tab-width: 8 +# mode: cmake +# indent-tabs-mode: t +# End: +# ex: shiftwidth=2 tabstop=8 diff --git a/regress/gchecker/gchecker_test.g b/regress/gchecker/gchecker_test.g new file mode 100644 index 00000000000..0f33a930130 Binary files /dev/null and b/regress/gchecker/gchecker_test.g differ diff --git a/regress/gchecker/regress-gchecker.cmake.in b/regress/gchecker/regress-gchecker.cmake.in new file mode 100644 index 00000000000..ffbf7c5721b --- /dev/null +++ b/regress/gchecker/regress-gchecker.cmake.in @@ -0,0 +1,57 @@ +set(CBDIR "@CMAKE_CURRENT_BINARY_DIR@") +set(CSDIR "@CMAKE_CURRENT_SOURCE_DIR@") +set(DDIR "@DATA_DIR@") +set(GCHECKER_CF "@GCHECKER_CLEAN_FILES@") + +set(SBDIR "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@") +set(DBDIR "@CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG@") +set(RBDIR "@CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE@") +# Use the mechanism created to allow multiconfig builds to +# know what the current build type is. +if(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Release") + set(BDIR "${RBDIR}") + set(test_suffix "-Release") +elseif(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Debug") + set(BDIR "${DBDIR}") + set(test_suffix "-Debug") +else(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Release") + set(BDIR "${SBDIR}") + set(test_suffix) +endif(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Release") + +get_filename_component(EXE "@CMAKE_COMMAND@" EXT) +set(GCHECKER "${BDIR}/gchecker${EXE}") + +# Clean up in case we've run before +foreach(GCF ${GCHECKER_CF}) + execute_process(COMMAND "@CMAKE_COMMAND@" -E remove -f "${CBDIR}/${GCF}") +endforeach(GCF ${GCHECKER_CF}) +execute_process(COMMAND "@CMAKE_COMMAND@" -E remove_directory "${CBDIR}/gchecker_test.g.ck") + +file(WRITE "${CBDIR}/gchecker.log" "Running gchecker:\n${GCHECKER} ${CSDIR}/gchecker_test.g\n") + +execute_process( + COMMAND "${GCHECKER}" "${CSDIR}/gchecker_test.g" RESULT_VARIABLE gchecker_result + OUTPUT_VARIABLE gchecker_log ERROR_VARIABLE gchecker_log + WORKING_DIRECTORY ${CBDIR} + ) +file(APPEND "${CBDIR}/gchecker.log" "${gchecker_log}") +set(gchecker_log) +if(NOT EXISTS "${CBDIR}/gchecker_test.g.ck/ck.gchecker_test.g.overlaps") + message(FATAL_ERROR "${GCHECKER} failed to process gchecker_test.g, aborting.\nSee ${CBDIR}/gchecker.log for more details.") +endif(NOT EXISTS "${CBDIR}/gchecker_test.g.ck/ck.gchecker_test.g.overlaps") + +if(gchecker_result) + file(APPEND "${CBDIR}/gchecker.log" "\n\nError: return code ${gchecker_result}") + message(FATAL_ERROR "[gchecker] Failure, see ${CBDIR}/gchecker.log for more info.\n") +else(gchecker_result) + execute_process(COMMAND "@CMAKE_COMMAND@" -E touch "@CMAKE_CURRENT_BINARY_DIR@/gchecker${test_suffix}.done") +endif(gchecker_result) + +# Local Variables: +# tab-width: 8 +# mode: cmake +# indent-tabs-mode: t +# End: +# ex: shiftwidth=2 tabstop=8 + diff --git a/src/conv/asc/asc2g.c b/src/conv/asc/asc2g.c index cf8d1783435..97174c728b4 100644 --- a/src/conv/asc/asc2g.c +++ b/src/conv/asc/asc2g.c @@ -1038,7 +1038,7 @@ polyhbld(void) { char *cp; char *name; - off_t startpos; + b_off_t startpos; size_t nlines; struct rt_pg_internal *pg; struct rt_db_internal intern; @@ -1049,7 +1049,7 @@ polyhbld(void) name = bu_strdup(cp); /* Count up the number of poly data lines which follow */ - startpos = bu_ftell(ifp); + startpos = ftell(ifp); for (nlines = 0;; nlines++) { if (bu_fgets(buf, BUFSIZE, ifp) == NULL) break; if (buf[0] != ID_P_DATA) break; /* 'Q' */ @@ -1065,7 +1065,7 @@ polyhbld(void) pg->max_npts = 0; /* Return to first 'Q' record */ - bu_fseek(ifp, startpos, 0); + fseek(ifp, startpos, 0); for (nlines = 0; nlines < pg->npoly; nlines++) { struct rt_pg_face_internal *fp = &pg->poly[nlines]; diff --git a/src/conv/conv-vg2g.c b/src/conv/conv-vg2g.c index ef51b4fde2e..3a70b3a5b0c 100644 --- a/src/conv/conv-vg2g.c +++ b/src/conv/conv-vg2g.c @@ -206,7 +206,7 @@ main(int argc, char **argv) case ID_ARS_A: if (rec.a.a_name[0] == '\0') { /* Skip deleted junk */ - lseek(ifd, (off_t)(rec.a.a_totlen * sizeof(rec)), 1); + lseek(ifd, (b_off_t)(rec.a.a_totlen * sizeof(rec)), 1); goto top; } rec.a.a_xmin *= factor; diff --git a/src/conv/dxf/dxf-g.c b/src/conv/dxf/dxf-g.c index 723d1ad996f..6e615d895b5 100644 --- a/src/conv/dxf/dxf-g.c +++ b/src/conv/dxf/dxf-g.c @@ -62,7 +62,7 @@ struct insert_data { struct state_data { struct bu_list l; struct block_list *curr_block; - off_t file_offset; + b_off_t file_offset; int state; int sub_state; mat_t xform; @@ -107,7 +107,7 @@ struct layer { struct block_list { struct bu_list l; char *block_name; - off_t offset; + b_off_t offset; char handle[17]; point_t base; }; @@ -629,7 +629,7 @@ process_blocks_code(int code) } else if (!bu_strncmp(line, "BLOCK", 5)) { /* start of a new block */ BU_ALLOC(curr_block, struct block_list); - curr_block->offset = bu_ftell(dxf); + curr_block->offset = ftell(dxf); BU_LIST_INSERT(&(block_head), &(curr_block->l)); break; } @@ -1109,7 +1109,7 @@ process_entities_unknown_code(int code) break; } bu_free((char *)tmp_state, "curr_state"); - bu_fseek(dxf, curr_state->file_offset, SEEK_SET); + fseek(dxf, curr_state->file_offset, SEEK_SET); curr_state->sub_state = UNKNOWN_ENTITY_STATE; if (verbose) { bu_log("Popped state at end of inserted block (seeked to %jd)\n", (intmax_t)curr_state->file_offset); @@ -1223,7 +1223,7 @@ process_insert_entities_code(int code) BU_LIST_PUSH(&state_stack, &(curr_state->l)); curr_state = new_state; new_state = NULL; - bu_fseek(dxf, curr_state->curr_block->offset, SEEK_SET); + fseek(dxf, curr_state->curr_block->offset, SEEK_SET); curr_state->state = ENTITIES_SECTION; curr_state->sub_state = UNKNOWN_ENTITY_STATE; if (verbose) { @@ -2504,7 +2504,7 @@ process_dimension_entities_code(int code) BU_LIST_PUSH(&state_stack, &(curr_state->l)); curr_state = new_state; new_state = NULL; - bu_fseek(dxf, curr_state->curr_block->offset, SEEK_SET); + fseek(dxf, curr_state->curr_block->offset, SEEK_SET); curr_state->state = ENTITIES_SECTION; curr_state->sub_state = UNKNOWN_ENTITY_STATE; if (verbose) { @@ -3083,7 +3083,7 @@ readcodes() size_t line_len; static int line_num = 0; - curr_state->file_offset = bu_ftell(dxf); + curr_state->file_offset = ftell(dxf); if (bu_fgets(line, MAX_LINE_SIZE, dxf) == NULL) { return ERROR_FLAG; diff --git a/src/conv/fast4-g.c b/src/conv/fast4-g.c index 2a4c43f0faf..499f895799c 100644 --- a/src/conv/fast4-g.c +++ b/src/conv/fast4-g.c @@ -2062,10 +2062,10 @@ make_bot_object(void) static void skip_section(void) { - off_t section_start; + b_off_t section_start; /* skip to start of next section */ - section_start = bu_ftell(fpin); + section_start = ftell(fpin); if (section_start < 0) { bu_exit(1, "Error: couldn't get input file's current file position.\n"); } @@ -2076,7 +2076,7 @@ skip_section(void) bu_strncmp(line, "WALL", 4) && bu_strncmp(line, "VEHICLE", 7)) { - section_start = bu_ftell(fpin); + section_start = ftell(fpin); if (section_start < 0) { bu_exit(1, "Error: couldn't get input file's current file position.\n"); } @@ -2085,7 +2085,7 @@ skip_section(void) } } /* seek to start of the section */ - bu_fseek(fpin, section_start, SEEK_SET); + fseek(fpin, section_start, SEEK_SET); } diff --git a/src/conv/g-acad.c b/src/conv/g-acad.c index 12086c6aae0..8c5cd16b922 100644 --- a/src/conv/g-acad.c +++ b/src/conv/g-acad.c @@ -649,7 +649,7 @@ main(int argc, char **argv) /* Write out number of facet entities to .facet file */ rewind(fp); - bu_fseek(fp, 46, 0); /* Re-position pointer to 2nd line */ + fseek(fp, 46, 0); /* Re-position pointer to 2nd line */ fprintf(fp, "%d\n", regions_written); /* Write out number of regions */ fclose(fp); diff --git a/src/conv/g-obj.c b/src/conv/g-obj.c index 4d8f4940845..c7ed9f50f90 100644 --- a/src/conv/g-obj.c +++ b/src/conv/g-obj.c @@ -59,8 +59,8 @@ print_usage(const char *progname) } -static off_t vert_offset=0; -static off_t norm_offset=0; +static b_off_t vert_offset=0; +static b_off_t norm_offset=0; static int do_normals=0; static int NMG_debug; /* saved arg of -X, for longjmp handling */ static int verbose=0; diff --git a/src/conv/iges/findp.c b/src/conv/iges/findp.c index 93faa7d8367..d88e6d56628 100644 --- a/src/conv/iges/findp.c +++ b/src/conv/iges/findp.c @@ -36,7 +36,7 @@ Findp() { int saverec, rec2; size_t i; - off_t offset; + b_off_t offset; char str[8]; str[7] = '\0'; @@ -44,13 +44,13 @@ Findp() saverec = currec; /* save current record number */ - if (bu_fseek(fd, 0, 2)) { + if (fseek(fd, 0, 2)) { /* go to end of file */ bu_log("Cannot seek to end of file\n"); perror("Findp"); bu_exit(1, NULL); } - offset = bu_ftell(fd); /* get file length */ + offset = ftell(fd); /* get file length */ rec2 = offset/reclen; /* calculate record number for last record */ Readrec(rec2); /* read last record into "card" buffer */ dstart = 0; diff --git a/src/conv/iges/g-iges.c b/src/conv/iges/g-iges.c index 2064add10e1..7348341c36c 100644 --- a/src/conv/iges/g-iges.c +++ b/src/conv/iges/g-iges.c @@ -402,7 +402,7 @@ main(int argc, char *argv[]) if (!multi_file) { /* Copy the parameter section from the temporary file to the output file */ - if ((bu_fseek(fp_param, 0, 0))) { + if ((fseek(fp_param, 0, 0))) { perror("g-iges"); bu_exit(1, "Cannot seek to start of temporary file\n"); } @@ -619,7 +619,7 @@ do_nmg_region_end(struct db_tree_state *tsp, const struct db_full_path *pathp, u char copy_buffer[CP_BUF_SIZE] = {0}; /* Copy the parameter section from the temporary file to the output file */ - if ((bu_fseek(fp_param, 0, 0))) { + if ((fseek(fp_param, 0, 0))) { perror("g-iges"); bu_exit(1, "Cannot seek to start of temporary file\n"); } diff --git a/src/conv/iges/readrec.c b/src/conv/iges/readrec.c index 04e5b6e2899..fd4ffe804e0 100644 --- a/src/conv/iges/readrec.c +++ b/src/conv/iges/readrec.c @@ -40,11 +40,11 @@ Readrec(int recno) { int i, ch; - off_t offset; + b_off_t offset; currec = recno; offset = (recno - 1) * reclen; - if (bu_fseek(fd, offset, 0)) { + if (fseek(fd, offset, 0)) { bu_log("Error in seek\n"); perror("Readrec"); bu_exit(1, NULL); diff --git a/src/conv/iges/recsize.c b/src/conv/iges/recsize.c index 266c46f0410..4ac8948e8a1 100644 --- a/src/conv/iges/recsize.c +++ b/src/conv/iges/recsize.c @@ -68,7 +68,7 @@ Recsize() if (k == (-1)) /* We didn't encounter an early EOF */ k = NRECS; - if (bu_fseek(fd, 0, 0)) { + if (fseek(fd, 0, 0)) { /* rewind file */ bu_log("Cannot rewind file\n"); perror("Recsize"); diff --git a/src/conv/intaval/tgf-g.cpp b/src/conv/intaval/tgf-g.cpp index 4d7ce77d2e6..1318c14afa6 100644 --- a/src/conv/intaval/tgf-g.cpp +++ b/src/conv/intaval/tgf-g.cpp @@ -34,9 +34,9 @@ #include #ifndef HAVE_DECL_FSEEKO -#include /* for off_t */ -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" /* for b_off_t */ +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/src/conv/k-g.cpp b/src/conv/k-g.cpp index 23d38012740..fc3359d72d5 100644 --- a/src/conv/k-g.cpp +++ b/src/conv/k-g.cpp @@ -30,8 +30,9 @@ #include #ifndef HAVE_DECL_FSEEKO -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" /* for b_off_t */ +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/src/conv/nastran-g.c b/src/conv/nastran-g.c index 42b8a54d412..2e179ebe88a 100644 --- a/src/conv/nastran-g.c +++ b/src/conv/nastran-g.c @@ -108,7 +108,7 @@ static struct rt_wdb *fpout; /* brlcad output file */ static FILE *fpin; /* NASTRAN input file */ static FILE *fptmp; /* temporary version of NASTRAN input */ static char *usage = "[-xX lvl] [-t tol.dist] [-n] [-m] [-i NASTRAN_file] -o BRL-CAD_file\n"; -static off_t start_off; +static b_off_t start_off; static char *delims=", \t"; static struct coord_sys coord_head; /* head of linked list of coordinate systems */ static struct pbar pbar_head; /* head of linked list of PBAR's */ @@ -161,7 +161,7 @@ reset_input(void) for (i=0; i < 20; i++) prev_rec[i][0] = '\0'; - bu_fseek(fpin, start_off, SEEK_SET); + fseek(fpin, start_off, SEEK_SET); line_count = bulk_data_start_line; tmp = bu_fgets(next_line, MAX_LINE_SIZE, fpin); @@ -1193,7 +1193,7 @@ main(int argc, char **argv) if (bu_strncmp(line, "BEGIN BULK", 10)) continue; - start_off = bu_ftell(fpin); + start_off = ftell(fpin); break; } @@ -1219,7 +1219,7 @@ main(int argc, char **argv) nmg_model = (struct model *)NULL; /* count grid points */ - bu_fseek(fptmp, 0, SEEK_SET); + fseek(fptmp, 0, SEEK_SET); while (bu_fgets(line, MAX_LINE_SIZE, fptmp)) { if (!bu_strncmp(line, "GRID", 4)) grid_count++; @@ -1229,7 +1229,7 @@ main(int argc, char **argv) } /* get default values and properties */ - bu_fseek(fptmp, 0, SEEK_SET); + fseek(fptmp, 0, SEEK_SET); while (get_next_record(fptmp, 1, 0)) { if (!bu_strncmp(curr_rec[0], "BAROR", 5)) { /* get BAR defaults */ @@ -1262,7 +1262,7 @@ main(int argc, char **argv) g_pts = (struct grid_point *)bu_calloc(grid_count, sizeof(struct grid_point), "grid points"); /* get all grid points */ - bu_fseek(fptmp, 0, SEEK_SET); + fseek(fptmp, 0, SEEK_SET); while (get_next_record(fptmp, 1, 0)) { int gid; int cid; @@ -1287,7 +1287,7 @@ main(int argc, char **argv) /* find coordinate systems */ - bu_fseek(fptmp, 0, SEEK_SET); + fseek(fptmp, 0, SEEK_SET); while (get_next_record(fptmp, 1, 0)) { if (bu_strncmp(curr_rec[0], "CORD", 4)) continue; @@ -1306,7 +1306,7 @@ main(int argc, char **argv) mk_id(fpout, nastran_file); /* get elements */ - bu_fseek(fptmp, 0, SEEK_SET); + fseek(fptmp, 0, SEEK_SET); while (get_next_record(fptmp, 1, 0)) { if (!bu_strncmp(curr_rec[0], "CBAR", 4)) get_cbar(); diff --git a/src/conv/raw/raw-g.cpp b/src/conv/raw/raw-g.cpp index 17da37ba6cb..5c2452b2d55 100644 --- a/src/conv/raw/raw-g.cpp +++ b/src/conv/raw/raw-g.cpp @@ -33,8 +33,9 @@ #include #ifndef HAVE_DECL_FSEEKO -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" /* for b_off_t */ +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/src/conv/vdeck/vdeck.c b/src/conv/vdeck/vdeck.c index 22efe245186..d4e94864e9b 100644 --- a/src/conv/vdeck/vdeck.c +++ b/src/conv/vdeck/vdeck.c @@ -144,7 +144,7 @@ int ndir; /* Entries in directory. */ /* Miscellaneous globals leftover from Keith's KARDS code. */ int delsol = 0, delreg = 0; char buff[30]; -off_t savsol; /* File position of # of solids & regions */ +b_off_t savsol; /* File position of # of solids & regions */ /* Structures. */ mat_t identity; @@ -1218,7 +1218,7 @@ deck(char *prefix) ewrite(solfp, LF, 1); /* Save space for number of solids and regions. */ - savsol = bu_ftell(solfp); + savsol = ftell(solfp); if (savsol < 0) { perror("ftell"); } @@ -1272,7 +1272,7 @@ deck(char *prefix) /* Go back, and add number of solids and regions on second card. */ if (savsol >= 0) - bu_fseek(solfp, savsol, 0); + fseek(solfp, savsol, 0); vdeck_itoa(nns, buff, 5); ewrite(solfp, buff, 5); diff --git a/src/conv/vdeck/vextern.h b/src/conv/vdeck/vextern.h index 21e1eb971c2..c2996400aef 100644 --- a/src/conv/vdeck/vextern.h +++ b/src/conv/vdeck/vextern.h @@ -80,7 +80,7 @@ extern int ndir, nns, nnr; extern int delsol, delreg; extern char buff[]; -extern off_t savsol; +extern b_off_t savsol; extern jmp_buf env; #define EPSILON 0.0001 diff --git a/src/fb/bw-fb.c b/src/fb/bw-fb.c index aaf886361ed..fb37944eaec 100644 --- a/src/fb/bw-fb.c +++ b/src/fb/bw-fb.c @@ -46,7 +46,7 @@ #include "fb.h" -int skipbytes(int fd, off_t num); +int skipbytes(int fd, b_off_t num); #define MAX_LINE (16*1024) /* Largest output scan line length */ @@ -334,7 +334,7 @@ main(int argc, char **argv) * Throw bytes away. Use reads into ibuf buffer if a pipe, else seek. */ int -skipbytes(int fd, off_t num) +skipbytes(int fd, b_off_t num) { int n, tries; diff --git a/src/fb/pix-fb.c b/src/fb/pix-fb.c index d216d298ae4..5f00e8dfcb3 100644 --- a/src/fb/pix-fb.c +++ b/src/fb/pix-fb.c @@ -186,7 +186,7 @@ get_args(int argc, char **argv) * Throw bytes away. Use reads into scanline buffer if a pipe, else seek. */ int -skipbytes(int fd, off_t num) +skipbytes(int fd, b_off_t num) { int n, tries; @@ -309,7 +309,7 @@ main(int argc, char **argv) } } - if (file_yoff != 0) skipbytes(infd, (off_t)file_yoff*(off_t)file_width*sizeof(RGBpixel)); + if (file_yoff != 0) skipbytes(infd, (b_off_t)file_yoff*(b_off_t)file_width*sizeof(RGBpixel)); if (multiple_lines) { /* Bottom to top with multi-line reads & writes */ @@ -340,11 +340,11 @@ main(int argc, char **argv) /* Normal way -- bottom to top */ for (y = scr_yoff; y < scr_yoff + yout; y++) { if (y < 0 || y > scr_height) { - skipbytes(infd, (off_t)file_width*sizeof(RGBpixel)); + skipbytes(infd, (b_off_t)file_width*sizeof(RGBpixel)); continue; } if (file_xoff+xskip != 0) - skipbytes(infd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel)); + skipbytes(infd, (b_off_t)(file_xoff+xskip)*sizeof(RGBpixel)); n = bu_mread(infd, (char *)scanline, scanbytes); if (n <= 0) break; m = fb_write(fbp, xstart, y, scanline, xout); @@ -356,17 +356,17 @@ main(int argc, char **argv) } /* slop at the end of the line? */ if ((size_t)file_xoff+xskip+scanpix < file_width) - skipbytes(infd, (off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel)); + skipbytes(infd, (b_off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel)); } } else { /* Inverse -- top to bottom */ for (y = scr_height-1-scr_yoff; y >= scr_height-scr_yoff-yout; y--) { if (y < 0 || y >= scr_height) { - skipbytes(infd, (off_t)file_width*sizeof(RGBpixel)); + skipbytes(infd, (b_off_t)file_width*sizeof(RGBpixel)); continue; } if (file_xoff+xskip != 0) - skipbytes(infd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel)); + skipbytes(infd, (b_off_t)(file_xoff+xskip)*sizeof(RGBpixel)); n = bu_mread(infd, (char *)scanline, scanbytes); if (n <= 0) break; m = fb_write(fbp, xstart, y, scanline, xout); @@ -378,7 +378,7 @@ main(int argc, char **argv) } /* slop at the end of the line? */ if ((size_t)file_xoff+xskip+scanpix < file_width) - skipbytes(infd, (off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel)); + skipbytes(infd, (b_off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel)); } } bu_snooze(BU_SEC2USEC(pause_sec)); diff --git a/src/fb/tests/fbthreadtest.c b/src/fb/tests/fbthreadtest.c index 3534b7a91ca..530d11d2ede 100644 --- a/src/fb/tests/fbthreadtest.c +++ b/src/fb/tests/fbthreadtest.c @@ -93,7 +93,7 @@ static Tcl_ThreadCreateType threadprocprint(ClientData data) { } -int skipbytes(int fd, off_t num); +int skipbytes(int fd, b_off_t num); static unsigned char *scanline; /* 1 scanline pixel buffer */ static int scanbytes; /* # of bytes of scanline */ diff --git a/src/gtools/CMakeLists.txt b/src/gtools/CMakeLists.txt index fb12292eb0b..90063168d20 100644 --- a/src/gtools/CMakeLists.txt +++ b/src/gtools/CMakeLists.txt @@ -16,6 +16,7 @@ BRLCAD_ADDDATA(gtransfer.c sample_applications) BRLCAD_ADDEXEC(gex "gex.cpp" "libbu;librt") BRLCAD_ADDEXEC(glint glint.cpp "librt;${M_LIBRARY}") BRLCAD_ADDEXEC(gqa gqa.c "libged;librt") +BRLCAD_ADDEXEC(gchecker gchecker.cpp "libged;librt;libbu") set(GSH_SRCS gsh.cpp diff --git a/src/gtools/gchecker.cpp b/src/gtools/gchecker.cpp new file mode 100644 index 00000000000..59b265be360 --- /dev/null +++ b/src/gtools/gchecker.cpp @@ -0,0 +1,398 @@ +/* G C H E C K E R . C P P + * BRL-CAD + * + * Copyright (c) 2020 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file gchecker.cpp + * + * C++ version of the check.tcl logic generating overlap files used + * by the MGED Overlap Tool + * + */ + +#include "common.h" + +#ifdef HAVE_SYS_STAT_H +# include /* for mkdir */ +#endif + +#ifdef HAVE_WINDOWS_H +# include /* For chdir */ +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bu/app.h" +#include "bu/file.h" +#include "bu/opt.h" +#include "bu/path.h" +#include "ged.h" + +static void +_cmd_help(const char *usage, struct bu_opt_desc *d) +{ + struct bu_vls str = BU_VLS_INIT_ZERO; + char *option_help; + + bu_vls_sprintf(&str, "%s", usage); + + if ((option_help = bu_opt_describe(d, NULL))) { + bu_vls_printf(&str, "Options:\n%s\n", option_help); + bu_free(option_help, "help str"); + } + + bu_log("%s", bu_vls_cstr(&str)); + bu_vls_free(&str); +} + + +int +main(int argc, const char **argv) +{ + int print_help = 0; + int dry_run = 0; + int verbose = 0; + const char *usage = "Usage: gchecker [options] file.g [objects ...]\n\n"; + struct bu_opt_desc d[4]; + BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and exit"); + BU_OPT(d[1], "d", "dry-run", "", NULL, &dry_run, "Step through the checker stages, but don't raytrace"); + BU_OPT(d[2], "v", "verbose", "", NULL, &verbose, "Print verbose information about result processing"); + BU_OPT_NULL(d[3]); + + std::set> unique_pairs; + std::multimap, double> pair_sizes; + std::map, double> pair_avg_sizes; + + + bu_setprogname(argv[0]); + + argc-=(argc>0); argv+=(argc>0); + + /* must be wanting help */ + if (argc < 1) { + _cmd_help(usage, d); + return 0; + } + + /* parse standard options */ + int opt_ret = bu_opt_parse(NULL, argc, argv, d); + + if (print_help) { + _cmd_help(usage, d); + return 0; + } + + /* adjust argc to match the leftovers of the options parsing */ + argc = opt_ret; + + if (argc < 1) { + _cmd_help(usage, d); + return 1; + } + + + char gqa_exe[MAXPATHLEN] = {0}; + char mged_exe[MAXPATHLEN] = {0}; + char rtcheck_exe[MAXPATHLEN] = {0}; + bu_dir(gqa_exe, MAXPATHLEN, BU_DIR_BIN, "gqa", BU_DIR_EXT, NULL); + bu_dir(mged_exe, MAXPATHLEN, BU_DIR_BIN, "mged", BU_DIR_EXT, NULL); + bu_dir(rtcheck_exe, MAXPATHLEN, BU_DIR_BIN, "rtcheck", BU_DIR_EXT, NULL); + + if (!bu_file_exists(gqa_exe, NULL)) { + bu_exit(1, "could not locate gqa executable"); + } + if (!bu_file_exists(mged_exe, NULL)) { + bu_exit(1, "could not locate mged executable"); + } + if (!bu_file_exists(rtcheck_exe, NULL)) { + bu_exit(1, "could not locate rtcheck executable"); + } + + // Have programs - see if we have the .g file + struct bu_vls gfile = BU_VLS_INIT_ZERO; + bu_vls_sprintf(&gfile, "%s", argv[0]); + if (!bu_file_exists(bu_vls_cstr(&gfile), NULL)) { + char fpgfile[MAXPATHLEN] = {0}; + bu_dir(fpgfile, MAXPATHLEN, BU_DIR_CURR, bu_vls_cstr(&gfile), NULL); + bu_vls_sprintf(&gfile, "%s", fpgfile); + if (!bu_file_exists(bu_vls_cstr(&gfile), NULL)) { + bu_vls_free(&gfile); + bu_exit(1, "file %s does not exist", argv[0]); + } + } + + struct bu_vls gbasename = BU_VLS_INIT_ZERO; + if (!bu_path_component(&gbasename, bu_vls_cstr(&gfile), BU_PATH_BASENAME)) { + bu_vls_free(&gfile); + bu_exit(1, "Could not identify basename in geometry file path \"%s\"", argv[0]); + } + struct bu_vls wdir = BU_VLS_INIT_ZERO; + bu_vls_printf(&wdir, "%s.ck", bu_vls_cstr(&gbasename)); + if (bu_file_exists(bu_vls_cstr(&wdir), NULL)) { + bu_vls_free(&gfile); + bu_vls_free(&gbasename); + bu_exit(1, "Working directory\"%s\" already exists - remove to continue", bu_vls_cstr(&wdir)); + } + + + if (dry_run) { + bu_log("(Note: dry run - skipping rtcheck)\n"); + } + + // Make the working directory +#ifdef HAVE_WINDOWS_H + CreateDirectory(bu_vls_cstr(&wdir), NULL); +#else + /* mode: 775 */ + mkdir(bu_vls_cstr(&wdir), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); +#endif + + // Put a copy of the .g file in the working directory + std::ifstream sgfile(bu_vls_cstr(&gfile), std::ios::binary); + std::ofstream dgfile; + dgfile.open(bu_dir(NULL, 0, bu_vls_cstr(&wdir), bu_vls_cstr(&gbasename), NULL), std::ios::binary); + dgfile << sgfile.rdbuf(); + dgfile.close(); + sgfile.close(); + + // Change working directory + if (chdir(bu_vls_cstr(&wdir))) { + bu_exit(1, "Failed to chdir to \"%s\" ", bu_vls_cstr(&wdir)); + } + + if (verbose) { + bu_log("Working on a copy in %s\n", bu_vls_cstr(&wdir)); + } + + // All set - open up the .g file and go to work. + struct ged *gedp = ged_open("db", bu_vls_cstr(&gbasename), 1); + if (gedp == GED_NULL) { + bu_exit(1, "Failed to open \"%s\" ", bu_vls_cstr(&gbasename)); + } + + // Make sure our reference counts are up to date, so we can tell + // which objects are top level + db_update_nref(gedp->ged_wdbp->dbip, &rt_uniresource); + + std::vector objs; + if (argc > 1) { + for (int i = 1; i < argc; i++) { + struct directory *dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_QUIET); + if (dp == RT_DIR_NULL) { + bu_exit(1, "Failed to open object \"%s\" in \"%s\" ", argv[i], bu_vls_cstr(&gbasename)); + } + objs.push_back(dp); + } + } else { + // Get all top level objects + struct directory **all_paths; + int obj_cnt = db_ls(gedp->ged_wdbp->dbip, DB_LS_TOPS, NULL, &all_paths); + for (int i = 0; i < obj_cnt; i++) { + objs.push_back(all_paths[i]); + } + bu_free(all_paths, "free db_tops output"); + } + + if (objs.size() == 1) { + bu_log("Processing tops object: %s\n", objs[0]->d_namep); + } else { + bu_log("Processing tops objects:\n"); + for (size_t i = 0; i < objs.size(); i++) { + bu_log(" %s\n", objs[i]->d_namep); + } + } + + int total_views = 0; + for (size_t i = 0; i < objs.size(); i++) { + for (int az = 0; az < 180; az+=45) { + for (int el = 0; el < 180; el+=45) { + total_views++; + } + } + } + + if (total_views != (int)(16 * objs.size())) { + bu_exit(1, "view incrementing error\n"); + } + + // Run rtcheck equiv. + if (!dry_run) { + std::regex oregex("<(.*),.(.*)>: ([0-9]*).* (.*).mm"); + for (size_t i = 0; i < objs.size(); i++) { + for (int az = 0; az < 180; az+=45) { + for (int el = 0; el < 180; el+=45) { + struct bu_vls str = BU_VLS_INIT_ZERO; + const char **av = (const char **)bu_calloc(8, sizeof(char *), "cmd array"); + av[0] = bu_strdup("check"); + av[1] = bu_strdup("overlaps"); + av[2] = bu_strdup("-G1024"); + bu_vls_sprintf(&str, "-a%d", az); + av[3] = bu_strdup(bu_vls_cstr(&str)); + bu_vls_sprintf(&str, "-e%d", el); + av[4] = bu_strdup(bu_vls_cstr(&str)); + av[5] = bu_strdup("-q"); + av[6] = bu_strdup(objs[i]->d_namep); + bu_vls_trunc(gedp->ged_result_str, 0); + if (ged_check(gedp, 7, av) != GED_OK) { + bu_exit(1, "error running ged_check\n"); + } + for (int j = 0; j < 7; j++) bu_free((void *)av[j], "str"); + bu_free(av, "av array"); + bu_vls_free(&str); + + // Split up results into something we can process with regex + std::istringstream sres(bu_vls_cstr(gedp->ged_result_str)); + std::string line; + while (std::getline(sres, line)) { + std::smatch nvar; + if (!std::regex_search(line, nvar, oregex) || nvar.size() != 5) { + continue; + } + if (verbose) { + bu_log("%zd: %s\n", nvar.size(), line.c_str()); + for (size_t m = 0; m < nvar.size(); m++) { + bu_log(" %zd: %s\n", m, nvar.str(m).c_str()); + } + } + std::pair key; + // sort left and right strings lexicographically to produce unique pairing keys + key = (nvar.str(1) < nvar.str(2)) ? std::make_pair(nvar.str(1), nvar.str(2)) : std::make_pair(nvar.str(2), nvar.str(1)); + // size = count * depth + double val = std::stod(nvar.str(3)) * std::stod(nvar.str(4)); + unique_pairs.insert(key); + pair_sizes.insert(std::make_pair(key, val)); + if (verbose) { + bu_log("Inserting: %s,%s -> %f\n", key.first.c_str(), key.second.c_str(), val); + } + } + } + } + } + + // Run gqa equiv. + for (size_t i = 0; i < objs.size(); i++) { + for (int az = 0; az < 180; az+=45) { + for (int el = 0; el < 180; el+=45) { + const char **av = (const char **)bu_calloc(6, sizeof(char *), "cmd array"); + av[0] = bu_strdup("check"); + av[1] = bu_strdup("overlaps"); + av[2] = bu_strdup("-g1mm,1mm"); + av[3] = bu_strdup("-q"); + av[4] = bu_strdup(objs[i]->d_namep); + bu_vls_trunc(gedp->ged_result_str, 0); + if (ged_check(gedp, 5, av) != GED_OK) { + bu_exit(1, "error running ged_check\n"); + } + for (int j = 0; j < 5; j++) bu_free((void *)av[j], "str"); + bu_free(av, "av array"); + + // Split up results into something we can process with regex + std::istringstream sres(bu_vls_cstr(gedp->ged_result_str)); + std::string line; + while (std::getline(sres, line)) { + std::smatch nvar; + if (!std::regex_search(line, nvar, oregex) || nvar.size() != 5) { + continue; + } + if (verbose) { + bu_log("%zd: %s\n", nvar.size(), line.c_str()); + for (size_t m = 0; m < nvar.size(); m++) { + bu_log(" %zd: %s\n", m, nvar.str(m).c_str()); + } + } + std::pair key; + // sort left and right strings lexicographically to produce unique pairing keys + key = (nvar.str(1) < nvar.str(2)) ? std::make_pair(nvar.str(1), nvar.str(2)) : std::make_pair(nvar.str(2), nvar.str(1)); + // size = count * depth + double val = std::stod(nvar.str(3)) * std::stod(nvar.str(4)); + unique_pairs.insert(key); + pair_sizes.insert(std::make_pair(key, val)); + if (verbose) { + bu_log("Inserting: %s,%s -> %f\n", key.first.c_str(), key.second.c_str(), val); + } + } + } + } + } + } + + if (verbose) { + bu_log("Found %zd unique pairings: \n", unique_pairs.size()); + } + std::set>::iterator p_it; + for (p_it = unique_pairs.begin(); p_it != unique_pairs.end(); p_it++) { + if (verbose) { + bu_log(" %s + %s: \n", p_it->first.c_str(), p_it->second.c_str()); + } + // For each pairing, get the average size + size_t scnt = pair_sizes.count(*p_it); + double ssum = 0.0; + if (verbose) { + bu_log(" Have %zd sizes: \n", scnt); + } + std::multimap, double>::iterator s_it; + for (s_it = pair_sizes.equal_range(*p_it).first; s_it != pair_sizes.equal_range(*p_it).second; s_it++) { + double s = (*s_it).second; + ssum += s; + if (verbose) { + bu_log(" %f \n", s); + } + } + if (verbose) { + bu_log(" Avg: %f\n", ssum/(double)scnt); + } + pair_avg_sizes[*p_it] = ssum/(double)scnt; + } + + // If we have something to write out, do so + if (pair_avg_sizes.size()) { + std::string ofile = std::string("ck.") + std::string(bu_vls_cstr(&gbasename)) + std::string(".overlaps"); + std::ofstream of(ofile); + std::map, double>::iterator a_it; + for (a_it = pair_avg_sizes.begin(); a_it != pair_avg_sizes.end(); a_it++) { + bu_log("%s + %s: %f\n", a_it->first.first.c_str(), a_it->first.second.c_str(), a_it->second); + of << a_it->first.first.c_str() << " " << a_it->first.second.c_str() << " " << std::fixed << std::setprecision(5) << a_it->second << "\n"; + } + of.close(); + } + + // Remove the copy of the .g file + std::remove(bu_vls_cstr(&gbasename)); + + // Clean up + bu_vls_free(&gfile); + bu_vls_free(&gbasename); + bu_vls_free(&wdir); + + return 0; +} + +// Local Variables: +// tab-width: 8 +// mode: C++ +// c-basic-offset: 4 +// indent-tabs-mode: t +// c-file-style: "stroustrup" +// End: +// ex: shiftwidth=4 tabstop=8 diff --git a/src/gtools/gdiff/gdiff.c b/src/gtools/gdiff/gdiff.c index c5d6b11ebfd..18be1c2326c 100644 --- a/src/gtools/gdiff/gdiff.c +++ b/src/gtools/gdiff/gdiff.c @@ -84,7 +84,7 @@ do_diff(struct db_i *left_dbip, struct db_i *right_dbip, struct diff_state *stat struct db_i *inmem_dbip; BU_PTBL_INIT(&diff3_results); BU_GET(inmem_dbip, struct db_i); - inmem_dbip->dbi_eof = (off_t)-1L; + inmem_dbip->dbi_eof = (b_off_t)-1L; inmem_dbip->dbi_fp = NULL; inmem_dbip->dbi_mf = NULL; inmem_dbip->dbi_read_only = 0; diff --git a/src/libanalyze/nirt.cpp b/src/libanalyze/nirt.cpp index e9a98a40724..07bd58cd2dc 100644 --- a/src/libanalyze/nirt.cpp +++ b/src/libanalyze/nirt.cpp @@ -35,8 +35,9 @@ /* needed on mac in c90 mode */ #ifndef HAVE_DECL_FSEEKO -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include #include diff --git a/src/libbu/dir.c b/src/libbu/dir.c index dc37c735ead..8a7d0238749 100644 --- a/src/libbu/dir.c +++ b/src/libbu/dir.c @@ -285,7 +285,7 @@ dir_config(char *buf, size_t len) static void -append(struct bu_vls *vp, const char *buf) +path_append(struct bu_vls *vp, const char *buf) { size_t len = bu_vls_strlen(vp); if (len && bu_vls_addr(vp)[len-1] != BU_DIR_SEPARATOR) @@ -527,64 +527,64 @@ vdir(char *result, size_t len, va_list args) switch ((bu_dir_t)arg) { case BU_DIR_CURR: bu_getcwd(buf, MAXPATHLEN); - append(&vls, buf); + path_append(&vls, buf); break; case BU_DIR_INIT: bu_getiwd(buf, MAXPATHLEN); - append(&vls, buf); + path_append(&vls, buf); break; case BU_DIR_BIN: cpath = _bu_dir_brlcad_root(BRLCAD_BIN_DIR, 1); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_LIB: cpath = _bu_dir_brlcad_root(BRLCAD_LIB_DIR, 1); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_LIBEXEC: cpath = _bu_dir_brlcad_root(BRLCAD_LIBEXEC_DIR, 1); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_INCLUDE: cpath = _bu_dir_brlcad_root(BRLCAD_INCLUDE_DIR, 1); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_DATA: cpath = _bu_dir_brlcad_root(BRLCAD_DATA_DIR, 1); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_DOC: cpath = _bu_dir_brlcad_root(BRLCAD_DOC_DIR, 1); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_MAN: cpath = _bu_dir_brlcad_root(BRLCAD_MAN_DIR, 1); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_TEMP: cpath = dir_temp(buf, MAXPATHLEN); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_HOME: cpath = dir_home(buf, MAXPATHLEN); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_CACHE: cpath = dir_cache(buf, MAXPATHLEN); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_CONFIG: cpath = dir_config(buf, MAXPATHLEN); - append(&vls, cpath); + path_append(&vls, cpath); break; case BU_DIR_EXT: - append(&vls, EXECUTABLE_SUFFIX); + bu_vls_strcat(&vls, EXECUTABLE_SUFFIX); break; case BU_DIR_LIBEXT: - append(&vls, SHARED_LIBRARY_SUFFIX); + bu_vls_strcat(&vls, SHARED_LIBRARY_SUFFIX); break; default: - append(&vls, (const char *)arg); + path_append(&vls, (const char *)arg); break; } arg = va_arg(args, uintptr_t); diff --git a/src/libbu/file.c b/src/libbu/file.c index 9d95aea3388..3144c2c5391 100644 --- a/src/libbu/file.c +++ b/src/libbu/file.c @@ -490,38 +490,6 @@ bu_file_delete(const char *path) return 1; } - -int -bu_fseek(FILE *stream, off_t offset, int origin) -{ - int ret; - -#if defined(HAVE__FSEEKI64) && defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8 - ret = _fseeki64(stream, offset, origin); -#else - ret = fseek(stream, offset, origin); -#endif - - return ret; -} - - -off_t -bu_ftell(FILE *stream) -{ - off_t ret; - -#if defined(HAVE__FTELLI64) && defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8 - /* windows 64bit */ - ret = _ftelli64(stream); -#else - ret = ftell(stream); -#endif - - return ret; -} - - /* * Local Variables: * mode: C diff --git a/src/libbu/mappedfile.c b/src/libbu/mappedfile.c index e9a591e44f1..c33512776c4 100644 --- a/src/libbu/mappedfile.c +++ b/src/libbu/mappedfile.c @@ -75,7 +75,7 @@ static void * -win_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset, void **handle) +win_mmap(void *start, size_t length, int prot, int flags, int fd, b_off_t offset, void **handle) { if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) return MAP_FAILED; @@ -102,7 +102,7 @@ win_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset, else flProtect = PAGE_READONLY; - off_t end = length + offset; + b_off_t end = length + offset; HANDLE mmap_fd, h; if (fd == -1) mmap_fd = INVALID_HANDLE_VALUE; diff --git a/src/libbu/vfont.c b/src/libbu/vfont.c index f0d6ae96ff5..2995d9568d3 100644 --- a/src/libbu/vfont.c +++ b/src/libbu/vfont.c @@ -99,7 +99,7 @@ get_font(const char* fontname, void (*vfont_log)(const char *fmt, ...)) /* Addresses of characters in the file are relative to point in * the file after the directory, so grab the current position. */ - font.offset = bu_ftell(font.ffdes); + font.offset = ftell(font.ffdes); return font; } diff --git a/src/libbu/vfont.h b/src/libbu/vfont.h index 36a05222218..834c8adae92 100644 --- a/src/libbu/vfont.h +++ b/src/libbu/vfont.h @@ -27,7 +27,7 @@ #define LIBBU_VFONT_H #include "common.h" - +#include "bio.h" /* for b_off_T */ #include "bu/file.h" #include "bu/endian.h" #include "bu/str.h" @@ -67,7 +67,7 @@ struct dispatch { struct vfont_file { FILE *ffdes; /* File pointer for current font. */ - off_t offset; /* Current offset to character data. */ + b_off_t offset; /* Current offset to character data. */ struct header hdr; /* Header for font file. */ struct dispatch dir[256]; /* Directory for character font. */ int width; /* Current character width. */ diff --git a/src/libbu/vls.c b/src/libbu/vls.c index ec7e78f58c0..c91b7c797d2 100644 --- a/src/libbu/vls.c +++ b/src/libbu/vls.c @@ -221,7 +221,7 @@ bu_vls_trunc(struct bu_vls *vp, int len) void -bu_vls_nibble(struct bu_vls *vp, off_t len) +bu_vls_nibble(struct bu_vls *vp, b_off_t len) { BU_CK_VLS(vp); diff --git a/src/libfb/fb_generic.c b/src/libfb/fb_generic.c index bd52e340806..ca8f8bc5d20 100644 --- a/src/libfb/fb_generic.c +++ b/src/libfb/fb_generic.c @@ -670,7 +670,7 @@ fb_write_fp(fb *ifp, FILE *fp, int req_width, int req_height, int crunch, int in * Throw bytes away. Use reads into scanline buffer if a pipe, else seek. */ static int -fb_skip_bytes(int fd, off_t num, int fileinput, int scanbytes, unsigned char *scanline) +fb_skip_bytes(int fd, b_off_t num, int fileinput, int scanbytes, unsigned char *scanline) { int n, tries; @@ -785,7 +785,7 @@ fb_read_fd(fb *ifp, int fd, int file_width, int file_height, int file_xoff, int } } - if (file_yoff != 0) fb_skip_bytes(fd, (off_t)file_yoff*(off_t)file_width*sizeof(RGBpixel), fileinput, scanbytes, scanline); + if (file_yoff != 0) fb_skip_bytes(fd, (b_off_t)file_yoff*(b_off_t)file_width*sizeof(RGBpixel), fileinput, scanbytes, scanline); if (multiple_lines) { /* Bottom to top with multi-line reads & writes */ @@ -816,11 +816,11 @@ fb_read_fd(fb *ifp, int fd, int file_width, int file_height, int file_xoff, int /* Normal way -- bottom to top */ for (y = scr_yoff; y < scr_yoff + yout; y++) { if (y < 0 || y > scr_height) { - fb_skip_bytes(fd, (off_t)file_width*sizeof(RGBpixel), fileinput, scanbytes, scanline); + fb_skip_bytes(fd, (b_off_t)file_width*sizeof(RGBpixel), fileinput, scanbytes, scanline); continue; } if (file_xoff+xskip != 0) - fb_skip_bytes(fd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel), fileinput, scanbytes, scanline); + fb_skip_bytes(fd, (b_off_t)(file_xoff+xskip)*sizeof(RGBpixel), fileinput, scanbytes, scanline); n = bu_mread(fd, (char *)scanline, scanbytes); if (n <= 0) break; m = fb_write(ifp, xstart, y, scanline, xout); @@ -832,17 +832,17 @@ fb_read_fd(fb *ifp, int fd, int file_width, int file_height, int file_xoff, int } /* slop at the end of the line? */ if ((size_t)file_xoff+xskip+scanpix < (size_t)file_width) - fb_skip_bytes(fd, (off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel), fileinput, scanbytes, scanline); + fb_skip_bytes(fd, (b_off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel), fileinput, scanbytes, scanline); } } else { /* Inverse -- top to bottom */ for (y = scr_height-1-scr_yoff; y >= scr_height-scr_yoff-yout; y--) { if (y < 0 || y >= scr_height) { - fb_skip_bytes(fd, (off_t)file_width*sizeof(RGBpixel), fileinput, scanbytes, scanline); + fb_skip_bytes(fd, (b_off_t)file_width*sizeof(RGBpixel), fileinput, scanbytes, scanline); continue; } if (file_xoff+xskip != 0) - fb_skip_bytes(fd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel), fileinput, scanbytes, scanline); + fb_skip_bytes(fd, (b_off_t)(file_xoff+xskip)*sizeof(RGBpixel), fileinput, scanbytes, scanline); n = bu_mread(fd, (char *)scanline, scanbytes); if (n <= 0) break; m = fb_write(ifp, xstart, y, scanline, xout); @@ -854,7 +854,7 @@ fb_read_fd(fb *ifp, int fd, int file_width, int file_height, int file_xoff, int } /* slop at the end of the line? */ if ((size_t)file_xoff+xskip+scanpix < (size_t)file_width) - fb_skip_bytes(fd, (off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel), fileinput, scanbytes, scanline); + fb_skip_bytes(fd, (b_off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel), fileinput, scanbytes, scanline); } } free(scanline); diff --git a/src/libfb/if_X24.c b/src/libfb/if_X24.c index 694849b9f80..a0d04def481 100644 --- a/src/libfb/if_X24.c +++ b/src/libfb/if_X24.c @@ -2009,7 +2009,7 @@ X24_getmem(fb *ifp) fd = open(BS_NAME, O_RDWR | O_CREAT | O_BINARY, 0666); if (fd < 0) fb_log("X24_getmem: can't create fb file, using private memory instead, errno %d\n", errno); - else if (lseek(fd, (off_t)size, SEEK_SET) < 0) + else if (lseek(fd, (b_off_t)size, SEEK_SET) < 0) fb_log("X24_getmem: can't seek fb file, using private memory instead, errno %d\n", errno); else if (write(fd, &isnew, 1) < 0) fb_log("X24_getmem: can't zero fb file, using private memory instead, errno %d\n", errno); diff --git a/src/libfb/if_disk.c b/src/libfb/if_disk.c index c8e9a324daf..135c4847527 100644 --- a/src/libfb/if_disk.c +++ b/src/libfb/if_disk.c @@ -262,7 +262,7 @@ dsk_write(fb *ifp, int x, int y, const unsigned char *pixelp, size_t count) dest = (y * ifp->if_width + x) * sizeof(RGBpixel); if (dest != ifp->if_seekpos) { - if (lseek(ifp->if_fd, (off_t)dest, 0) == -1) { + if (lseek(ifp->if_fd, (b_off_t)dest, 0) == -1) { fb_log("disk_buffer_write : seek to %zd failed.\n", dest); return -1; } @@ -293,7 +293,7 @@ dsk_rmap(fb *ifp, ColorMap *cmap) if (fd == 1) fd = 0; if (ifp->if_seekpos != FILE_CMAP_SIZE && - lseek(fd, (off_t)FILE_CMAP_SIZE, 0) == -1) { + lseek(fd, (b_off_t)FILE_CMAP_SIZE, 0) == -1) { fb_log("disk_colormap_read : seek to %zd failed.\n", FILE_CMAP_SIZE); return -1; } @@ -316,7 +316,7 @@ dsk_wmap(fb *ifp, const ColorMap *cmap) return 0; if (fb_is_linear_cmap(cmap)) return 0; - if (lseek(ifp->if_fd, (off_t)FILE_CMAP_SIZE, 0) == -1) { + if (lseek(ifp->if_fd, (b_off_t)FILE_CMAP_SIZE, 0) == -1) { fb_log("disk_colormap_write : seek to %zd failed.\n", FILE_CMAP_SIZE); return -1; } diff --git a/src/libgcv/plugins/fastgen4/fastgen4_read.c b/src/libgcv/plugins/fastgen4/fastgen4_read.c index 46161749d72..d72fde3236d 100644 --- a/src/libgcv/plugins/fastgen4/fastgen4_read.c +++ b/src/libgcv/plugins/fastgen4/fastgen4_read.c @@ -2158,10 +2158,10 @@ make_bot_object(struct conversion_state *pstate) HIDDEN void skip_section(struct conversion_state *pstate) { - off_t section_start; + b_off_t section_start; /* skip to start of next section */ - section_start = bu_ftell(pstate->fpin); + section_start = ftell(pstate->fpin); if (section_start < 0) { bu_bomb("Error: couldn't get input file's current file position."); } @@ -2172,7 +2172,7 @@ skip_section(struct conversion_state *pstate) bu_strncmp(pstate->line, "WALL", 4) && bu_strncmp(pstate->line, "vehicle", 7)) { - section_start = bu_ftell(pstate->fpin); + section_start = ftell(pstate->fpin); if (section_start < 0) { bu_bomb("Error: couldn't get input file's current file position."); } @@ -2181,7 +2181,7 @@ skip_section(struct conversion_state *pstate) } } /* seek to start of the section */ - bu_fseek(pstate->fpin, section_start, SEEK_SET); + fseek(pstate->fpin, section_start, SEEK_SET); } diff --git a/src/libgcv/plugins/fastgen4/fastgen4_write.cpp b/src/libgcv/plugins/fastgen4/fastgen4_write.cpp index d7172ac7ec8..afe8a98aef6 100644 --- a/src/libgcv/plugins/fastgen4/fastgen4_write.cpp +++ b/src/libgcv/plugins/fastgen4/fastgen4_write.cpp @@ -36,8 +36,9 @@ #include #ifndef HAVE_DECL_FSEEKO -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" /* for b_off_t */ +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/src/libgcv/plugins/obj/obj_write.c b/src/libgcv/plugins/obj/obj_write.c index df0e0d128a6..adcaaf2fd51 100644 --- a/src/libgcv/plugins/obj/obj_write.c +++ b/src/libgcv/plugins/obj/obj_write.c @@ -58,8 +58,8 @@ struct conversion_state const struct obj_write_options *obj_write_options; FILE *fp; - off_t vert_offset; - off_t norm_offset; + b_off_t vert_offset; + b_off_t norm_offset; size_t regions_tried; size_t regions_converted; size_t regions_written; diff --git a/src/libgcv/plugins/vrml/vrml_read/file_util.cpp b/src/libgcv/plugins/vrml/vrml_read/file_util.cpp index 22cba2e91e8..0a88f5c6436 100644 --- a/src/libgcv/plugins/vrml/vrml_read/file_util.cpp +++ b/src/libgcv/plugins/vrml/vrml_read/file_util.cpp @@ -33,9 +33,9 @@ #include #ifndef HAVE_DECL_FSEEKO -#include /* for off_t */ -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" /* for b_off_t */ +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/src/libged/dup.c b/src/libged/dup.c index 8c32a91652d..7e22422abc8 100644 --- a/src/libged/dup.c +++ b/src/libged/dup.c @@ -42,7 +42,7 @@ struct dir_check_stuff { static void dup_dir_check5(struct db_i *input_dbip, const struct db5_raw_internal *rip, - off_t addr, + b_off_t addr, void *ptr) { char *name; @@ -105,7 +105,7 @@ dup_dir_check5(struct db_i *input_dbip, * Check a name against the global directory. */ static int -dup_dir_check(struct db_i *input_dbip, const char *name, off_t UNUSED(laddr), size_t UNUSED(len), int UNUSED(flags), void *ptr) +dup_dir_check(struct db_i *input_dbip, const char *name, b_off_t UNUSED(laddr), size_t UNUSED(len), int UNUSED(flags), void *ptr) { struct directory *dupdp; struct bu_vls local = BU_VLS_INIT_ZERO; diff --git a/src/libged/ged.c b/src/libged/ged.c index 45ed1ff7bae..1bf803de576 100644 --- a/src/libged/ged.c +++ b/src/libged/ged.c @@ -426,7 +426,7 @@ ged_open(const char *dbtype, const char *filename, int existing_only) int i; BU_ALLOC(dbip, struct db_i); - dbip->dbi_eof = (off_t)-1L; + dbip->dbi_eof = (b_off_t)-1L; dbip->dbi_fp = NULL; dbip->dbi_mf = NULL; dbip->dbi_read_only = 0; diff --git a/src/libged/tables.c b/src/libged/tables.c index 48f6ce5b625..d420cf62ffb 100644 --- a/src/libged/tables.c +++ b/src/libged/tables.c @@ -101,7 +101,7 @@ tables_check(char *a, char *b) HIDDEN size_t tables_sol_number(const matp_t matrix, char *name, size_t *old, size_t *numsol) { - off_t i; + b_off_t i; struct identt idbuf1, idbuf2; static struct identt identt = {0, {0}, MAT_INIT_ZERO}; ssize_t readval; diff --git a/src/libicv/rot.c b/src/libicv/rot.c index 78d7fac9e79..62e182b9fa2 100644 --- a/src/libicv/rot.c +++ b/src/libicv/rot.c @@ -291,7 +291,7 @@ icv_rot(size_t argc, const char *argv[]) ssize_t x, y; size_t j; int ret = 0; - off_t outbyte, outplace; + b_off_t outbyte, outplace; FILE *ifp, *ofp; unsigned char *obuf; unsigned char *buffer; @@ -353,7 +353,7 @@ icv_rot(size_t argc, const char *argv[]) xout = (nyin - 1) - lasty; outbyte = ((yout * nyin) + xout) * pixbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, SEEK_SET) < 0) { + if (fseek(ofp, outbyte, SEEK_SET) < 0) { ret = 3; perror("fseek"); bu_log("ERROR: %s can't seek on output (ofp=%p, outbyte=%jd)\n", argv[0], (void *)ofp, (intmax_t)outbyte); @@ -383,7 +383,7 @@ icv_rot(size_t argc, const char *argv[]) xout = yin; outbyte = ((yout * nyin) + xout) * pixbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, SEEK_SET) < 0) { + if (fseek(ofp, outbyte, SEEK_SET) < 0) { ret = 3; perror("fseek"); bu_log("ERROR: %s can't seek on output (ofp=%p, outbyte=%jd)\n", argv[0], (void *)ofp, (intmax_t)outbyte); @@ -405,7 +405,7 @@ icv_rot(size_t argc, const char *argv[]) yout = (nyin - 1) - y + 1; outbyte = yout * scanbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, SEEK_SET) < 0) { + if (fseek(ofp, outbyte, SEEK_SET) < 0) { ret = 3; perror("fseek"); bu_log("ERROR: %s can't seek on output (ofp=%p, outbyte=%jd)\n", argv[0], (void *)ofp, (intmax_t)outbyte); diff --git a/src/liboptical/oslexec_pvt.h b/src/liboptical/oslexec_pvt.h index d70791f1611..6c3fe2334bb 100644 --- a/src/liboptical/oslexec_pvt.h +++ b/src/liboptical/oslexec_pvt.h @@ -190,7 +190,7 @@ class PeakCounter /// Template to count a vector's allocated size, in bytes. /// template -inline off_t vectorbytes (const std::vector &v) +inline b_off_t vectorbytes (const std::vector &v) { return v.capacity() * sizeof(T); } @@ -798,20 +798,20 @@ class OSLEXECPUBLIC ShadingSystemImpl : public ShadingSystem double m_stat_llvm_opt_time; ///< llvm IR optimization time double m_stat_llvm_jit_time; ///< llvm JIT time - PeakCounter m_stat_memory; ///< Stat: all shading system memory - - PeakCounter m_stat_mem_master; ///< Stat: master-related mem - PeakCounter m_stat_mem_master_ops; - PeakCounter m_stat_mem_master_args; - PeakCounter m_stat_mem_master_syms; - PeakCounter m_stat_mem_master_defaults; - PeakCounter m_stat_mem_master_consts; - PeakCounter m_stat_mem_inst; ///< Stat: instance-related mem - PeakCounter m_stat_mem_inst_ops; - PeakCounter m_stat_mem_inst_args; - PeakCounter m_stat_mem_inst_syms; - PeakCounter m_stat_mem_inst_paramvals; - PeakCounter m_stat_mem_inst_connections; + PeakCounter m_stat_memory; ///< Stat: all shading system memory + + PeakCounter m_stat_mem_master; ///< Stat: master-related mem + PeakCounter m_stat_mem_master_ops; + PeakCounter m_stat_mem_master_args; + PeakCounter m_stat_mem_master_syms; + PeakCounter m_stat_mem_master_defaults; + PeakCounter m_stat_mem_master_consts; + PeakCounter m_stat_mem_inst; ///< Stat: instance-related mem + PeakCounter m_stat_mem_inst_ops; + PeakCounter m_stat_mem_inst_args; + PeakCounter m_stat_mem_inst_syms; + PeakCounter m_stat_mem_inst_paramvals; + PeakCounter m_stat_mem_inst_connections; spin_mutex m_stat_mutex; ///< Mutex for non-atomic stats ClosureRegistry m_closure_registry; diff --git a/src/libpkg/pkg.c b/src/libpkg/pkg.c index 58575179332..5bf890d53c7 100644 --- a/src/libpkg/pkg.c +++ b/src/libpkg/pkg.c @@ -27,11 +27,11 @@ #include "common.h" #include -#include #include /* used by inet_addr() routine, below */ #include #include + #ifdef HAVE_SYS_PARAM_H # include #endif @@ -58,15 +58,6 @@ # undef LITTLE_ENDIAN /* defined in netinet/{ip.h, tcp.h} */ #endif -#ifdef HAVE_UNISTD_H -# include -#else -# include -# include -# include -#endif - - /* Not all systems with "BSD Networking" include UNIX Domain sockets */ #ifdef HAVE_SYS_UN_H # include /* UNIX Domain sockets */ @@ -86,6 +77,9 @@ #endif #include + +#include "bio.h" + #include "pkg.h" #if defined(HAVE_GETHOSTBYNAME) && !defined(HAVE_DECL_GETHOSTBYNAME) && !defined(_WINSOCKAPI_) diff --git a/src/librt/db5_alloc.c b/src/librt/db5_alloc.c index 2d5059d135e..95ef8cc9691 100644 --- a/src/librt/db5_alloc.c +++ b/src/librt/db5_alloc.c @@ -95,7 +95,7 @@ db5_write_free(struct db_i *dbip, struct directory *dp, size_t length) int db5_realloc(struct db_i *dbip, struct directory *dp, struct bu_external *ep) { - off_t baseaddr; + b_off_t baseaddr; size_t baselen; RT_CK_DBI(dbip); @@ -155,7 +155,7 @@ db5_realloc(struct db_i *dbip, struct directory *dp, struct bu_external *ep) if (db5_write_free(dbip, dp, dp->d_len) < 0) return -1; /* Second, erase back half of storage to remainder. */ - dp->d_addr = baseaddr + (off_t)ep->ext_nbytes; + dp->d_addr = baseaddr + (b_off_t)ep->ext_nbytes; dp->d_len = baselen - ep->ext_nbytes; if (db5_write_free(dbip, dp, dp->d_len) < 0) return -1; @@ -185,7 +185,7 @@ db5_realloc(struct db_i *dbip, struct directory *dp, struct bu_external *ep) */ { struct mem_map *mmp; - off_t newaddr; + b_off_t newaddr; if ((mmp = rt_memalloc_nosplit(&(dbip->dbi_freep), ep->ext_nbytes)) != MAP_NULL) { if (RT_G_DEBUG&RT_DEBUG_DB) @@ -201,7 +201,7 @@ db5_realloc(struct db_i *dbip, struct directory *dp, struct bu_external *ep) newaddr = mmp->m_addr; if ((size_t)mmp->m_size > (size_t)ep->ext_nbytes) { /* Reformat and free the surplus */ - dp->d_addr = mmp->m_addr + (off_t)ep->ext_nbytes; + dp->d_addr = mmp->m_addr + (b_off_t)ep->ext_nbytes; dp->d_len = mmp->m_size - ep->ext_nbytes; if (RT_G_DEBUG&RT_DEBUG_DB) bu_log("db5_realloc(%s) returning surplus at %jd, len=%zu\n", @@ -223,7 +223,7 @@ db5_realloc(struct db_i *dbip, struct directory *dp, struct bu_external *ep) /* No free storage of the desired size, extend the database */ dp->d_addr = dbip->dbi_eof; - dbip->dbi_eof += (off_t)ep->ext_nbytes; + dbip->dbi_eof += (b_off_t)ep->ext_nbytes; dp->d_len = ep->ext_nbytes; if (RT_G_DEBUG & RT_DEBUG_DB) bu_log("db5_realloc(%s) extending database addr=%jd, len=%zu\n", diff --git a/src/librt/db5_scan.c b/src/librt/db5_scan.c index f301fc7e40a..0ceae053d7d 100644 --- a/src/librt/db5_scan.c +++ b/src/librt/db5_scan.c @@ -37,14 +37,14 @@ db5_scan( struct db_i *dbip, void (*handler)(struct db_i *, const struct db5_raw_internal *, - off_t addr, void *client_data), + b_off_t addr, void *client_data), void *client_data) { unsigned char header[8]; struct db5_raw_internal raw; int got; size_t nrec; - off_t addr; + b_off_t addr; RT_CK_DBI(dbip); if (RT_G_DEBUG&RT_DEBUG_DB) bu_log("db5_scan(%p, %lx)\n", @@ -56,26 +56,26 @@ db5_scan( /* Fast-path when file is already memory-mapped */ if (dbip->dbi_mf) { const unsigned char *cp = (const unsigned char *)dbip->dbi_inmem; - off_t eof; + b_off_t eof; - eof = (off_t)dbip->dbi_mf->buflen; + eof = (b_off_t)dbip->dbi_mf->buflen; if (db5_header_is_valid(cp) == 0) { bu_log("db5_scan ERROR: %s is lacking a proper BRL-CAD v5 database header\n", dbip->dbi_filename); goto fatal; } cp += sizeof(header); - addr = (off_t)sizeof(header); + addr = (b_off_t)sizeof(header); while (addr < eof) { if ((cp = db5_get_raw_internal_ptr(&raw, cp)) == NULL) { goto fatal; } (*handler)(dbip, &raw, addr, client_data); nrec++; - addr += (off_t)raw.object_length; + addr += (b_off_t)raw.object_length; } dbip->dbi_eof = addr; - BU_ASSERT(dbip->dbi_eof == (off_t)dbip->dbi_mf->buflen); + BU_ASSERT(dbip->dbi_eof == (b_off_t)dbip->dbi_mf->buflen); } else { /* In a totally portable way, read the database with stdio */ rewind(dbip->dbi_fp); @@ -85,7 +85,7 @@ db5_scan( goto fatal; } for (;;) { - addr = bu_ftell(dbip->dbi_fp); + addr = ftell(dbip->dbi_fp); if ((got = db5_get_raw_internal_fp(&raw, dbip->dbi_fp)) < 0) { if (got == -1) break; /* EOF */ goto fatal; @@ -97,7 +97,7 @@ db5_scan( raw.buf = NULL; } } - dbip->dbi_eof = bu_ftell(dbip->dbi_fp); + dbip->dbi_eof = ftell(dbip->dbi_fp); rewind(dbip->dbi_fp); } @@ -114,7 +114,7 @@ struct directory * db_diradd5( struct db_i *dbip, const char *name, - off_t laddr, + b_off_t laddr, unsigned char major_type, unsigned char minor_type, unsigned char name_hidden, @@ -186,7 +186,7 @@ db_diradd5( struct directory * db5_diradd(struct db_i *dbip, const struct db5_raw_internal *rip, - off_t laddr, + b_off_t laddr, void *client_data) { struct directory **headp; @@ -271,7 +271,7 @@ HIDDEN void db5_diradd_handler( struct db_i *dbip, const struct db5_raw_internal *rip, - off_t laddr, + b_off_t laddr, void *client_data) /* unused client_data from db5_scan() */ { RT_CK_DBI(dbip); @@ -297,7 +297,7 @@ db5_diradd_handler( } HIDDEN int -db_diradd4(struct db_i *dbi, const char *s, off_t o, size_t st, int i, void *v) +db_diradd4(struct db_i *dbi, const char *s, b_off_t o, size_t st, int i, void *v) { if (!db_diradd(dbi, s, o, st, i, v)) return 0; return 1; diff --git a/src/librt/db_alloc.c b/src/librt/db_alloc.c index 650f21e6494..8f88f6fa745 100644 --- a/src/librt/db_alloc.c +++ b/src/librt/db_alloc.c @@ -81,11 +81,11 @@ db_alloc(register struct db_i *dbip, register struct directory *dp, size_t count return -1; } dp->d_len = count; - dbip->dbi_eof += (off_t)(count * sizeof(union record)); + dbip->dbi_eof += (b_off_t)(count * sizeof(union record)); dbip->dbi_nrec += count; break; } - dp->d_addr = (off_t)(len * sizeof(union record)); + dp->d_addr = (b_off_t)(len * sizeof(union record)); dp->d_len = count; if (db_get(dbip, dp, &rec, 0, 1) < 0) return -1; @@ -201,7 +201,7 @@ db_zapper(struct db_i *dbip, struct directory *dp, size_t start) for (i=0; i < todo; i++) rp[i].u_id = ID_FREE; - ret = db_put(dbip, dp, rp, (off_t)start, todo); + ret = db_put(dbip, dp, rp, (b_off_t)start, todo); bu_free((char *)rp, "db_zapper buf"); return ret; } diff --git a/src/librt/db_corrupt.c b/src/librt/db_corrupt.c index e131af8b638..9e81ed8c023 100644 --- a/src/librt/db_corrupt.c +++ b/src/librt/db_corrupt.c @@ -25,7 +25,7 @@ */ #include "common.h" - +#include "bio.h" /* for b_off_t */ #include "vmath.h" #include "raytrace.h" @@ -41,7 +41,7 @@ struct counter { static int -db_corrupt_handler(struct db_i *dbip, const char *name, off_t offset, size_t size, int UNUSED(type), void *data) +db_corrupt_handler(struct db_i *dbip, const char *name, b_off_t offset, size_t size, int UNUSED(type), void *data) { struct counter *cnt = (struct counter *)data; struct bu_external ext; @@ -54,7 +54,7 @@ db_corrupt_handler(struct db_i *dbip, const char *name, off_t offset, size_t siz RT_CK_DBI(dbip); /* get into position */ - ret = bu_fseek(dbip->dbi_fp, offset, 0); + ret = fseek(dbip->dbi_fp, offset, 0); if (ret) { bu_log("Database seek failure, unable to seek [%s]\n", name); return 0; diff --git a/src/librt/db_fullpath.c b/src/librt/db_fullpath.c index d6671cfdac9..1fdcd7ccb33 100644 --- a/src/librt/db_fullpath.c +++ b/src/librt/db_fullpath.c @@ -162,7 +162,7 @@ db_append_full_path(struct db_full_path *dest, const struct db_full_path *src) void -db_dup_path_tail(struct db_full_path *newp, const struct db_full_path *oldp, off_t start) +db_dup_path_tail(struct db_full_path *newp, const struct db_full_path *oldp, b_off_t start) { RT_CK_FULL_PATH(newp); RT_CK_FULL_PATH(oldp); diff --git a/src/librt/db_inmem.c b/src/librt/db_inmem.c index ae1c83ea410..98edf317ef8 100644 --- a/src/librt/db_inmem.c +++ b/src/librt/db_inmem.c @@ -52,7 +52,7 @@ db_open_inmem(void) register int i; BU_ALLOC(dbip, struct db_i); - dbip->dbi_eof = (off_t)-1L; + dbip->dbi_eof = (b_off_t)-1L; dbip->dbi_fp = NULL; dbip->dbi_mf = NULL; diff --git a/src/librt/db_io.c b/src/librt/db_io.c index 19132e2ad45..ac60917f56a 100644 --- a/src/librt/db_io.c +++ b/src/librt/db_io.c @@ -50,7 +50,7 @@ * -1 FAILURE */ int -db_read(const struct db_i *dbip, void *addr, size_t count, off_t offset) +db_read(const struct db_i *dbip, void *addr, size_t count, b_off_t offset) /* byte count */ /* byte offset from start of file */ { @@ -80,7 +80,7 @@ db_read(const struct db_i *dbip, void *addr, size_t count, off_t offset) } bu_semaphore_acquire(BU_SEM_SYSCALL); - ret = bu_fseek(dbip->dbi_fp, offset, 0); + ret = fseek(dbip->dbi_fp, offset, 0); if (ret) bu_bomb("db_read: fseek error\n"); got = (size_t)fread(addr, 1, count, dbip->dbi_fp); @@ -134,7 +134,7 @@ db_getmrec(const struct db_i *dbip, const struct directory *dp) int -db_get(const struct db_i *dbip, const struct directory *dp, union record *where, off_t offset, size_t len) +db_get(const struct db_i *dbip, const struct directory *dp, union record *where, b_off_t offset, size_t len) { RT_CK_DBI(dbip); @@ -173,7 +173,7 @@ db_get(const struct db_i *dbip, const struct directory *dp, union record *where, int -db_write(struct db_i *dbip, const void *addr, size_t count, off_t offset) +db_write(struct db_i *dbip, const void *addr, size_t count, b_off_t offset) { register size_t got; @@ -198,7 +198,7 @@ db_write(struct db_i *dbip, const void *addr, size_t count, off_t offset) bu_semaphore_acquire(BU_SEM_SYSCALL); bu_interrupt_suspend(); - (void)bu_fseek(dbip->dbi_fp, offset, 0); + (void)fseek(dbip->dbi_fp, offset, 0); got = fwrite(addr, 1, count, dbip->dbi_fp); fflush(dbip->dbi_fp); @@ -216,7 +216,7 @@ db_write(struct db_i *dbip, const void *addr, size_t count, off_t offset) int -db_put(struct db_i *dbip, const struct directory *dp, union record *where, off_t offset, size_t len) +db_put(struct db_i *dbip, const struct directory *dp, union record *where, b_off_t offset, size_t len) { RT_CK_DBI(dbip); RT_CK_DIR(dp); diff --git a/src/librt/db_lookup.c b/src/librt/db_lookup.c index 41572964003..3e6b4a04410 100644 --- a/src/librt/db_lookup.c +++ b/src/librt/db_lookup.c @@ -230,7 +230,7 @@ db_lookup(const struct db_i *dbip, const char *name, int noisy) struct directory * -db_diradd(struct db_i *dbip, const char *name, off_t laddr, size_t len, int flags, void *ptr) +db_diradd(struct db_i *dbip, const char *name, b_off_t laddr, size_t len, int flags, void *ptr) { struct directory **headp; struct directory *dp; diff --git a/src/librt/db_open.c b/src/librt/db_open.c index 9d5e5cf42a6..f7bc95da80d 100644 --- a/src/librt/db_open.c +++ b/src/librt/db_open.c @@ -131,7 +131,7 @@ db_open(const char *name, const char *mode) BU_ALLOC(dbip, struct db_i); dbip->dbi_mf = mfp; - dbip->dbi_eof = (off_t)mfp->buflen; + dbip->dbi_eof = (b_off_t)mfp->buflen; dbip->dbi_inmem = mfp->buf; dbip->dbi_mf->apbuf = (void *)dbip; @@ -149,7 +149,7 @@ db_open(const char *name, const char *mode) /* Read-write mode */ BU_ALLOC(dbip, struct db_i); - dbip->dbi_eof = (off_t)-1L; + dbip->dbi_eof = (b_off_t)-1L; if ((dbip->dbi_fp = fopen(name, "r+b")) == NULL) { if (RT_G_DEBUG & RT_DEBUG_DB) { diff --git a/src/librt/db_scan.c b/src/librt/db_scan.c index 9b038c9e606..27f32ffb173 100644 --- a/src/librt/db_scan.c +++ b/src/librt/db_scan.c @@ -28,8 +28,8 @@ #include "common.h" -#include #include +#include "bio.h" /* for b_off_t */ #include "bnetwork.h" #include "bu/units.h" @@ -72,16 +72,16 @@ * -1 Fatal Error */ int -db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, size_t, int, void *), int do_old_matter, void *client_data) +db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, b_off_t, size_t, int, void *), int do_old_matter, void *client_data) /* argument for handler */ { union record record; /* Initial record, holds name */ union record rec2; /* additional record(s) */ - register off_t addr; /* start of current rec */ - register off_t here; /* intermediate positions */ - register off_t next; /* start of next rec */ + register b_off_t addr; /* start of current rec */ + register b_off_t here; /* intermediate positions */ + register b_off_t next; /* start of next rec */ register int nrec; /* # records for this solid */ register int totrec; /* # records for database */ register long j; @@ -99,7 +99,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s return -1; } rewind(dbip->dbi_fp); - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); if (next < 0) { perror("ftell"); next = 0; @@ -111,7 +111,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s totrec = 0; while (1) { nrec = 0; - if (bu_fseek(dbip->dbi_fp, next, 0) != 0) { + if (fseek(dbip->dbi_fp, next, 0) != 0) { bu_log("db_scan: fseek(offset=%jd) failure\n", (intmax_t)next); return -1; } @@ -120,7 +120,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&record, sizeof record, 1, dbip->dbi_fp) != 1 || feof(dbip->dbi_fp)) break; - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); if (next < 0) { perror("db_scan: ftell: "); return -1; @@ -146,18 +146,18 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s break; case ID_ARS_A: while (1) { - here = bu_ftell(dbip->dbi_fp); + here = ftell(dbip->dbi_fp); if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; RT_DEBUG_PR(here, rec2); if (rec2.u_id != ID_ARS_B) { - bu_fseek(dbip->dbi_fp, here, 0); + fseek(dbip->dbi_fp, here, 0); break; } nrec++; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.a.a_name, addr, nrec, RT_DIR_SOLID, client_data); break; case ID_ARS_B: @@ -171,7 +171,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.ss.ss_name, addr, nrec, RT_DIR_SOLID, client_data); break; case ID_MATERIAL: @@ -192,17 +192,17 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s break; case ID_P_HEAD: while (1) { - here = bu_ftell(dbip->dbi_fp); + here = ftell(dbip->dbi_fp); if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; RT_DEBUG_PR(here, rec2); if (rec2.u_id != ID_P_DATA) { - bu_fseek(dbip->dbi_fp, here, 0); + fseek(dbip->dbi_fp, here, 0); break; } nrec++; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.p.p_name, addr, nrec, RT_DIR_SOLID, client_data); break; case ID_P_DATA: @@ -211,12 +211,12 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s case ID_BSOLID: while (1) { /* Find and skip subsequent BSURFs */ - here = bu_ftell(dbip->dbi_fp); + here = ftell(dbip->dbi_fp); if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; RT_DEBUG_PR(here, rec2); if (rec2.u_id != ID_BSURF) { - bu_fseek(dbip->dbi_fp, here, 0); + fseek(dbip->dbi_fp, here, 0); break; } @@ -227,7 +227,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); } handler(dbip, record.B.B_name, addr, nrec, RT_DIR_SOLID, client_data); break; @@ -249,7 +249,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.n.n_name, addr, nrec, RT_DIR_SOLID, client_data); break; case DBID_PARTICLE: @@ -262,7 +262,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.pwr.pwr_name, addr, nrec, RT_DIR_SOLID, client_data); break; case DBID_NMG: @@ -272,7 +272,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.nmg.N_name, addr, nrec, RT_DIR_SOLID, client_data); break; case DBID_SKETCH: @@ -282,7 +282,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.skt.skt_name, addr, nrec, RT_DIR_SOLID, client_data); break; case DBID_EXTR: @@ -292,7 +292,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.extr.ex_name, addr, nrec, RT_DIR_SOLID, client_data); break; case DBID_CLINE: @@ -305,7 +305,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); handler(dbip, record.s.s_name, addr, nrec, RT_DIR_SOLID, client_data); break; case ID_MEMB: @@ -313,17 +313,17 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s break; case ID_COMB: while (1) { - here = bu_ftell(dbip->dbi_fp); + here = ftell(dbip->dbi_fp); if (fread((char *)&rec2, sizeof(rec2), 1, dbip->dbi_fp) != 1) break; RT_DEBUG_PR(here, rec2); if (rec2.u_id != ID_MEMB) { - bu_fseek(dbip->dbi_fp, here, 0); + fseek(dbip->dbi_fp, here, 0); break; } nrec++; } - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); switch (record.c.c_flags) { default: case DBV4_NON_REGION: @@ -346,7 +346,7 @@ db_scan(struct db_i *dbip, int (*handler) (struct db_i *, const char *, off_t, s totrec += nrec; } dbip->dbi_nrec = totrec; - next = bu_ftell(dbip->dbi_fp); + next = ftell(dbip->dbi_fp); if (next < 0) dbip->dbi_eof = -1; else @@ -396,7 +396,7 @@ db_update_ident(struct db_i *dbip, const char *new_title, double local2mm) return db5_update_ident(dbip, new_title, local2mm); RT_DIR_SET_NAMEP(&dir, ident); - dir.d_addr = (off_t)0L; + dir.d_addr = (b_off_t)0L; dir.d_len = 1; dir.d_magic = RT_DIR_MAGIC; dir.d_flags = 0; diff --git a/src/librt/librt_private.h b/src/librt/librt_private.h index 35f65f6a68d..bbaafc50bc3 100644 --- a/src/librt/librt_private.h +++ b/src/librt/librt_private.h @@ -133,7 +133,7 @@ extern int cyclic_path(const struct db_full_path *fp, const char *test_name, lon extern int tcl_list_to_avs(const char *tcl_list, struct bu_attribute_value_set *avs, int offset); /* db_io.c */ -extern int db_read(const struct db_i *dbip, void *addr, size_t count, off_t offset); +extern int db_read(const struct db_i *dbip, void *addr, size_t count, b_off_t offset); /* db5_io.c */ #define DB_SIZE_OBJ 0x1 diff --git a/src/librt/mater.c b/src/librt/mater.c index 5ae334e22f4..f777f1f006b 100644 --- a/src/librt/mater.c +++ b/src/librt/mater.c @@ -171,7 +171,7 @@ rt_insert_color(struct mater *newp) * Called from db_scan() when initially scanning database. */ void -rt_color_addrec(int low, int hi, int r, int g, int b, off_t addr) +rt_color_addrec(int low, int hi, int r, int g, int b, b_off_t addr) { register struct mater *mp; diff --git a/src/librt/memalloc.c b/src/librt/memalloc.c index 2c2750b9a33..39dc9f94c8a 100644 --- a/src/librt/memalloc.c +++ b/src/librt/memalloc.c @@ -82,7 +82,7 @@ rt_memalloc(struct mem_map **pp, register size_t size) return 0L; /* No more space */ addr = (size_t)curp->m_addr; - curp->m_addr += (off_t)size; + curp->m_addr += (b_off_t)size; /* If the element size goes to zero, put it on the freelist */ @@ -137,12 +137,12 @@ rt_memalloc_nosplit(struct mem_map **pp, register size_t size) void -rt_memfree(struct mem_map **pp, size_t size, off_t addr) +rt_memfree(struct mem_map **pp, size_t size, b_off_t addr) { register int type = 0; register struct mem_map *prevp = MAP_NULL; register struct mem_map *curp; - off_t il; + b_off_t il; struct mem_map *tmap; if (size == 0) @@ -156,14 +156,14 @@ rt_memfree(struct mem_map **pp, size_t size, off_t addr) /* Make up the `type' variable */ if (prevp) { - il = prevp->m_addr + (off_t)prevp->m_size; + il = prevp->m_addr + (b_off_t)prevp->m_size; if (il > addr) type |= M_BOVFL; if (il == addr) type |= M_BMTCH; } if (curp) { - il = addr + (off_t)size; + il = addr + (b_off_t)size; if (il > curp->m_addr) type |= M_TOVFL; if (il == curp->m_addr) @@ -203,7 +203,7 @@ rt_memfree(struct mem_map **pp, size_t size, off_t addr) case M_TMTCH: /* Expand top element downward */ curp->m_size += size; - curp->m_addr -= (off_t)size; + curp->m_addr -= (b_off_t)size; break; default: /* No matches; allocate and insert */ diff --git a/src/librt/primitives/primitive_util.c b/src/librt/primitives/primitive_util.c index 24744100236..8808299cbe0 100644 --- a/src/librt/primitives/primitive_util.c +++ b/src/librt/primitives/primitive_util.c @@ -529,7 +529,7 @@ clt_read_code(const char *filename, size_t *length) if (!fp) bu_exit(-1, "failed to read OpenCL code file (%s)\n", filename); fseek(fp, 0, SEEK_END); - *length = bu_ftell(fp); + *length = ftell(fp); rewind(fp); data = (char*)bu_malloc((*length+1)*sizeof(char), "failed bu_malloc() in clt_read_code()"); diff --git a/src/mged/edsol.c b/src/mged/edsol.c index b90b3e88a11..b4abcbe0f20 100644 --- a/src/mged/edsol.c +++ b/src/mged/edsol.c @@ -3982,7 +3982,7 @@ sedit(void) (struct rt_dsp_internal *)es_int.idb_ptr; const char *fname; struct stat stat_buf; - off_t need_size; + b_off_t need_size; struct bu_vls message = BU_VLS_INIT_ZERO; RT_DSP_CK_MAGIC(dsp); @@ -4017,7 +4017,7 @@ sedit(void) struct rt_ebm_internal *ebm = (struct rt_ebm_internal *)es_int.idb_ptr; struct stat stat_buf; - off_t need_size; + b_off_t need_size; RT_EBM_CK_MAGIC(ebm); @@ -4050,7 +4050,7 @@ sedit(void) (struct rt_ebm_internal *)es_int.idb_ptr; const char *fname; struct stat stat_buf; - off_t need_size; + b_off_t need_size; RT_EBM_CK_MAGIC(ebm); @@ -4126,7 +4126,7 @@ sedit(void) struct rt_vol_internal *vol = (struct rt_vol_internal *)es_int.idb_ptr; struct stat stat_buf; - off_t need_size; + b_off_t need_size; RT_VOL_CK_MAGIC(vol); @@ -4212,7 +4212,7 @@ sedit(void) (struct rt_vol_internal *)es_int.idb_ptr; const char *fname; struct stat stat_buf; - off_t need_size; + b_off_t need_size; RT_VOL_CK_MAGIC(vol); diff --git a/src/mged/wdb_obj.c b/src/mged/wdb_obj.c index 832edbd23ce..c6f2e848a36 100644 --- a/src/mged/wdb_obj.c +++ b/src/mged/wdb_obj.c @@ -5155,7 +5155,7 @@ struct dir_check_stuff { void wdb_dir_check5(struct db_i *input_dbip, const struct db5_raw_internal *rip, - off_t UNUSED(addr), + b_off_t UNUSED(addr), void *ptr) { char *name; @@ -5218,7 +5218,7 @@ wdb_dir_check5(struct db_i *input_dbip, * Check a name against the global directory. */ int -wdb_dir_check(struct db_i *input_dbip, const char *name, off_t UNUSED(laddr), size_t UNUSED(len), int UNUSED(flags), void *ptr) +wdb_dir_check(struct db_i *input_dbip, const char *name, b_off_t UNUSED(laddr), size_t UNUSED(len), int UNUSED(flags), void *ptr) { struct directory *dupdp; struct bu_vls local; diff --git a/src/nirt/main.cpp b/src/nirt/main.cpp index 33713c17331..f12e9b6840d 100644 --- a/src/nirt/main.cpp +++ b/src/nirt/main.cpp @@ -35,9 +35,9 @@ /* needed on mac in c90 mode */ #ifndef HAVE_DECL_FSEEKO -#include /* for off_t */ -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +#include "bio.h" /* for b_off_t */ +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/src/other/libregex/regex.h b/src/other/libregex/regex.h index 0d1bce2517d..e6bdc2c0543 100644 --- a/src/other/libregex/regex.h +++ b/src/other/libregex/regex.h @@ -52,30 +52,38 @@ # define HAVE_SSIZE_T 1 #endif -#if defined(_WIN32) && !defined(_OFF_T_DEFINED) - typedef SSIZE_T off_t; -# define _OFF_T_DEFINED 1 -#endif - -/* On Windows 64bit, "off_t" is defined as a "long" - * within "sys/types.h" which breaks "libregex". To - * resolve this, we must define "off_t" before we - * include "sys/types.h". Defining "off_t" as - * "ssize_t" works for both Windows 32bit and 64bit. - */ +#include +#include +#include +#include +/* We want 64 bit (large file) I/O capabilities whenever they are available. + * Always define this before we include sys/types.h */ +#ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +#endif #include -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__off_t_defined) && !defined(_OFF_T) && !defined(_OFF_T_DECLARED) - typedef ptrdiff_t off_t; -# define __off_t_defined 1 -# define _OFF_T_DECLARED 1 +/* off_t is 32 bit size even on 64 bit Windows. In the past we have tried to + * force off_t to be 64 bit but this is failing on newer Windows/Visual Studio + * verions in 2020 - therefore, we instead introduce the b_off_t define to + * properly substitute the correct numerical type for the correct platform. */ +#if defined(_WIN64) +# include +# define regoff_t __int64 +# define fseek _fseeki64 +# define ftell _ftelli64 +# define fstat _fstati64 +# define stat _stati64 +#elif defined (_WIN32) +# include +# define regoff_t _off_t +# define fstat _fstat +# define stat _stat +#else +# define regoff_t off_t #endif -#include -#include -#include -#include #ifdef __cplusplus # define __BEGIN_DECLS extern "C" { @@ -104,7 +112,7 @@ /* types */ -typedef off_t regoff_t; + typedef struct { int re_magic; diff --git a/src/other/stepcode/src/clstepcore/complexSupport.h b/src/other/stepcode/src/clstepcore/complexSupport.h index 30e61896c5c..2549a12be57 100644 --- a/src/other/stepcode/src/clstepcore/complexSupport.h +++ b/src/other/stepcode/src/clstepcore/complexSupport.h @@ -20,9 +20,37 @@ #include #ifndef HAVE_DECL_FSEEKO -#include /* for off_t */ -extern "C" int fseeko(FILE *, off_t, int); -extern "C" off_t ftello(FILE *); +/* We want 64 bit (large file) I/O capabilities whenever they are available. + * Always define this before we include sys/types.h */ +#ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +#endif +#include + +/* off_t is 32 bit size even on 64 bit Windows. In the past we have tried to + * force off_t to be 64 bit but this is failing on newer Windows/Visual Studio + * verions in 2020 - therefore, we instead introduce the b_off_t define to + * properly substitute the correct numerical type for the correct platform. */ +#if defined(_WIN64) +# include +# define b_off_t __int64 +# define fseek _fseeki64 +# define ftell _ftelli64 +# define fstat _fstati64 +# define lseek _lseeki64 +# define stat _stati64 +#elif defined (_WIN32) +# include +# define b_off_t _off_t +# define fstat _fstat +# define lseek _lseek +# define stat _stat +#else +# define b_off_t off_t +#endif + +extern "C" int fseeko(FILE *, b_off_t, int); +extern "C" b_off_t ftello(FILE *); #endif #include diff --git a/src/rt/do.c b/src/rt/do.c index 6e081819fa3..dde8aaa5b77 100644 --- a/src/rt/do.c +++ b/src/rt/do.c @@ -690,7 +690,7 @@ clt_run(int cur_pixel, int last_pixel) } if (outfp) { bu_semaphore_acquire(BU_SEM_SYSCALL); - if (bu_fseek(outfp, cur_pixel*clt_o[1], 0) != 0) + if (fseek(outfp, cur_pixel*clt_o[1], 0) != 0) fprintf(stderr, "fseek error\n"); if (fwrite(pixelp, size, 1, outfp) != 1) bu_exit(EXIT_FAILURE, "pixel fwrite error"); diff --git a/src/rt/view.c b/src/rt/view.c index 9d2a68ac4fa..15b7688a931 100644 --- a/src/rt/view.c +++ b/src/rt/view.c @@ -306,7 +306,7 @@ view_pixel(struct application *ap) icv_writepixel(bif, ap->a_x, ap->a_y, ap->a_color); } else if (outfp != NULL) { bu_semaphore_acquire(BU_SEM_SYSCALL); - if (bu_fseek(outfp, (ap->a_y*width*pwidth) + (ap->a_x*pwidth), 0) != 0) + if (fseek(outfp, (ap->a_y*width*pwidth) + (ap->a_x*pwidth), 0) != 0) fprintf(stderr, "fseek error\n"); if (fwrite(p, 3, 1, outfp) != 1) bu_exit(EXIT_FAILURE, "pixel fwrite error"); @@ -512,7 +512,7 @@ view_pixel(struct application *ap) size_t count; bu_semaphore_acquire(BU_SEM_SYSCALL); - if (bu_fseek(outfp, ap->a_y*width*pwidth, 0) != 0) + if (fseek(outfp, ap->a_y*width*pwidth, 0) != 0) fprintf(stderr, "fseek error\n"); count = fwrite(scanline[ap->a_y].sl_buf, sizeof(char), width*pwidth, outfp); diff --git a/src/util/ap-pix.c b/src/util/ap-pix.c index 5e5a915ec13..9e3f0b2f1ad 100644 --- a/src/util/ap-pix.c +++ b/src/util/ap-pix.c @@ -80,9 +80,9 @@ main(int argc, char **argv) bu_exit(2, "%s: can't open \"%s\"\n", argv0, argv[1]); } yelfp = fopen(argv[1], "r"); - bu_fseek(yelfp, 50*sizeof(yelline), 0); + fseek(yelfp, 50*sizeof(yelline), 0); cyafp = fopen(argv[1], "r"); - bu_fseek(cyafp, 100*sizeof(cyaline), 0); + fseek(cyafp, 100*sizeof(cyaline), 0); line = 0; while ((int)fread(&cyaline, sizeof(cyaline), 1, cyafp) > 0) { diff --git a/src/util/bwcrop.c b/src/util/bwcrop.c index 301825e967f..6ffd89060d7 100644 --- a/src/util/bwcrop.c +++ b/src/util/bwcrop.c @@ -34,10 +34,11 @@ #include "common.h" #include -#include #include /* for INT_MAX */ #include "vmath.h" +#include "bio.h" /* for b_off_t */ + #include "bu/file.h" #include "bu/malloc.h" #include "bu/exit.h" @@ -49,7 +50,7 @@ unsigned char *buffer; ssize_t scanlen; /* length of infile scanlines */ ssize_t buflines; /* Number of lines held in buffer */ -off_t buf_start = -1000; /* First line in buffer */ +b_off_t buf_start = -1000; /* First line in buffer */ unsigned long xnum, ynum; /* Number of pixels in new file */ float ulx, uly, urx, ury, lrx, lry, llx, lly; /* Corners of original file */ @@ -103,7 +104,7 @@ fill_buffer(int y) if (buf_start < 0) buf_start = 0; - bu_fseek(ifp, buf_start * scanlen, 0); + fseek(ifp, buf_start * scanlen, 0); ret = fread(buffer, scanlen, buflines, ifp); if (ret == 0) perror("fread"); diff --git a/src/util/bwhisteq.c b/src/util/bwhisteq.c index 687b9746fb4..fc170fa5ee8 100644 --- a/src/util/bwhisteq.c +++ b/src/util/bwhisteq.c @@ -105,7 +105,7 @@ main(int argc, char **argv) fprintf(stderr, "result[%d] = %d\n", i, result[i]); } - bu_fseek(fp, 0, 0); + fseek(fp, 0, 0); while ((n = fread(buf, 1, BUFSIZE, fp)) > 0) { for (i = 0; i < n; i++) { long idx = buf[i]; diff --git a/src/util/bwrot.c b/src/util/bwrot.c index bda318a2924..34009377097 100644 --- a/src/util/bwrot.c +++ b/src/util/bwrot.c @@ -358,7 +358,7 @@ main(int argc, char **argv) xout = (nyin - 1) - lasty; outbyte = ((yout * nyin) + xout) * pixbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, SEEK_SET) < 0) { + if (fseek(ofp, outbyte, SEEK_SET) < 0) { ret = 3; perror("fseek"); bu_log("ERROR: %s can't seek on output (ofp=%p, outbyte=%zd)\n", bu_getprogname(), (void *)ofp, outbyte); @@ -384,7 +384,7 @@ main(int argc, char **argv) xout = yin; outbyte = ((yout * nyin) + xout) * pixbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, SEEK_SET) < 0) { + if (fseek(ofp, outbyte, SEEK_SET) < 0) { ret = 3; perror("fseek"); bu_log("ERROR: %s can't seek on output (ofp=%p, outbyte=%zd)\n", bu_getprogname(), (void *)ofp, outbyte); @@ -402,7 +402,7 @@ main(int argc, char **argv) yout = (nyin - 1) - y + 1; outbyte = yout * scanbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, SEEK_SET) < 0) { + if (fseek(ofp, outbyte, SEEK_SET) < 0) { ret = 3; perror("fseek"); bu_log("ERROR: %s can't seek on output (ofp=%p, outbyte=%zd)\n", bu_getprogname(), (void *)ofp, outbyte); diff --git a/src/util/bwscale.c b/src/util/bwscale.c index b9b46b10163..6ee2124cf38 100644 --- a/src/util/bwscale.c +++ b/src/util/bwscale.c @@ -49,7 +49,7 @@ unsigned char *outbuf; unsigned char *buffer; ssize_t scanlen; /* length of infile (and buffer) scanlines */ ssize_t buflines; /* Number of lines held in buffer */ -off_t buf_start = -1000; /* First line in buffer */ +b_off_t buf_start = -1000; /* First line in buffer */ ssize_t bufy; /* y coordinate in buffer */ FILE *buffp; @@ -87,7 +87,7 @@ fill_buffer(int y) buf_start = y - buflines/2; if (buf_start < 0) buf_start = 0; - if (bu_fseek(buffp, buf_start * scanlen, 0) < 0) { + if (fseek(buffp, buf_start * scanlen, 0) < 0) { fprintf(stderr, "bwscale: Can't seek to input pixel!\n"); /* bu_exit (3, NULL); */ } diff --git a/src/util/pixbustup.c b/src/util/pixbustup.c index ac577f94797..ed52171b876 100644 --- a/src/util/pixbustup.c +++ b/src/util/pixbustup.c @@ -51,7 +51,7 @@ printUsage(void) int main(int argc, char **argv) { - off_t image_offset; + b_off_t image_offset; size_t framenumber; char *base_name; char name[128]; diff --git a/src/util/pixcrop.c b/src/util/pixcrop.c index f596cf3d7ce..62b8be262e8 100644 --- a/src/util/pixcrop.c +++ b/src/util/pixcrop.c @@ -34,10 +34,11 @@ #include "common.h" #include -#include #include /* for INT_MAX */ #include "vmath.h" +#include "bio.h" /* for b_off_t */ + #include "bu/file.h" #include "bu/malloc.h" #include "bu/exit.h" @@ -49,7 +50,7 @@ unsigned char *buffer; ssize_t scanlen; /* length of infile scanlines */ ssize_t buflines; /* Number of lines held in buffer */ -off_t buf_start = -1000; /* First line in buffer */ +b_off_t buf_start = -1000; /* First line in buffer */ unsigned long xnum, ynum; /* Number of pixels in new file */ float ulx, uly, urx, ury, lrx, lry, llx, lly; /* Corners of original file */ @@ -102,7 +103,7 @@ fill_buffer(int y) buf_start = y - buflines/2; if (buf_start < 0) buf_start = 0; - bu_fseek(ifp, 0, 0); + fseek(ifp, 0, 0); ret = fread(buffer, scanlen, 3*buflines, ifp); if (ret == 0) perror("fread"); diff --git a/src/util/pixrot.c b/src/util/pixrot.c index 3649c864d14..ac96cf8e5b0 100644 --- a/src/util/pixrot.c +++ b/src/util/pixrot.c @@ -142,7 +142,7 @@ int main(int argc, char **argv) { int x, y, j; - off_t outbyte, outplace; + b_off_t outbyte, outplace; size_t ret; if (!get_args(argc, argv) || isatty(fileno(stdout))) { @@ -190,7 +190,7 @@ main(int argc, char **argv) xout = (nyin - 1) - lasty; outbyte = ((yout * nyin) + xout) * pixbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, 0) < 0) { + if (fseek(ofp, outbyte, 0) < 0) { bu_exit(3, "pixrot: Can't seek on output, yet I need to!\n"); } outplace = outbyte; @@ -215,7 +215,7 @@ main(int argc, char **argv) xout = yin; outbyte = ((yout * nyin) + xout) * pixbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, 0) < 0) { + if (fseek(ofp, outbyte, 0) < 0) { bu_exit(3, "pixrot: Can't seek on output, yet I need to!\n"); } outplace = outbyte; @@ -232,7 +232,7 @@ main(int argc, char **argv) yout = (nyin - 1) - y; outbyte = yout * scanbytes; if (outplace != outbyte) { - if (bu_fseek(ofp, outbyte, 0) < 0) { + if (fseek(ofp, outbyte, 0) < 0) { bu_exit(3, "pixrot: Can't seek on output, yet I need to!\n"); } outplace = outbyte; diff --git a/src/util/pixscale.c b/src/util/pixscale.c index 5eb57a54411..c59f99cab76 100644 --- a/src/util/pixscale.c +++ b/src/util/pixscale.c @@ -50,7 +50,7 @@ unsigned char *outbuf; unsigned char *buffer; ssize_t scanlen; /* length of infile (and buffer) scanlines */ ssize_t buflines; /* Number of lines held in buffer */ -off_t buf_start = -1000; /* First line in buffer */ +b_off_t buf_start = -1000; /* First line in buffer */ ssize_t bufy; /* y coordinate in buffer */ FILE *buffp; @@ -83,14 +83,14 @@ Usage: pixscale [-r] [-s squareinsize] [-w inwidth] [-n inheight]\n\ void fill_buffer(int y) { - static off_t file_pos = 0; + static b_off_t file_pos = 0; size_t ret; buf_start = y - buflines/2; if (buf_start < 0) buf_start = 0; if (file_pos != buf_start * scanlen) { - if (bu_fseek(buffp, buf_start * scanlen, 0) < 0) { + if (fseek(buffp, buf_start * scanlen, 0) < 0) { bu_exit(3, "pixscale: Can't seek to input pixel! y=%d\n", y); } file_pos = buf_start * scanlen; diff --git a/src/util/plot3rot.c b/src/util/plot3rot.c index ed7dbe2b9c4..c9f06bb9a59 100644 --- a/src/util/plot3rot.c +++ b/src/util/plot3rot.c @@ -525,7 +525,7 @@ dofile(FILE *fp) bu_log("plot3rot: unrecognized command '%c' (0x%x)\n", (isprint(c)) ? c : '?', c); - bu_log("plot3rot: ftell = %jd\n", (intmax_t)bu_ftell(fp)); + bu_log("plot3rot: ftell = %jd\n", (intmax_t)ftell(fp)); putchar(c); break; }