1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * Copyright by The HDF Group. * 3 * Copyright by the Board of Trustees of the University of Illinois. * 4 * All rights reserved. * 5 * * 6 * This file is part of HDF5. The full HDF5 copyright notice, including * 7 * terms governing use, modification, and redistribution, is contained in * 8 * the COPYING file, which can be found at the root of the source code * 9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * 10 * If you do not have access to either file, you may request a copy from * 11 * help@hdfgroup.org. * 12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 13 14 /* Programmer: Robb Matzke <matzke@llnl.gov> 15 * Friday, October 30, 1998 16 * 17 * Purpose: This file is included by all HDF5 library source files to 18 * define common things which are not defined in the HDF5 API. 19 * The configuration constants like H5_HAVE_UNISTD_H etc. are 20 * defined in H5config.h which is included by H5public.h. 21 * 22 */ 23 24 #ifndef _H5private_H 25 #define _H5private_H 26 27 #include "H5public.h" /* Include Public Definitions */ 28 29 /* include the pthread header */ 30 #ifdef H5_HAVE_THREADSAFE 31 #ifdef H5_HAVE_WIN32_API 32 #ifndef H5_HAVE_WIN_THREADS 33 #ifdef H5_HAVE_PTHREAD_H 34 #include <pthread.h> 35 #endif /* H5_HAVE_PTHREAD_H */ 36 #endif /* H5_HAVE_WIN_THREADS */ 37 #else /* H5_HAVE_WIN32_API */ 38 #ifdef H5_HAVE_PTHREAD_H 39 #include <pthread.h> 40 #endif /* H5_HAVE_PTHREAD_H */ 41 #endif /* H5_HAVE_WIN32_API */ 42 #endif /* H5_HAVE_THREADSAFE */ 43 44 /* 45 * Include ANSI-C header files. 46 */ 47 #ifdef H5_STDC_HEADERS 48 # include <assert.h> 49 # include <ctype.h> 50 # include <errno.h> 51 # include <fcntl.h> 52 # include <float.h> 53 # include <limits.h> 54 # include <math.h> 55 # include <signal.h> 56 # include <stdarg.h> 57 # include <stdio.h> 58 # include <stdlib.h> 59 # include <string.h> 60 #endif 61 62 /* 63 * If _POSIX_VERSION is defined in unistd.h then this system is Posix.1 64 * compliant. Otherwise all bets are off. 65 */ 66 #ifdef H5_HAVE_UNISTD_H 67 # include <sys/types.h> 68 # include <unistd.h> 69 #endif 70 #ifdef _POSIX_VERSION 71 # include <sys/wait.h> 72 # include <pwd.h> 73 #endif 74 75 /* 76 * C9x integer types 77 */ 78 #ifndef __cplusplus 79 #ifdef H5_HAVE_STDINT_H 80 # include <stdint.h> 81 #endif 82 #endif 83 84 /* 85 * The `struct stat' data type for stat() and fstat(). This is a Posix file 86 * but often apears on non-Posix systems also. The `struct stat' is required 87 * for hdf5 to compile, although only a few fields are actually used. 88 */ 89 #ifdef H5_HAVE_SYS_STAT_H 90 # include <sys/stat.h> 91 #endif 92 93 /* 94 * If a program may include both `time.h' and `sys/time.h' then 95 * TIME_WITH_SYS_TIME is defined (see AC_HEADER_TIME in configure.ac). 96 * On some older systems, `sys/time.h' includes `time.h' but `time.h' is not 97 * protected against multiple inclusion, so programs should not explicitly 98 * include both files. This macro is useful in programs that use, for example, 99 * `struct timeval' or `struct timezone' as well as `struct tm'. It is best 100 * used in conjunction with `HAVE_SYS_TIME_H', whose existence is checked 101 * by `AC_CHECK_HEADERS(sys/time.h)' in configure.ac. 102 */ 103 #if defined(H5_TIME_WITH_SYS_TIME) 104 # include <sys/time.h> 105 # include <time.h> 106 #elif defined(H5_HAVE_SYS_TIME_H) 107 # include <sys/time.h> 108 #else 109 # include <time.h> 110 #endif 111 112 /* 113 * Longjumps are used to detect alignment constrants 114 */ 115 #ifdef H5_HAVE_SETJMP_H 116 # include <setjmp.h> 117 #endif 118 119 /* 120 * Resource usage is not Posix.1 but HDF5 uses it anyway for some performance 121 * and debugging code if available. 122 */ 123 #ifdef H5_HAVE_SYS_RESOURCE_H 124 # include <sys/resource.h> 125 #endif 126 127 /* 128 * Unix ioctls. These are used by h5ls (and perhaps others) to determine a 129 * resonable output width. 130 */ 131 #ifdef H5_HAVE_SYS_IOCTL_H 132 # include <sys/ioctl.h> 133 #endif 134 135 /* 136 * System information. These are needed on the DEC Alpha to turn off fixing 137 * of unaligned accesses by the operating system during detection of 138 * alignment constraints in H5detect.c:main(). 139 */ 140 #ifdef H5_HAVE_SYS_SYSINFO_H 141 # include <sys/sysinfo.h> 142 #endif 143 #ifdef H5_HAVE_SYS_PROC_H 144 # include <sys/proc.h> 145 #endif 146 #ifdef H5_HAVE_IO_H 147 # include <io.h> 148 #endif 149 150 /* 151 * Dynamic library handling. These are needed for dynamically loading I/O 152 * filters and VFDs. 153 */ 154 #ifdef H5_HAVE_DLFCN_H 155 #include <dlfcn.h> 156 #endif 157 #ifdef H5_HAVE_DIRENT_H 158 #include <dirent.h> 159 #endif 160 161 /* Define the default VFD for this platform. 162 * Since the removal of the Windows VFD, this is sec2 for all platforms. 163 */ 164 #define H5_DEFAULT_VFD H5FD_SEC2 165 166 #ifdef H5_HAVE_WIN32_API 167 /* The following two defines must be before any windows headers are included */ 168 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ 169 #define NOGDI /* Exclude Graphic Display Interface macros */ 170 171 #ifdef H5_HAVE_WINSOCK2_H 172 #include <winsock2.h> 173 #endif 174 175 #ifdef H5_HAVE_THREADSAFE 176 #include <process.h> /* For _beginthread() */ 177 #endif 178 179 #include <windows.h> 180 #include <direct.h> /* For _getcwd() */ 181 182 #endif /*H5_HAVE_WIN32_API*/ 183 184 /* Various ways that inline functions can be declared */ 185 #if defined(H5_HAVE___INLINE__) 186 /* GNU (alternative form) */ 187 #define H5_INLINE __inline__ 188 #elif defined(H5_HAVE___INLINE) 189 /* Visual Studio */ 190 #define H5_INLINE __inline 191 #elif defined(H5_HAVE_INLINE) 192 /* GNU, C++ 193 * Use "inline" as a last resort on the off-chance that there will 194 * be C++ problems. 195 */ 196 #define H5_INLINE inline 197 #else 198 #define H5_INLINE 199 #endif /* inline choices */ 200 201 #ifndef F_OK 202 # define F_OK 00 203 # define W_OK 02 204 # define R_OK 04 205 #endif 206 207 /* 208 * MPE Instrumentation support 209 */ 210 #ifdef H5_HAVE_MPE 211 /*------------------------------------------------------------------------ 212 * Purpose: Begin to collect MPE log information for a function. It should 213 * be ahead of the actual function's process. 214 * 215 * Programmer: Long Wang 216 * 217 *------------------------------------------------------------------------ 218 */ 219 #include "mpe.h" 220 /* 221 * #define eventa(func_name) h5_mpe_ ## func_name ## _a 222 * #define eventb(func_name) h5_mpe_ ## func_name ## _b 223 */ 224 #define eventa(func_name) h5_mpe_eventa 225 #define eventb(func_name) h5_mpe_eventb 226 #define MPE_LOG_VARS \ 227 static int eventa(FUNC) = -1; \ 228 static int eventb(FUNC) = -1; \ 229 char p_event_start[128]; 230 231 /* Hardwire the color to "red", since that's what all the routines are using 232 * now. In the future, if we want to change that color for a given routine, 233 * we should define a "FUNC_ENTER_API_COLOR" macro which takes an extra 'color' 234 * parameter and then make additional FUNC_ENTER_<foo>_COLOR macros to get that 235 * color information down to the BEGIN_MPE_LOG macro (which should have a new 236 * BEGIN_MPE_LOG_COLOR variant). -QAK 237 */ 238 239 #define BEGIN_MPE_LOG \ 240 if (H5_MPEinit_g){ \ 241 sprintf(p_event_start, "start %s", FUNC); \ 242 if (eventa(FUNC) == -1 && eventb(FUNC) == -1) { \ 243 const char* p_color = "red"; \ 244 eventa(FUNC)=MPE_Log_get_event_number(); \ 245 eventb(FUNC)=MPE_Log_get_event_number(); \ 246 MPE_Describe_state(eventa(FUNC), eventb(FUNC), FUNC, p_color); \ 247 } \ 248 MPE_Log_event(eventa(FUNC), 0, p_event_start); \ 249 } 250 251 252 /*------------------------------------------------------------------------ 253 * Purpose: Finish the collection of MPE log information for a function. 254 * It should be after the actual function's process. 255 * 256 * Programmer: Long Wang 257 */ 258 #define FINISH_MPE_LOG \ 259 if (H5_MPEinit_g) { \ 260 MPE_Log_event(eventb(FUNC), 0, FUNC); \ 261 } 262 263 #else /* H5_HAVE_MPE */ 264 #define MPE_LOG_VARS /* void */ 265 #define BEGIN_MPE_LOG /* void */ 266 #define FINISH_MPE_LOG /* void */ 267 268 #endif /* H5_HAVE_MPE */ 269 270 /* 271 * dmalloc (debugging malloc) support 272 */ 273 #ifdef H5_HAVE_DMALLOC_H 274 #include "dmalloc.h" 275 #endif /* H5_HAVE_DMALLOC_H */ 276 277 /* 278 * NT doesn't define SIGBUS, but since NT only runs on processors 279 * that do not have alignment constraints a SIGBUS would never be 280 * raised, so we just replace it with SIGILL (which also should 281 * never be raised by the hdf5 library). 282 */ 283 #ifndef SIGBUS 284 # define SIGBUS SIGILL 285 #endif 286 287 /* 288 * Does the compiler support the __attribute__(()) syntax? It's no 289 * big deal if we don't. 290 */ 291 #ifdef __cplusplus 292 # define __attribute__(X) /*void*/ 293 #else /* __cplusplus */ 294 #ifndef H5_HAVE_ATTRIBUTE 295 # define __attribute__(X) /*void*/ 296 #endif 297 #endif /* __cplusplus */ 298 299 /* 300 * Status return values for the `herr_t' type. 301 * Since some unix/c routines use 0 and -1 (or more precisely, non-negative 302 * vs. negative) as their return code, and some assumption had been made in 303 * the code about that, it is important to keep these constants the same 304 * values. When checking the success or failure of an integer-valued 305 * function, remember to compare against zero and not one of these two 306 * values. 307 */ 308 #define SUCCEED 0 309 #define FAIL (-1) 310 #define UFAIL (unsigned)(-1) 311 312 /* number of members in an array */ 313 #ifndef NELMTS 314 # define NELMTS(X) (sizeof(X)/sizeof(X[0])) 315 #endif 316 317 /* minimum of two, three, or four values */ 318 #undef MIN 319 #define MIN(a,b) (((a)<(b)) ? (a) : (b)) 320 #define MIN2(a,b) MIN(a,b) 321 #define MIN3(a,b,c) MIN(a,MIN(b,c)) 322 #define MIN4(a,b,c,d) MIN(MIN(a,b),MIN(c,d)) 323 324 /* maximum of two, three, or four values */ 325 #undef MAX 326 #define MAX(a,b) (((a)>(b)) ? (a) : (b)) 327 #define MAX2(a,b) MAX(a,b) 328 #define MAX3(a,b,c) MAX(a,MAX(b,c)) 329 #define MAX4(a,b,c,d) MAX(MAX(a,b),MAX(c,d)) 330 331 /* limit the middle value to be within a range (inclusive) */ 332 #define RANGE(LO,X,HI) MAX(LO,MIN(X,HI)) 333 334 /* absolute value */ 335 #ifndef ABS 336 # define ABS(a) (((a)>=0) ? (a) : -(a)) 337 #endif 338 339 /* sign of argument */ 340 #ifndef SIGN 341 # define SIGN(a) ((a)>0 ? 1 : (a)<0 ? -1 : 0) 342 #endif 343 344 /* test for number that is a power of 2 */ 345 /* (from: http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2) */ 346 # define POWER_OF_TWO(n) (!(n & (n - 1)) && n) 347 348 /* 349 * HDF Boolean type. 350 */ 351 #ifndef FALSE 352 # define FALSE 0 353 #endif 354 #ifndef TRUE 355 # define TRUE 1 356 #endif 357 358 /* 359 * Numeric data types. Some of these might be defined in Posix.1g, otherwise 360 * we define them with the closest available type which is at least as large 361 * as the number of bits indicated in the type name. The `int8' types *must* 362 * be exactly one byte wide because we use it for pointer calculations to 363 * void* memory. 364 */ 365 #if H5_SIZEOF_INT8_T==0 366 typedef signed char int8_t; 367 # undef H5_SIZEOF_INT8_T 368 # define H5_SIZEOF_INT8_T H5_SIZEOF_CHAR 369 #elif H5_SIZEOF_INT8_T==1 370 #else 371 # error "the int8_t type must be 1 byte wide" 372 #endif 373 374 #if H5_SIZEOF_UINT8_T==0 375 typedef unsigned char uint8_t; 376 # undef H5_SIZEOF_UINT8_T 377 # define H5_SIZEOF_UINT8_T H5_SIZEOF_CHAR 378 #elif H5_SIZEOF_UINT8_T==1 379 #else 380 # error "the uint8_t type must be 1 byte wide" 381 #endif 382 383 #if H5_SIZEOF_INT16_T>=2 384 #elif H5_SIZEOF_SHORT>=2 385 typedef short int16_t; 386 # undef H5_SIZEOF_INT16_T 387 # define H5_SIZEOF_INT16_T H5_SIZEOF_SHORT 388 #elif H5_SIZEOF_INT>=2 389 typedef int int16_t; 390 # undef H5_SIZEOF_INT16_T 391 # define H5_SIZEOF_INT16_T H5_SIZEOF_INT 392 #else 393 # error "nothing appropriate for int16_t" 394 #endif 395 396 #if H5_SIZEOF_UINT16_T>=2 397 #elif H5_SIZEOF_SHORT>=2 398 typedef unsigned short uint16_t; 399 # undef H5_SIZEOF_UINT16_T 400 # define H5_SIZEOF_UINT16_T H5_SIZEOF_SHORT 401 #elif H5_SIZEOF_INT>=2 402 typedef unsigned uint16_t; 403 # undef H5_SIZEOF_UINT16_T 404 # define H5_SIZEOF_UINT16_T H5_SIZEOF_INT 405 #else 406 # error "nothing appropriate for uint16_t" 407 #endif 408 409 #if H5_SIZEOF_INT32_T>=4 410 #elif H5_SIZEOF_SHORT>=4 411 typedef short int32_t; 412 # undef H5_SIZEOF_INT32_T 413 # define H5_SIZEOF_INT32_T H5_SIZEOF_SHORT 414 #elif H5_SIZEOF_INT>=4 415 typedef int int32_t; 416 # undef H5_SIZEOF_INT32_T 417 # define H5_SIZEOF_INT32_T H5_SIZEOF_INT 418 #elif H5_SIZEOF_LONG>=4 419 typedef long int32_t; 420 # undef H5_SIZEOF_INT32_T 421 # define H5_SIZEOF_INT32_T H5_SIZEOF_LONG 422 #else 423 # error "nothing appropriate for int32_t" 424 #endif 425 426 /* 427 * Maximum and minimum values. These should be defined in <limits.h> for the 428 * most part. 429 */ 430 #ifndef LLONG_MAX 431 # define LLONG_MAX ((long long)(((unsigned long long)1 \ 432 <<(8*sizeof(long long)-1))-1)) 433 # define LLONG_MIN ((long long)(-LLONG_MAX)-1) 434 #endif 435 #ifndef ULLONG_MAX 436 # define ULLONG_MAX ((unsigned long long)((long long)(-1))) 437 #endif 438 #ifndef SIZET_MAX 439 # define SIZET_MAX ((size_t)(ssize_t)(-1)) 440 # define SSIZET_MAX ((ssize_t)(((size_t)1<<(8*sizeof(ssize_t)-1))-1)) 441 #endif 442 443 /* 444 * Maximum & minimum values for our typedefs. 445 */ 446 #define HSIZET_MAX ((hsize_t)ULLONG_MAX) 447 #define HSSIZET_MAX ((hssize_t)LLONG_MAX) 448 #define HSSIZET_MIN (~(HSSIZET_MAX)) 449 450 /* 451 * Types and max sizes for POSIX I/O. 452 * OS X (Darwin) is odd since the max I/O size does not match the types. 453 */ 454 #if defined(H5_HAVE_WIN32_API) 455 # define h5_posix_io_t unsigned int 456 # define h5_posix_io_ret_t int 457 # define H5_POSIX_MAX_IO_BYTES INT_MAX 458 #elif defined(H5_HAVE_DARWIN) 459 # define h5_posix_io_t size_t 460 # define h5_posix_io_ret_t ssize_t 461 # define H5_POSIX_MAX_IO_BYTES INT_MAX 462 #else 463 # define h5_posix_io_t size_t 464 # define h5_posix_io_ret_t ssize_t 465 # define H5_POSIX_MAX_IO_BYTES SSIZET_MAX 466 #endif 467 468 /* 469 * A macro to portably increment enumerated types. 470 */ 471 #ifndef H5_INC_ENUM 472 # define H5_INC_ENUM(TYPE,VAR) (VAR)=((TYPE)((VAR)+1)) 473 #endif 474 475 /* 476 * A macro to portably decrement enumerated types. 477 */ 478 #ifndef H5_DEC_ENUM 479 # define H5_DEC_ENUM(TYPE,VAR) (VAR)=((TYPE)((VAR)-1)) 480 #endif 481 482 /* Double constant wrapper 483 * 484 * Quiets gcc warnings from -Wunsuffixed-float-constants. 485 * 486 * This is a really annoying warning since the standard specifies that 487 * constants of type double do NOT get a suffix so there's no way 488 * to specify a constant of type double. To quiet gcc, we specify floating 489 * point constants as type long double and cast to double. 490 * 491 * Note that this macro only needs to be used where using a double 492 * is important. For most code, suffixing constants with F will quiet the 493 * compiler and not produce erroneous code. 494 */ 495 #define H5_DOUBLE(S) ((double) S ## L) 496 497 /* 498 * Methods to compare the equality of floating-point values: 499 * 500 * 1. H5_XXX_ABS_EQUAL - check if the difference is smaller than the 501 * Epsilon value. The Epsilon values, FLT_EPSILON, DBL_EPSILON, 502 * and LDBL_EPSILON, are defined by compiler in float.h. 503 * 504 * 2. H5_XXX_REL_EQUAL - check if the relative difference is smaller than a 505 * predefined value M. See if two values are relatively equal. 506 * It's the developer's responsibility not to pass in the value 0, which 507 * may cause the equation to fail. 508 */ 509 #define H5_FLT_ABS_EQUAL(X,Y) (HDfabsf(X-Y) < FLT_EPSILON) 510 #define H5_DBL_ABS_EQUAL(X,Y) (HDfabs (X-Y) < DBL_EPSILON) 511 #define H5_LDBL_ABS_EQUAL(X,Y) (HDfabsl(X-Y) < LDBL_EPSILON) 512 513 #define H5_FLT_REL_EQUAL(X,Y,M) (HDfabsf((Y-X) / X) < M) 514 #define H5_DBL_REL_EQUAL(X,Y,M) (HDfabs ((Y-X) / X) < M) 515 #define H5_LDBL_REL_EQUAL(X,Y,M) (HDfabsl((Y-X) / X) < M) 516 517 /* KiB, MiB, GiB, TiB, EiB - Used in profiling and timing code */ 518 #define H5_KB (1024.0F) 519 #define H5_MB (1024.0F * 1024.0F) 520 #define H5_GB (1024.0F * 1024.0F * 1024.0F) 521 #define H5_TB (1024.0F * 1024.0F * 1024.0F * 1024.0F) 522 #define H5_EB (1024.0F * 1024.0F * 1024.0F * 1024.0F * 1024.0F) 523 524 /* 525 * Data types and functions for timing certain parts of the library. 526 */ 527 typedef struct { 528 double utime; /*user time */ 529 double stime; /*system time */ 530 double etime; /*elapsed wall-clock time */ 531 } H5_timer_t; 532 533 H5_DLL void H5_timer_reset (H5_timer_t *timer); 534 H5_DLL void H5_timer_begin (H5_timer_t *timer); 535 H5_DLL void H5_timer_end (H5_timer_t *sum/*in,out*/, 536 H5_timer_t *timer/*in,out*/); 537 H5_DLL void H5_bandwidth(char *buf/*out*/, double nbytes, double nseconds); 538 H5_DLL time_t H5_now(void); 539 540 /* Depth of object copy */ 541 typedef enum { 542 H5_COPY_SHALLOW, /* Shallow copy from source to destination, just copy field pointers */ 543 H5_COPY_DEEP /* Deep copy from source to destination, including duplicating fields pointed to */ 544 } H5_copy_depth_t; 545 546 /* Common object copying udata (right now only used for groups and datasets) */ 547 typedef struct H5O_copy_file_ud_common_t { 548 struct H5O_pline_t *src_pline; /* Copy of filter pipeline for object */ 549 } H5O_copy_file_ud_common_t; 550 551 /* Unique object "position" */ 552 typedef struct { 553 unsigned long fileno; /* The unique identifier for the file of the object */ 554 haddr_t addr; /* The unique address of the object's header in that file */ 555 } H5_obj_t; 556 557 /* 558 * Redefine all the POSIX functions. We should never see a POSIX 559 * function (or any other non-HDF5 function) in the source! 560 */ 561 562 /* Put all platform-specific definitions in the following file */ 563 /* so that the following definitions are platform free. */ 564 #include "H5win32defs.h" /* For Windows-specific definitions */ 565 566 #ifndef HDabort 567 #define HDabort() abort() 568 #endif /* HDabort */ 569 #ifndef HDabs 570 #define HDabs(X) abs(X) 571 #endif /* HDabs */ 572 #ifndef HDaccess 573 #define HDaccess(F,M) access(F, M) 574 #endif /* HDaccess */ 575 #ifndef HDacos 576 #define HDacos(X) acos(X) 577 #endif /* HDacos */ 578 #ifndef HDalarm 579 #ifdef H5_HAVE_ALARM 580 #define HDalarm(N) alarm(N) 581 #else /* H5_HAVE_ALARM */ 582 #define HDalarm(N) (0) 583 #endif /* H5_HAVE_ALARM */ 584 #endif /* HDalarm */ 585 #ifndef HDasctime 586 #define HDasctime(T) asctime(T) 587 #endif /* HDasctime */ 588 #ifndef HDasin 589 #define HDasin(X) asin(X) 590 #endif /* HDasin */ 591 #ifndef HDasprintf 592 #define HDasprintf asprintf /*varargs*/ 593 #endif /* HDasprintf */ 594 #ifndef HDassert 595 #define HDassert(X) assert(X) 596 #endif /* HDassert */ 597 #ifndef HDatan 598 #define HDatan(X) atan(X) 599 #endif /* HDatan */ 600 #ifndef HDatan2 601 #define HDatan2(X,Y) atan2(X,Y) 602 #endif /* HDatan2 */ 603 #ifndef HDatexit 604 #define HDatexit(F) atexit(F) 605 #endif /* HDatexit */ 606 #ifndef HDatof 607 #define HDatof(S) atof(S) 608 #endif /* HDatof */ 609 #ifndef HDatoi 610 #define HDatoi(S) atoi(S) 611 #endif /* HDatoi */ 612 #ifndef HDatol 613 #define HDatol(S) atol(S) 614 #endif /* HDatol */ 615 #ifndef HDbsearch 616 #define HDbsearch(K,B,N,Z,F) bsearch(K,B,N,Z,F) 617 #endif /* HDbsearch */ 618 #ifndef HDcalloc 619 #define HDcalloc(N,Z) calloc(N,Z) 620 #endif /* HDcalloc */ 621 #ifndef HDceil 622 #define HDceil(X) ceil(X) 623 #endif /* HDceil */ 624 #ifndef HDcfgetispeed 625 #define HDcfgetispeed(T) cfgetispeed(T) 626 #endif /* HDcfgetispeed */ 627 #ifndef HDcfgetospeed 628 #define HDcfgetospeed(T) cfgetospeed(T) 629 #endif /* HDcfgetospeed */ 630 #ifndef HDcfsetispeed 631 #define HDcfsetispeed(T,S) cfsetispeed(T,S) 632 #endif /* HDcfsetispeed */ 633 #ifndef HDcfsetospeed 634 #define HDcfsetospeed(T,S) cfsetospeed(T,S) 635 #endif /* HDcfsetospeed */ 636 #ifndef HDchdir 637 #define HDchdir(S) chdir(S) 638 #endif /* HDchdir */ 639 #ifndef HDchmod 640 #define HDchmod(S,M) chmod(S,M) 641 #endif /* HDchmod */ 642 #ifndef HDchown 643 #define HDchown(S,O,G) chown(S,O,G) 644 #endif /* HDchown */ 645 #ifndef HDclearerr 646 #define HDclearerr(F) clearerr(F) 647 #endif /* HDclearerr */ 648 #ifndef HDclock 649 #define HDclock() clock() 650 #endif /* HDclock */ 651 #ifndef HDclose 652 #define HDclose(F) close(F) 653 #endif /* HDclose */ 654 #ifndef HDclosedir 655 #define HDclosedir(D) closedir(D) 656 #endif /* HDclosedir */ 657 #ifndef HDcos 658 #define HDcos(X) cos(X) 659 #endif /* HDcos */ 660 #ifndef HDcosh 661 #define HDcosh(X) cosh(X) 662 #endif /* HDcosh */ 663 #ifndef HDcreat 664 #define HDcreat(S,M) creat(S,M) 665 #endif /* HDcreat */ 666 #ifndef HDctermid 667 #define HDctermid(S) ctermid(S) 668 #endif /* HDctermid */ 669 #ifndef HDctime 670 #define HDctime(T) ctime(T) 671 #endif /* HDctime */ 672 #ifndef HDcuserid 673 #define HDcuserid(S) cuserid(S) 674 #endif /* HDcuserid */ 675 #ifndef HDdifftime 676 #ifdef H5_HAVE_DIFFTIME 677 #define HDdifftime(X,Y) difftime(X,Y) 678 #else /* H5_HAVE_DIFFTIME */ 679 #define HDdifftime(X,Y) ((double)(X)-(double)(Y)) 680 #endif /* H5_HAVE_DIFFTIME */ 681 #endif /* HDdifftime */ 682 #ifndef HDdiv 683 #define HDdiv(X,Y) div(X,Y) 684 #endif /* HDdiv */ 685 #ifndef HDdup 686 #define HDdup(F) dup(F) 687 #endif /* HDdup */ 688 #ifndef HDdup2 689 #define HDdup2(F,I) dup2(F,I) 690 #endif /* HDdup2 */ 691 /* execl() variable arguments */ 692 /* execle() variable arguments */ 693 /* execlp() variable arguments */ 694 #ifndef HDexecv 695 #define HDexecv(S,AV) execv(S,AV) 696 #endif /* HDexecv */ 697 #ifndef HDexecve 698 #define HDexecve(S,AV,E) execve(S,AV,E) 699 #endif /* HDexecve */ 700 #ifndef HDexecvp 701 #define HDexecvp(S,AV) execvp(S,AV) 702 #endif /* HDexecvp */ 703 #ifndef HDexit 704 #define HDexit(N) exit(N) 705 #endif /* HDexit */ 706 #ifndef HD_exit 707 #define HD_exit(N) _exit(N) 708 #endif /* HD_exit */ 709 #ifndef HDexp 710 #define HDexp(X) exp(X) 711 #endif /* HDexp */ 712 #ifndef HDfabs 713 #define HDfabs(X) fabs(X) 714 #endif /* HDfabs */ 715 /* use ABS() because fabsf() fabsl() are not common yet. */ 716 #ifndef HDfabsf 717 #define HDfabsf(X) ABS(X) 718 #endif /* HDfabsf */ 719 #ifndef HDfabsl 720 #define HDfabsl(X) ABS(X) 721 #endif /* HDfabsl */ 722 #ifndef HDfclose 723 #define HDfclose(F) fclose(F) 724 #endif /* HDfclose */ 725 /* fcntl() variable arguments */ 726 #ifndef HDfdopen 727 #define HDfdopen(N,S) fdopen(N,S) 728 #endif /* HDfdopen */ 729 #ifndef HDfeof 730 #define HDfeof(F) feof(F) 731 #endif /* HDfeof */ 732 #ifndef HDferror 733 #define HDferror(F) ferror(F) 734 #endif /* HDferror */ 735 #ifndef HDfflush 736 #define HDfflush(F) fflush(F) 737 #endif /* HDfflush */ 738 #ifndef HDfgetc 739 #define HDfgetc(F) fgetc(F) 740 #endif /* HDfgetc */ 741 #ifndef HDfgetpos 742 #define HDfgetpos(F,P) fgetpos(F,P) 743 #endif /* HDfgetpos */ 744 #ifndef HDfgets 745 #define HDfgets(S,N,F) fgets(S,N,F) 746 #endif /* HDfgets */ 747 #ifndef HDfileno 748 #define HDfileno(F) fileno(F) 749 #endif /* HDfileno */ 750 #ifndef HDfloor 751 #define HDfloor(X) floor(X) 752 #endif /* HDfloor */ 753 #ifndef HDfmod 754 #define HDfmod(X,Y) fmod(X,Y) 755 #endif /* HDfmod */ 756 #ifndef HDfopen 757 #define HDfopen(S,M) fopen(S,M) 758 #endif /* HDfopen */ 759 #ifndef HDfork 760 #define HDfork() fork() 761 #endif /* HDfork */ 762 #ifndef HDfpathconf 763 #define HDfpathconf(F,N) fpathconf(F,N) 764 #endif /* HDfpathconf */ 765 H5_DLL int HDfprintf (FILE *stream, const char *fmt, ...); 766 #ifndef HDfputc 767 #define HDfputc(C,F) fputc(C,F) 768 #endif /* HDfputc */ 769 #ifndef HDfputs 770 #define HDfputs(S,F) fputs(S,F) 771 #endif /* HDfputs */ 772 #ifndef HDfread 773 #define HDfread(M,Z,N,F) fread(M,Z,N,F) 774 #endif /* HDfread */ 775 #ifndef HDfree 776 #define HDfree(M) free(M) 777 #endif /* HDfree */ 778 #ifndef HDfreopen 779 #define HDfreopen(S,M,F) freopen(S,M,F) 780 #endif /* HDfreopen */ 781 #ifndef HDfrexp 782 #define HDfrexp(X,N) frexp(X,N) 783 #endif /* HDfrexp */ 784 /* Check for Cray-specific 'frexpf()' and 'frexpl()' routines */ 785 #ifndef HDfrexpf 786 #ifdef H5_HAVE_FREXPF 787 #define HDfrexpf(X,N) frexpf(X,N) 788 #else /* H5_HAVE_FREXPF */ 789 #define HDfrexpf(X,N) frexp(X,N) 790 #endif /* H5_HAVE_FREXPF */ 791 #endif /* HDfrexpf */ 792 #ifndef HDfrexpl 793 #ifdef H5_HAVE_FREXPL 794 #define HDfrexpl(X,N) frexpl(X,N) 795 #else /* H5_HAVE_FREXPL */ 796 #define HDfrexpl(X,N) frexp(X,N) 797 #endif /* H5_HAVE_FREXPL */ 798 #endif /* HDfrexpl */ 799 /* fscanf() variable arguments */ 800 #ifndef HDfseek 801 #define HDfseek(F,O,W) fseeko(F,O,W) 802 #endif /* HDfseek */ 803 #ifndef HDfsetpos 804 #define HDfsetpos(F,P) fsetpos(F,P) 805 #endif /* HDfsetpos */ 806 #ifndef HDfstat 807 #define HDfstat(F,B) fstat(F,B) 808 #endif /* HDfstat */ 809 #ifndef HDlstat 810 #define HDlstat(S,B) lstat(S,B) 811 #endif /* HDlstat */ 812 #ifndef HDstat 813 #define HDstat(S,B) stat(S,B) 814 #endif /* HDstat */ 815 816 #ifndef H5_HAVE_WIN32_API 817 /* These definitions differ in Windows and are defined in 818 * H5win32defs for that platform. 819 */ 820 typedef struct stat h5_stat_t; 821 typedef off_t h5_stat_size_t; 822 #define HDoff_t off_t 823 #endif /* H5_HAVE_WIN32_API */ 824 825 #define H5_SIZEOF_H5_STAT_SIZE_T H5_SIZEOF_OFF_T 826 827 #ifndef HDftell 828 #define HDftell(F) ftello(F) 829 #endif /* HDftell */ 830 #ifndef HDftruncate 831 #define HDftruncate(F,L) ftruncate(F,L) 832 #endif /* HDftruncate */ 833 #ifndef HDfwrite 834 #define HDfwrite(M,Z,N,F) fwrite(M,Z,N,F) 835 #endif /* HDfwrite */ 836 #ifndef HDgetc 837 #define HDgetc(F) getc(F) 838 #endif /* HDgetc */ 839 #ifndef HDgetchar 840 #define HDgetchar() getchar() 841 #endif /* HDgetchar */ 842 #ifndef HDgetcwd 843 #define HDgetcwd(S,Z) getcwd(S,Z) 844 #endif /* HDgetcwd */ 845 #ifndef HDgetdcwd 846 #define HDgetdcwd(D,S,Z) getcwd(S,Z) 847 #endif /* HDgetdcwd */ 848 #ifndef HDgetdrive 849 #define HDgetdrive() 0 850 #endif /* HDgetdrive */ 851 #ifndef HDgetegid 852 #define HDgetegid() getegid() 853 #endif /* HDgetegid() */ 854 #ifndef HDgetenv 855 #define HDgetenv(S) getenv(S) 856 #endif /* HDgetenv */ 857 #ifndef HDgeteuid 858 #define HDgeteuid() geteuid() 859 #endif /* HDgeteuid */ 860 #ifndef HDgetgid 861 #define HDgetgid() getgid() 862 #endif /* HDgetgid */ 863 #ifndef HDgetgrgid 864 #define HDgetgrgid(G) getgrgid(G) 865 #endif /* HDgetgrgid */ 866 #ifndef HDgetgrnam 867 #define HDgetgrnam(S) getgrnam(S) 868 #endif /* HDgetgrnam */ 869 #ifndef HDgetgroups 870 #define HDgetgroups(Z,G) getgroups(Z,G) 871 #endif /* HDgetgroups */ 872 #ifndef HDgethostname 873 #define HDgethostname(N,L) gethostname(N,L) 874 #endif /* HDgetlogin */ 875 #ifndef HDgetlogin 876 #define HDgetlogin() getlogin() 877 #endif /* HDgetlogin */ 878 #ifndef HDgetpgrp 879 #define HDgetpgrp() getpgrp() 880 #endif /* HDgetpgrp */ 881 #ifndef HDgetpid 882 #define HDgetpid() getpid() 883 #endif /* HDgetpid */ 884 #ifndef HDgetppid 885 #define HDgetppid() getppid() 886 #endif /* HDgetppid */ 887 #ifndef HDgetpwnam 888 #define HDgetpwnam(S) getpwnam(S) 889 #endif /* HDgetpwnam */ 890 #ifndef HDgetpwuid 891 #define HDgetpwuid(U) getpwuid(U) 892 #endif /* HDgetpwuid */ 893 #ifndef HDgetrusage 894 #define HDgetrusage(X,S) getrusage(X,S) 895 #endif /* HDgetrusage */ 896 #ifndef HDgets 897 #define HDgets(S) gets(S) 898 #endif /* HDgets */ 899 #ifndef HDgettimeofday 900 #define HDgettimeofday(S,P) gettimeofday(S,P) 901 #endif /* HDgettimeofday */ 902 #ifndef HDgetuid 903 #define HDgetuid() getuid() 904 #endif /* HDgetuid */ 905 #ifndef HDgmtime 906 #define HDgmtime(T) gmtime(T) 907 #endif /* HDgmtime */ 908 #ifndef HDisalnum 909 #define HDisalnum(C) isalnum((int)(C)) /*cast for solaris warning*/ 910 #endif /* HDisalnum */ 911 #ifndef HDisalpha 912 #define HDisalpha(C) isalpha((int)(C)) /*cast for solaris warning*/ 913 #endif /* HDisalpha */ 914 #ifndef HDisatty 915 #define HDisatty(F) isatty(F) 916 #endif /* HDisatty */ 917 #ifndef HDiscntrl 918 #define HDiscntrl(C) iscntrl((int)(C)) /*cast for solaris warning*/ 919 #endif /* HDiscntrl */ 920 #ifndef HDisdigit 921 #define HDisdigit(C) isdigit((int)(C)) /*cast for solaris warning*/ 922 #endif /* HDisdigit */ 923 #ifndef HDisgraph 924 #define HDisgraph(C) isgraph((int)(C)) /*cast for solaris warning*/ 925 #endif /* HDisgraph */ 926 #ifndef HDislower 927 #define HDislower(C) islower((int)(C)) /*cast for solaris warning*/ 928 #endif /* HDislower */ 929 #ifndef HDisprint 930 #define HDisprint(C) isprint((int)(C)) /*cast for solaris warning*/ 931 #endif /* HDisprint */ 932 #ifndef HDispunct 933 #define HDispunct(C) ispunct((int)(C)) /*cast for solaris warning*/ 934 #endif /* HDispunct */ 935 #ifndef HDisspace 936 #define HDisspace(C) isspace((int)(C)) /*cast for solaris warning*/ 937 #endif /* HDisspace */ 938 #ifndef HDisupper 939 #define HDisupper(C) isupper((int)(C)) /*cast for solaris warning*/ 940 #endif /* HDisupper */ 941 #ifndef HDisxdigit 942 #define HDisxdigit(C) isxdigit((int)(C)) /*cast for solaris warning*/ 943 #endif /* HDisxdigit */ 944 #ifndef HDkill 945 #define HDkill(P,S) kill(P,S) 946 #endif /* HDkill */ 947 #ifndef HDlabs 948 #define HDlabs(X) labs(X) 949 #endif /* HDlabs */ 950 #ifndef HDldexp 951 #define HDldexp(X,N) ldexp(X,N) 952 #endif /* HDldexp */ 953 #ifndef HDldiv 954 #define HDldiv(X,Y) ldiv(X,Y) 955 #endif /* HDldiv */ 956 #ifndef HDlink 957 #define HDlink(OLD,NEW) link(OLD,NEW) 958 #endif /* HDlink */ 959 #ifndef HDlocaleconv 960 #define HDlocaleconv() localeconv() 961 #endif /* HDlocaleconv */ 962 #ifndef HDlocaltime 963 #define HDlocaltime(T) localtime(T) 964 #endif /* HDlocaltime */ 965 #ifndef HDlog 966 #define HDlog(X) log(X) 967 #endif /* HDlog */ 968 #ifndef HDlog10 969 #define HDlog10(X) log10(X) 970 #endif /* HDlog10 */ 971 #ifndef HDlongjmp 972 #define HDlongjmp(J,N) longjmp(J,N) 973 #endif /* HDlongjmp */ 974 #ifndef HDlseek 975 #define HDlseek(F,O,W) lseek(F,O,W) 976 #endif /* HDlseek */ 977 #ifndef HDmalloc 978 #define HDmalloc(Z) malloc(Z) 979 #endif /* HDmalloc */ 980 #ifndef HDposix_memalign 981 #define HDposix_memalign(P,A,Z) posix_memalign(P,A,Z) 982 #endif /* HDposix_memalign */ 983 #ifndef HDmblen 984 #define HDmblen(S,N) mblen(S,N) 985 #endif /* HDmblen */ 986 #ifndef HDmbstowcs 987 #define HDmbstowcs(P,S,Z) mbstowcs(P,S,Z) 988 #endif /* HDmbstowcs */ 989 #ifndef HDmbtowc 990 #define HDmbtowc(P,S,Z) mbtowc(P,S,Z) 991 #endif /* HDmbtowc */ 992 #ifndef HDmemchr 993 #define HDmemchr(S,C,Z) memchr(S,C,Z) 994 #endif /* HDmemchr */ 995 #ifndef HDmemcmp 996 #define HDmemcmp(X,Y,Z) memcmp(X,Y,Z) 997 #endif /* HDmemcmp */ 998 /* 999 * The (char*) casts are required for the DEC when optimizations are turned 1000 * on and the source and/or destination are not aligned. 1001 */ 1002 #ifndef HDmemcpy 1003 #define HDmemcpy(X,Y,Z) memcpy((char*)(X),(const char*)(Y),Z) 1004 #endif /* HDmemcpy */ 1005 #ifndef HDmemmove 1006 #define HDmemmove(X,Y,Z) memmove((char*)(X),(const char*)(Y),Z) 1007 #endif /* HDmemmove */ 1008 #ifndef HDmemset 1009 #define HDmemset(X,C,Z) memset(X,C,Z) 1010 #endif /* HDmemset */ 1011 #ifndef HDmkdir 1012 #define HDmkdir(S,M) mkdir(S,M) 1013 #endif /* HDmkdir */ 1014 #ifndef HDmkfifo 1015 #define HDmkfifo(S,M) mkfifo(S,M) 1016 #endif /* HDmkfifo */ 1017 #ifndef HDmktime 1018 #define HDmktime(T) mktime(T) 1019 #endif /* HDmktime */ 1020 #ifndef HDmodf 1021 #define HDmodf(X,Y) modf(X,Y) 1022 #endif /* HDmodf */ 1023 #ifndef HDopen 1024 #ifdef _O_BINARY 1025 #define HDopen(S,F,M) open(S,F|_O_BINARY,M) 1026 #else 1027 #define HDopen(S,F,M) open(S,F,M) 1028 #endif 1029 #endif /* HDopen */ 1030 #ifndef HDopendir 1031 #define HDopendir(S) opendir(S) 1032 #endif /* HDopendir */ 1033 #ifndef HDpathconf 1034 #define HDpathconf(S,N) pathconf(S,N) 1035 #endif /* HDpathconf */ 1036 #ifndef HDpause 1037 #define HDpause() pause() 1038 #endif /* HDpause */ 1039 #ifndef HDperror 1040 #define HDperror(S) perror(S) 1041 #endif /* HDperror */ 1042 #ifndef HDpipe 1043 #define HDpipe(F) pipe(F) 1044 #endif /* HDpipe */ 1045 #ifndef HDpow 1046 #define HDpow(X,Y) pow(X,Y) 1047 #endif /* HDpow */ 1048 /* printf() variable arguments */ 1049 #ifndef HDprintf 1050 #define HDprintf(...) HDfprintf(stdout, __VA_ARGS__) 1051 #endif /* HDprintf */ 1052 #ifndef HDputc 1053 #define HDputc(C,F) putc(C,F) 1054 #endif /* HDputc*/ 1055 #ifndef HDputchar 1056 #define HDputchar(C) putchar(C) 1057 #endif /* HDputchar */ 1058 #ifndef HDputs 1059 #define HDputs(S) puts(S) 1060 #endif /* HDputs */ 1061 #ifndef HDqsort 1062 #define HDqsort(M,N,Z,F) qsort(M,N,Z,F) 1063 #endif /* HDqsort*/ 1064 #ifndef HDraise 1065 #define HDraise(N) raise(N) 1066 #endif /* HDraise */ 1067 1068 #ifdef H5_HAVE_RAND_R 1069 #ifndef HDrandom 1070 #define HDrandom() HDrand() 1071 #endif /* HDrandom */ 1072 H5_DLL int HDrand(void); 1073 #elif H5_HAVE_RANDOM 1074 #ifndef HDrand 1075 #define HDrand() random() 1076 #endif /* HDrand */ 1077 #ifndef HDrandom 1078 #define HDrandom() random() 1079 #endif /* HDrandom */ 1080 #else /* H5_HAVE_RANDOM */ 1081 #ifndef HDrand 1082 #define HDrand() rand() 1083 #endif /* HDrand */ 1084 #ifndef HDrandom 1085 #define HDrandom() rand() 1086 #endif /* HDrandom */ 1087 #endif /* H5_HAVE_RANDOM */ 1088 1089 #ifndef HDread 1090 #define HDread(F,M,Z) read(F,M,Z) 1091 #endif /* HDread */ 1092 #ifndef HDreaddir 1093 #define HDreaddir(D) readdir(D) 1094 #endif /* HDreaddir */ 1095 #ifndef HDrealloc 1096 #define HDrealloc(M,Z) realloc(M,Z) 1097 #endif /* HDrealloc */ 1098 #ifndef HDrealpath 1099 #define HDrealpath(F1,F2) realpath(F1,F2) 1100 #endif /* HDrealloc */ 1101 #ifndef HDremove 1102 #define HDremove(S) remove(S) 1103 #endif /* HDremove */ 1104 #ifndef HDrename 1105 #define HDrename(OLD,NEW) rename(OLD,NEW) 1106 #endif /* HDrename */ 1107 #ifndef HDrewind 1108 #define HDrewind(F) rewind(F) 1109 #endif /* HDrewind */ 1110 #ifndef HDrewinddir 1111 #define HDrewinddir(D) rewinddir(D) 1112 #endif /* HDrewinddir */ 1113 #ifndef HDrmdir 1114 #define HDrmdir(S) rmdir(S) 1115 #endif /* HDrmdir */ 1116 /* scanf() variable arguments */ 1117 #ifndef HDsetbuf 1118 #define HDsetbuf(F,S) setbuf(F,S) 1119 #endif /* HDsetbuf */ 1120 #ifndef HDsetenv 1121 #define HDsetenv(N,V,O) setenv(N,V,O) 1122 #endif /* HDsetenv */ 1123 #ifndef HDsetgid 1124 #define HDsetgid(G) setgid(G) 1125 #endif /* HDsetgid */ 1126 #ifndef HDsetjmp 1127 #define HDsetjmp(J) setjmp(J) 1128 #endif /* HDsetjmp */ 1129 #ifndef HDsetlocale 1130 #define HDsetlocale(N,S) setlocale(N,S) 1131 #endif /* HDsetlocale */ 1132 #ifndef HDsetpgid 1133 #define HDsetpgid(P,PG) setpgid(P,PG) 1134 #endif /* HDsetpgid */ 1135 #ifndef HDsetsid 1136 #define HDsetsid() setsid() 1137 #endif /* HDsetsid */ 1138 #ifndef HDsetuid 1139 #define HDsetuid(U) setuid(U) 1140 #endif /* HDsetuid */ 1141 #ifndef HDsetvbuf 1142 #define HDsetvbuf(F,S,M,Z) setvbuf(F,S,M,Z) 1143 #endif /* HDsetvbuf */ 1144 #ifndef HDsigaddset 1145 #define HDsigaddset(S,N) sigaddset(S,N) 1146 #endif /* HDsigaddset */ 1147 #ifndef HDsigdelset 1148 #define HDsigdelset(S,N) sigdelset(S,N) 1149 #endif /* HDsigdelset */ 1150 #ifndef HDsigemptyset 1151 #define HDsigemptyset(S) sigemptyset(S) 1152 #endif /* HDsigemptyset */ 1153 #ifndef HDsigfillset 1154 #define HDsigfillset(S) sigfillset(S) 1155 #endif /* HDsigfillset */ 1156 #ifndef HDsigismember 1157 #define HDsigismember(S,N) sigismember(S,N) 1158 #endif /* HDsigismember */ 1159 #ifndef HDsiglongjmp 1160 #define HDsiglongjmp(J,N) siglongjmp(J,N) 1161 #endif /* HDsiglongjmp */ 1162 #ifndef HDsignal 1163 #define HDsignal(N,F) signal(N,F) 1164 #endif /* HDsignal */ 1165 #ifndef HDsigpending 1166 #define HDsigpending(S) sigpending(S) 1167 #endif /* HDsigpending */ 1168 #ifndef HDsigprocmask 1169 #define HDsigprocmask(H,S,O) sigprocmask(H,S,O) 1170 #endif /* HDsigprocmask */ 1171 #ifndef HDsigsetjmp 1172 #define HDsigsetjmp(J,N) sigsetjmp(J,N) 1173 #endif /* HDsigsetjmp */ 1174 #ifndef HDsigsuspend 1175 #define HDsigsuspend(S) sigsuspend(S) 1176 #endif /* HDsigsuspend */ 1177 #ifndef HDsin 1178 #define HDsin(X) sin(X) 1179 #endif /* HDsin */ 1180 #ifndef HDsinh 1181 #define HDsinh(X) sinh(X) 1182 #endif /* HDsinh */ 1183 #ifndef HDsleep 1184 #define HDsleep(N) sleep(N) 1185 #endif /* HDsleep */ 1186 #ifndef HDsnprintf 1187 #define HDsnprintf snprintf /*varargs*/ 1188 #endif /* HDsnprintf */ 1189 #ifndef HDsprintf 1190 #define HDsprintf sprintf /*varargs*/ 1191 #endif /* HDsprintf */ 1192 #ifndef HDsqrt 1193 #define HDsqrt(X) sqrt(X) 1194 #endif /* HDsqrt */ 1195 #ifdef H5_HAVE_RAND_R 1196 H5_DLL void HDsrand(unsigned int seed); 1197 #ifndef HDsrandom 1198 #define HDsrandom(S) HDsrand(S) 1199 #endif /* HDsrandom */ 1200 #elif H5_HAVE_RANDOM 1201 #ifndef HDsrand 1202 #define HDsrand(S) srandom(S) 1203 #endif /* HDsrand */ 1204 #ifndef HDsrandom 1205 #define HDsrandom(S) srandom(S) 1206 #endif /* HDsrandom */ 1207 #else /* H5_HAVE_RAND_R */ 1208 #ifndef HDsrand 1209 #define HDsrand(S) srand(S) 1210 #endif /* HDsrand */ 1211 #ifndef HDsrandom 1212 #define HDsrandom(S) srand(S) 1213 #endif /* HDsrandom */ 1214 #endif /* H5_HAVE_RAND_R */ 1215 /* sscanf() variable arguments */ 1216 1217 #ifndef HDstrcat 1218 #define HDstrcat(X,Y) strcat(X,Y) 1219 #endif /* HDstrcat */ 1220 #ifndef HDstrchr 1221 #define HDstrchr(S,C) strchr(S,C) 1222 #endif /* HDstrchr */ 1223 #ifndef HDstrcmp 1224 #define HDstrcmp(X,Y) strcmp(X,Y) 1225 #endif /* HDstrcmp */ 1226 #ifndef HDstrcasecmp 1227 #define HDstrcasecmp(X,Y) strcasecmp(X,Y) 1228 #endif /* HDstrcasecmp */ 1229 #ifndef HDstrcoll 1230 #define HDstrcoll(X,Y) strcoll(X,Y) 1231 #endif /* HDstrcoll */ 1232 #ifndef HDstrcpy 1233 #define HDstrcpy(X,Y) strcpy(X,Y) 1234 #endif /* HDstrcpy */ 1235 #ifndef HDstrcspn 1236 #define HDstrcspn(X,Y) strcspn(X,Y) 1237 #endif /* HDstrcspn */ 1238 #ifndef HDstrerror 1239 #define HDstrerror(N) strerror(N) 1240 #endif /* HDstrerror */ 1241 #ifndef HDstrftime 1242 #define HDstrftime(S,Z,F,T) strftime(S,Z,F,T) 1243 #endif /* HDstrftime */ 1244 #ifndef HDstrlen 1245 #define HDstrlen(S) strlen(S) 1246 #endif /* HDstrlen */ 1247 #ifndef HDstrncat 1248 #define HDstrncat(X,Y,Z) strncat(X,Y,Z) 1249 #endif /* HDstrncat */ 1250 #ifndef HDstrncmp 1251 #define HDstrncmp(X,Y,Z) strncmp(X,Y,Z) 1252 #endif /* HDstrncmp */ 1253 #ifndef HDstrncpy 1254 #define HDstrncpy(X,Y,Z) strncpy(X,Y,Z) 1255 #endif /* HDstrncpy */ 1256 #ifndef HDstrpbrk 1257 #define HDstrpbrk(X,Y) strpbrk(X,Y) 1258 #endif /* HDstrpbrk */ 1259 #ifndef HDstrrchr 1260 #define HDstrrchr(S,C) strrchr(S,C) 1261 #endif /* HDstrrchr */ 1262 #ifndef HDstrspn 1263 #define HDstrspn(X,Y) strspn(X,Y) 1264 #endif /* HDstrspn */ 1265 #ifndef HDstrstr 1266 #define HDstrstr(X,Y) strstr(X,Y) 1267 #endif /* HDstrstr */ 1268 #ifndef HDstrtod 1269 #define HDstrtod(S,R) strtod(S,R) 1270 #endif /* HDstrtod */ 1271 #ifndef HDstrtok 1272 #define HDstrtok(X,Y) strtok(X,Y) 1273 #endif /* HDstrtok */ 1274 #ifndef HDstrtol 1275 #define HDstrtol(S,R,N) strtol(S,R,N) 1276 #endif /* HDstrtol */ 1277 #ifndef HDstrtoll 1278 #ifdef H5_HAVE_STRTOLL 1279 #define HDstrtoll(S,R,N) strtoll(S,R,N) 1280 #else 1281 H5_DLL int64_t HDstrtoll (const char *s, const char **rest, int base); 1282 #endif /* H5_HAVE_STRTOLL */ 1283 #endif /* HDstrtoll */ 1284 #ifndef HDstrtoul 1285 #define HDstrtoul(S,R,N) strtoul(S,R,N) 1286 #endif /* HDstrtoul */ 1287 #ifndef HDstrtoull 1288 #define HDstrtoull(S,R,N) strtoull(S,R,N) 1289 #endif /* HDstrtoul */ 1290 #ifndef HDstrxfrm 1291 #define HDstrxfrm(X,Y,Z) strxfrm(X,Y,Z) 1292 #endif /* HDstrxfrm */ 1293 #ifdef H5_HAVE_SYMLINK 1294 #ifndef HDsymlink 1295 #define HDsymlink(F1,F2) symlink(F1,F2) 1296 #endif /* HDsymlink */ 1297 #endif /* H5_HAVE_SYMLINK */ 1298 #ifndef HDsysconf 1299 #define HDsysconf(N) sysconf(N) 1300 #endif /* HDsysconf */ 1301 #ifndef HDsystem 1302 #define HDsystem(S) system(S) 1303 #endif /* HDsystem */ 1304 #ifndef HDtan 1305 #define HDtan(X) tan(X) 1306 #endif /* HDtan */ 1307 #ifndef HDtanh 1308 #define HDtanh(X) tanh(X) 1309 #endif /* HDtanh */ 1310 #ifndef HDtcdrain 1311 #define HDtcdrain(F) tcdrain(F) 1312 #endif /* HDtcdrain */ 1313 #ifndef HDtcflow 1314 #define HDtcflow(F,A) tcflow(F,A) 1315 #endif /* HDtcflow */ 1316 #ifndef HDtcflush 1317 #define HDtcflush(F,N) tcflush(F,N) 1318 #endif /* HDtcflush */ 1319 #ifndef HDtcgetattr 1320 #define HDtcgetattr(F,T) tcgetattr(F,T) 1321 #endif /* HDtcgetattr */ 1322 #ifndef HDtcgetpgrp 1323 #define HDtcgetpgrp(F) tcgetpgrp(F) 1324 #endif /* HDtcgetpgrp */ 1325 #ifndef HDtcsendbreak 1326 #define HDtcsendbreak(F,N) tcsendbreak(F,N) 1327 #endif /* HDtcsendbreak */ 1328 #ifndef HDtcsetattr 1329 #define HDtcsetattr(F,O,T) tcsetattr(F,O,T) 1330 #endif /* HDtcsetattr */ 1331 #ifndef HDtcsetpgrp 1332 #define HDtcsetpgrp(F,N) tcsetpgrp(F,N) 1333 #endif /* HDtcsetpgrp */ 1334 #ifndef HDtime 1335 #define HDtime(T) time(T) 1336 #endif /* HDtime */ 1337 #ifndef HDtimes 1338 #define HDtimes(T) times(T) 1339 #endif /* HDtimes*/ 1340 #ifndef HDtmpfile 1341 #define HDtmpfile() tmpfile() 1342 #endif /* HDtmpfile */ 1343 #ifndef HDtmpnam 1344 #define HDtmpnam(S) tmpnam(S) 1345 #endif /* HDtmpnam */ 1346 #ifndef HDtolower 1347 #define HDtolower(C) tolower(C) 1348 #endif /* HDtolower */ 1349 #ifndef HDtoupper 1350 #define HDtoupper(C) toupper(C) 1351 #endif /* HDtoupper */ 1352 #ifndef HDttyname 1353 #define HDttyname(F) ttyname(F) 1354 #endif /* HDttyname */ 1355 #ifndef HDtzset 1356 #define HDtzset() tzset() 1357 #endif /* HDtzset */ 1358 #ifndef HDumask 1359 #define HDumask(N) umask(N) 1360 #endif /* HDumask */ 1361 #ifndef HDuname 1362 #define HDuname(S) uname(S) 1363 #endif /* HDuname */ 1364 #ifndef HDungetc 1365 #define HDungetc(C,F) ungetc(C,F) 1366 #endif /* HDungetc */ 1367 #ifndef HDunlink 1368 #define HDunlink(S) unlink(S) 1369 #endif /* HDunlink */ 1370 #ifndef HDutime 1371 #define HDutime(S,T) utime(S,T) 1372 #endif /* HDutime */ 1373 #ifndef HDva_arg 1374 #define HDva_arg(A,T) va_arg(A,T) 1375 #endif /* HDva_arg */ 1376 #ifndef HDva_end 1377 #define HDva_end(A) va_end(A) 1378 #endif /* HDva_end */ 1379 #ifndef HDva_start 1380 #define HDva_start(A,P) va_start(A,P) 1381 #endif /* HDva_start */ 1382 #ifndef HDvasprintf 1383 #define HDvasprintf(RET,FMT,A) vasprintf(RET,FMT,A) 1384 #endif /* HDvasprintf */ 1385 #ifndef HDvfprintf 1386 #define HDvfprintf(F,FMT,A) vfprintf(F,FMT,A) 1387 #endif /* HDvfprintf */ 1388 #ifndef HDvprintf 1389 #define HDvprintf(FMT,A) vprintf(FMT,A) 1390 #endif /* HDvprintf */ 1391 #ifndef HDvsprintf 1392 #define HDvsprintf(S,FMT,A) vsprintf(S,FMT,A) 1393 #endif /* HDvsprintf */ 1394 #ifndef HDvsnprintf 1395 #define HDvsnprintf(S,N,FMT,A) vsnprintf(S,N,FMT,A) 1396 #endif /* HDvsnprintf */ 1397 #ifndef HDwait 1398 #define HDwait(W) wait(W) 1399 #endif /* HDwait */ 1400 #ifndef HDwaitpid 1401 #define HDwaitpid(P,W,O) waitpid(P,W,O) 1402 #endif /* HDwaitpid */ 1403 #ifndef HDwcstombs 1404 #define HDwcstombs(S,P,Z) wcstombs(S,P,Z) 1405 #endif /* HDwcstombs */ 1406 #ifndef HDwctomb 1407 #define HDwctomb(S,C) wctomb(S,C) 1408 #endif /* HDwctomb */ 1409 #ifndef HDwrite 1410 #define HDwrite(F,M,Z) write(F,M,Z) 1411 #endif /* HDwrite */ 1412 1413 /* 1414 * And now for a couple non-Posix functions... Watch out for systems that 1415 * define these in terms of macros. 1416 */ 1417 #if !defined strdup && !defined H5_HAVE_STRDUP 1418 extern char *strdup(const char *s); 1419 #endif 1420 1421 #ifndef HDstrdup 1422 #define HDstrdup(S) strdup(S) 1423 #endif /* HDstrdup */ 1424 1425 #ifndef HDpthread_self 1426 #define HDpthread_self() pthread_self() 1427 #endif /* HDpthread_self */ 1428 1429 /* Use this version of pthread_self for printing the thread ID */ 1430 #ifndef HDpthread_self_ulong 1431 #define HDpthread_self_ulong() ((unsigned long)pthread_self()) 1432 #endif /* HDpthread_self_ulong */ 1433 1434 /* 1435 * A macro for detecting over/under-flow when casting between types 1436 */ 1437 #ifndef NDEBUG 1438 #define H5_CHECK_OVERFLOW(var, vartype, casttype) \ 1439 { \ 1440 casttype _tmp_overflow = (casttype)(var); \ 1441 assert((var) == (vartype)_tmp_overflow); \ 1442 } 1443 #else /* NDEBUG */ 1444 #define H5_CHECK_OVERFLOW(var, vartype, casttype) 1445 #endif /* NDEBUG */ 1446 1447 /* 1448 * A macro for detecting over/under-flow when assigning between types 1449 */ 1450 #ifndef NDEBUG 1451 #define ASSIGN_TO_SMALLER_SIZE(dst, dsttype, src, srctype) \ 1452 { \ 1453 srctype _tmp_src = (srctype)(src); \ 1454 dsttype _tmp_dst = (dsttype)(_tmp_src); \ 1455 assert(_tmp_src == (srctype)_tmp_dst); \ 1456 (dst) = _tmp_dst; \ 1457 } 1458 1459 #define ASSIGN_TO_LARGER_SIZE_SAME_SIGNED(dst, dsttype, src, srctype) \ 1460 (dst) = (dsttype)(src); 1461 1462 #define ASSIGN_TO_LARGER_SIZE_SIGNED_TO_UNSIGNED(dst, dsttype, src, srctype) \ 1463 { \ 1464 srctype _tmp_src = (srctype)(src); \ 1465 dsttype _tmp_dst = (dsttype)(_tmp_src); \ 1466 assert(_tmp_src >= 0); \ 1467 assert(_tmp_src == _tmp_dst); \ 1468 (dst) = _tmp_dst; \ 1469 } 1470 1471 #define ASSIGN_TO_LARGER_SIZE_UNSIGNED_TO_SIGNED(dst, dsttype, src, srctype) \ 1472 (dst) = (dsttype)(src); 1473 1474 #define ASSIGN_TO_SAME_SIZE_UNSIGNED_TO_SIGNED(dst, dsttype, src, srctype) \ 1475 { \ 1476 srctype _tmp_src = (srctype)(src); \ 1477 dsttype _tmp_dst = (dsttype)(_tmp_src); \ 1478 assert(_tmp_dst >= 0); \ 1479 assert(_tmp_src == (srctype)_tmp_dst); \ 1480 (dst) = _tmp_dst; \ 1481 } 1482 1483 #define ASSIGN_TO_SAME_SIZE_SIGNED_TO_UNSIGNED(dst, dsttype, src, srctype) \ 1484 { \ 1485 srctype _tmp_src = (srctype)(src); \ 1486 dsttype _tmp_dst = (dsttype)(_tmp_src); \ 1487 assert(_tmp_src >= 0); \ 1488 assert(_tmp_src == (srctype)_tmp_dst); \ 1489 (dst) = _tmp_dst; \ 1490 } 1491 1492 #define ASSIGN_TO_SAME_SIZE_SAME_SIGNED(dst, dsttype, src, srctype) \ 1493 (dst) = (dsttype)(src); 1494 1495 /* Include the generated overflow header file */ 1496 #include "H5overflow.h" 1497 1498 /* Assign a variable to one of a different size (think safer dst = (dsttype)src"). 1499 * The code generated by the macro checks for overflows. 1500 */ 1501 #define H5_CHECKED_ASSIGN(dst, dsttype, src, srctype) \ 1502 H5_GLUE4(ASSIGN_,srctype,_TO_,dsttype)(dst,dsttype,src,srctype)\ 1503 1504 #else /* NDEBUG */ 1505 #define H5_CHECKED_ASSIGN(dst, dsttype, src, srctype) \ 1506 (dst) = (dsttype)(src); 1507 #endif /* NDEBUG */ 1508 1509 #if defined(H5_HAVE_WINDOW_PATH) 1510 1511 /* directory delimiter for Windows: slash and backslash are acceptable on Windows */ 1512 #define H5_DIR_SLASH_SEPC '/' 1513 #define H5_DIR_SEPC '\\' 1514 #define H5_DIR_SEPS "\\" 1515 #define H5_CHECK_DELIMITER(SS) ((SS == H5_DIR_SEPC) || (SS == H5_DIR_SLASH_SEPC)) 1516 #define H5_CHECK_ABSOLUTE(NAME) ((HDisalpha(NAME[0])) && (NAME[1] == ':') && (H5_CHECK_DELIMITER(NAME[2]))) 1517 #define H5_CHECK_ABS_DRIVE(NAME) ((HDisalpha(NAME[0])) && (NAME[1] == ':')) 1518 #define H5_CHECK_ABS_PATH(NAME) (H5_CHECK_DELIMITER(NAME[0])) 1519 1520 #define H5_GET_LAST_DELIMITER(NAME, ptr) { \ 1521 char *slash, *backslash; \ 1522 \ 1523 slash = HDstrrchr(NAME, H5_DIR_SLASH_SEPC); \ 1524 backslash = HDstrrchr(NAME, H5_DIR_SEPC); \ 1525 if(backslash > slash) \ 1526 (ptr = backslash); \ 1527 else \ 1528 (ptr = slash); \ 1529 } 1530 1531 #else /* H5_HAVE_WINDOW_PATH */ 1532 1533 #define H5_DIR_SEPC '/' 1534 #define H5_DIR_SEPS "/" 1535 #define H5_CHECK_DELIMITER(SS) (SS == H5_DIR_SEPC) 1536 #define H5_CHECK_ABSOLUTE(NAME) (H5_CHECK_DELIMITER(*NAME)) 1537 #define H5_CHECK_ABS_DRIVE(NAME) (0) 1538 #define H5_CHECK_ABS_PATH(NAME) (0) 1539 #define H5_GET_LAST_DELIMITER(NAME, ptr) ptr = HDstrrchr(NAME, H5_DIR_SEPC); 1540 1541 #endif /* H5_HAVE_WINDOW_PATH */ 1542 1543 #define H5_COLON_SEPC ':' 1544 1545 1546 /* Use FUNC to safely handle variations of C99 __func__ keyword handling */ 1547 #ifdef H5_HAVE_C99_FUNC 1548 #define FUNC __func__ 1549 #elif defined(H5_HAVE_FUNCTION) 1550 #define FUNC __FUNCTION__ 1551 #else 1552 #error "We need __func__ or __FUNCTION__ to test function names!" 1553 #endif 1554 1555 /* 1556 * These macros check whether debugging has been requested for a certain 1557 * package at run-time. Code for debugging is conditionally compiled by 1558 * defining constants like `H5X_DEBUG'. In order to see the output though 1559 * the code must be enabled at run-time with an environment variable 1560 * HDF5_DEBUG which is a list of packages to debug. 1561 * 1562 * Note: If you add/remove items from this enum then be sure to update the 1563 * information about the package in H5_init_library(). 1564 */ 1565 typedef enum { 1566 H5_PKG_A, /*Attributes */ 1567 H5_PKG_AC, /*Meta data cache */ 1568 H5_PKG_B, /*B-trees */ 1569 H5_PKG_D, /*Datasets */ 1570 H5_PKG_E, /*Error handling */ 1571 H5_PKG_F, /*Files */ 1572 H5_PKG_G, /*Groups */ 1573 H5_PKG_HG, /*Global heap */ 1574 H5_PKG_HL, /*Local heap */ 1575 H5_PKG_I, /*Interface */ 1576 H5_PKG_MF, /*File memory management */ 1577 H5_PKG_MM, /*Core memory management */ 1578 H5_PKG_O, /*Object headers */ 1579 H5_PKG_P, /*Property lists */ 1580 H5_PKG_S, /*Data spaces */ 1581 H5_PKG_T, /*Data types */ 1582 H5_PKG_V, /*Vector functions */ 1583 H5_PKG_Z, /*Raw data filters */ 1584 H5_NPKGS /*Must be last */ 1585 } H5_pkg_t; 1586 1587 typedef struct H5_debug_open_stream_t { 1588 FILE *stream; /* Open output stream */ 1589 struct H5_debug_open_stream_t *next; /* Next open output stream */ 1590 } H5_debug_open_stream_t; 1591 1592 typedef struct H5_debug_t { 1593 FILE *trace; /*API trace output stream */ 1594 hbool_t ttop; /*Show only top-level calls? */ 1595 hbool_t ttimes; /*Show trace event times? */ 1596 struct { 1597 const char *name; /*package name */ 1598 FILE *stream; /*output stream or NULL */ 1599 } pkg[H5_NPKGS]; 1600 H5_debug_open_stream_t *open_stream; /* Stack of open output streams */ 1601 } H5_debug_t; 1602 1603 extern H5_debug_t H5_debug_g; 1604 #define H5DEBUG(X) (H5_debug_g.pkg[H5_PKG_##X].stream) 1605 /* Do not use const else AIX strings does not show it. */ 1606 extern char H5libhdf5_settings[]; /* embedded library information */ 1607 1608 /*------------------------------------------------------------------------- 1609 * Purpose: These macros are inserted automatically just after the 1610 * FUNC_ENTER() macro of API functions and are used to trace 1611 * application program execution. Unless H5_DEBUG_API has been 1612 * defined they are no-ops. 1613 * 1614 * Arguments: R - Return type encoded as a string 1615 * T - Argument types encoded as a string 1616 * A0-An - Arguments. The number at the end of the macro name 1617 * indicates the number of arguments. 1618 * 1619 * Programmer: Robb Matzke 1620 * 1621 * Modifications: 1622 *------------------------------------------------------------------------- 1623 */ 1624 #ifdef H5_DEBUG_API 1625 #define H5TRACE_DECL const char *RTYPE=NULL; \ 1626 double CALLTIME; 1627 #define H5TRACE0(R,T) RTYPE=R; \ 1628 CALLTIME=H5_trace(NULL,FUNC,T) 1629 #define H5TRACE1(R,T,A0) RTYPE=R; \ 1630 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0) 1631 #define H5TRACE2(R,T,A0,A1) RTYPE=R; \ 1632 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1) 1633 #define H5TRACE3(R,T,A0,A1,A2) RTYPE=R; \ 1634 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2) 1635 #define H5TRACE4(R,T,A0,A1,A2,A3) RTYPE=R; \ 1636 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3) 1637 #define H5TRACE5(R,T,A0,A1,A2,A3,A4) RTYPE=R; \ 1638 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3, \ 1639 #A4,A4) 1640 #define H5TRACE6(R,T,A0,A1,A2,A3,A4,A5) RTYPE=R; \ 1641 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3, \ 1642 #A4,A4,#A5,A5) 1643 #define H5TRACE7(R,T,A0,A1,A2,A3,A4,A5,A6) RTYPE=R; \ 1644 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3, \ 1645 #A4,A4,#A5,A5,#A6,A6) 1646 #define H5TRACE8(R,T,A0,A1,A2,A3,A4,A5,A6,A7) RTYPE=R; \ 1647 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3, \ 1648 #A4,A4,#A5,A5,#A6,A6,#A7,A7) 1649 #define H5TRACE9(R,T,A0,A1,A2,A3,A4,A5,A6,A7,A8) RTYPE=R; \ 1650 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3, \ 1651 #A4,A4,#A5,A5,#A6,A6,#A7,A7,#A8,A8) 1652 #define H5TRACE10(R,T,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9) RTYPE=R; \ 1653 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3, \ 1654 #A4,A4,#A5,A5,#A6,A6,#A7,A7,#A8,A8,#A9,A9) 1655 #define H5TRACE11(R,T,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) RTYPE=R; \ 1656 CALLTIME=H5_trace(NULL,FUNC,T,#A0,A0,#A1,A1,#A2,A2,#A3,A3, \ 1657 #A4,A4,#A5,A5,#A6,A6,#A7,A7,#A8,A8,#A9,A9, \ 1658 #A10,A10) 1659 #define H5TRACE_RETURN(V) if (RTYPE) { \ 1660 H5_trace(&CALLTIME,FUNC,RTYPE,NULL,V); \ 1661 RTYPE=NULL; \ 1662 } 1663 #else 1664 #define H5TRACE_DECL /*void*/ 1665 #define H5TRACE0(R,T) /*void*/ 1666 #define H5TRACE1(R,T,A0) /*void*/ 1667 #define H5TRACE2(R,T,A0,A1) /*void*/ 1668 #define H5TRACE3(R,T,A0,A1,A2) /*void*/ 1669 #define H5TRACE4(R,T,A0,A1,A2,A3) /*void*/ 1670 #define H5TRACE5(R,T,A0,A1,A2,A3,A4) /*void*/ 1671 #define H5TRACE6(R,T,A0,A1,A2,A3,A4,A5) /*void*/ 1672 #define H5TRACE7(R,T,A0,A1,A2,A3,A4,A5,A6) /*void*/ 1673 #define H5TRACE8(R,T,A0,A1,A2,A3,A4,A5,A6,A7) /*void*/ 1674 #define H5TRACE9(R,T,A0,A1,A2,A3,A4,A5,A6,A7,A8) /*void*/ 1675 #define H5TRACE10(R,T,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9) /*void*/ 1676 #define H5TRACE11(R,T,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) /*void*/ 1677 #define H5TRACE_RETURN(V) /*void*/ 1678 #endif 1679 1680 H5_DLL double H5_trace(const double *calltime, const char *func, const char *type, ...); 1681 1682 1683 /*------------------------------------------------------------------------- 1684 * Purpose: Register function entry for library initialization and code 1685 * profiling. 1686 * 1687 * Notes: Every file must have a file-scope variable called 1688 * `initialize_interface_g' of type hbool_t which is initialized 1689 * to FALSE. 1690 * 1691 * Don't use local variable initializers which contain 1692 * calls to other library functions since the initializer 1693 * would happen before the FUNC_ENTER() gets called. Don't 1694 * use initializers that require special cleanup code to 1695 * execute if FUNC_ENTER() fails since a failing FUNC_ENTER() 1696 * returns immediately without branching to the `done' label. 1697 * 1698 * Programmer: Quincey Koziol 1699 * 1700 *------------------------------------------------------------------------- 1701 */ 1702 1703 /* `S' is the name of a function which is being tested to check if it's 1704 * an API function. 1705 * 1706 * BADNESS: 1707 * - Underscore at positions 2 or 3 (0-indexed string). Handles 1708 * H5_ and H5X_. 1709 * - Underscore at position 4 if position 3 is uppercase or a digit. 1710 * Handles H5XY_. 1711 */ 1712 #define H5_IS_API(S) (\ 1713 '_'!=((const char *)S)[2] /* underscore at position 2 */ \ 1714 && '_'!=((const char *)S)[3] /* underscore at position 3 */ \ 1715 && !( /* NOT */ \ 1716 ((const char *)S)[4] /* pos 4 exists */ \ 1717 && (HDisupper(S[3]) || HDisdigit(S[3])) /* pos 3 dig | uc */ \ 1718 && '_'==((const char *)S)[4] /* pos 4 underscore */ \ 1719 )\ 1720 ) 1721 1722 /* `S' is the name of a function which is being tested to check if it's */ 1723 /* a public API function */ 1724 #define H5_IS_PUB(S) (((HDisdigit(S[1]) || HDisupper(S[1])) && HDislower(S[2])) || \ 1725 ((HDisdigit(S[2]) || HDisupper(S[2])) && HDislower(S[3])) || \ 1726 (!S[4] || ((HDisdigit(S[3]) || HDisupper(S[3])) && HDislower(S[4])))) 1727 1728 /* `S' is the name of a function which is being tested to check if it's */ 1729 /* a private library function */ 1730 #define H5_IS_PRIV(S) (((HDisdigit(S[1]) || HDisupper(S[1])) && '_' == S[2] && HDislower(S[3])) || \ 1731 ((HDisdigit(S[2]) || HDisupper(S[2])) && '_' == S[3] && HDislower(S[4])) || \ 1732 ((HDisdigit(S[3]) || HDisupper(S[3])) && '_' == S[4] && HDislower(S[5]))) 1733 1734 /* `S' is the name of a function which is being tested to check if it's */ 1735 /* a package private function */ 1736 #define H5_IS_PKG(S) (((HDisdigit(S[1]) || HDisupper(S[1])) && '_' == S[2] && '_' == S[3] && HDislower(S[4])) || \ 1737 ((HDisdigit(S[2]) || HDisupper(S[2])) && '_' == S[3] && '_' == S[4] && HDislower(S[5])) || \ 1738 ((HDisdigit(S[3]) || HDisupper(S[3])) && '_' == S[4] && '_' == S[5] && HDislower(S[6]))) 1739 1740 /* global library version information string */ 1741 extern char H5_lib_vers_info_g[]; 1742 1743 /* Lock headers */ 1744 #ifdef H5_HAVE_THREADSAFE 1745 1746 /* Include required thread-safety header */ 1747 #include "H5TSprivate.h" 1748 1749 /* replacement structure for original global variable */ 1750 typedef struct H5_api_struct { 1751 H5TS_mutex_t init_lock; /* API entrance mutex */ 1752 hbool_t H5_libinit_g; /* Has the library been initialized? */ 1753 } H5_api_t; 1754 1755 /* Macros for accessing the global variables */ 1756 #define H5_INIT_GLOBAL H5_g.H5_libinit_g 1757 1758 /* Macro for first thread initialization */ 1759 #ifdef H5_HAVE_WIN_THREADS 1760 #define H5_FIRST_THREAD_INIT InitOnceExecuteOnce(&H5TS_first_init_g, H5TS_win32_process_enter, NULL, NULL); 1761 #else 1762 #define H5_FIRST_THREAD_INIT pthread_once(&H5TS_first_init_g, H5TS_pthread_first_thread_init); 1763 #endif 1764 1765 /* Macros for threadsafe HDF-5 Phase I locks */ 1766 #define H5_API_LOCK \ 1767 H5TS_mutex_lock(&H5_g.init_lock); 1768 #define H5_API_UNLOCK \ 1769 H5TS_mutex_unlock(&H5_g.init_lock); 1770 1771 /* Macros for thread cancellation-safe mechanism */ 1772 #define H5_API_UNSET_CANCEL \ 1773 H5TS_cancel_count_inc(); 1774 1775 #define H5_API_SET_CANCEL \ 1776 H5TS_cancel_count_dec(); 1777 1778 extern H5_api_t H5_g; 1779 1780 #else /* H5_HAVE_THREADSAFE */ 1781 1782 /* disable any first thread init mechanism */ 1783 #define H5_FIRST_THREAD_INIT 1784 1785 /* disable locks (sequential version) */ 1786 #define H5_API_LOCK 1787 #define H5_API_UNLOCK 1788 1789 /* disable cancelability (sequential version) */ 1790 #define H5_API_UNSET_CANCEL 1791 #define H5_API_SET_CANCEL 1792 1793 /* extern global variables */ 1794 extern hbool_t H5_libinit_g; /* Has the library been initialized? */ 1795 1796 /* Macros for accessing the global variables */ 1797 #define H5_INIT_GLOBAL H5_libinit_g 1798 1799 #endif /* H5_HAVE_THREADSAFE */ 1800 1801 #ifdef H5_HAVE_CODESTACK 1802 1803 /* Include required function stack header */ 1804 #include "H5CSprivate.h" 1805 1806 #define H5_PUSH_FUNC H5CS_push(FUNC); 1807 #define H5_POP_FUNC H5CS_pop(); 1808 #else /* H5_HAVE_CODESTACK */ 1809 #define H5_PUSH_FUNC /* void */ 1810 #define H5_POP_FUNC /* void */ 1811 #endif /* H5_HAVE_CODESTACK */ 1812 1813 #ifdef H5_HAVE_MPE 1814 extern hbool_t H5_MPEinit_g; /* Has the MPE Library been initialized? */ 1815 #endif 1816 1817 /* Macros for defining interface initialization routines */ 1818 #ifdef H5_INTERFACE_INIT_FUNC 1819 static int H5_interface_initialize_g = 0; 1820 static herr_t H5_INTERFACE_INIT_FUNC(void); 1821 #define H5_INTERFACE_INIT(err) \ 1822 /* Initialize this interface or bust */ \ 1823 if (!H5_interface_initialize_g) { \ 1824 H5_interface_initialize_g = 1; \ 1825 if (H5_INTERFACE_INIT_FUNC()<0) { \ 1826 H5_interface_initialize_g = 0; \ 1827 HGOTO_ERROR (H5E_FUNC, H5E_CANTINIT, err, \ 1828 "interface initialization failed") \ 1829 } \ 1830 } 1831 #else /* H5_INTERFACE_INIT_FUNC */ 1832 #define H5_INTERFACE_INIT(err) 1833 #endif /* H5_INTERFACE_INIT_FUNC */ 1834 1835 1836 #ifndef NDEBUG 1837 #define FUNC_ENTER_CHECK_NAME(asrt) \ 1838 { \ 1839 static hbool_t func_check = FALSE; \ 1840 \ 1841 if(!func_check) { \ 1842 /* Check function naming status */ \ 1843 HDassert(asrt); \ 1844 \ 1845 /* Don't check again */ \ 1846 func_check = TRUE; \ 1847 } /* end if */ \ 1848 } /* end scope */ 1849 #else /* NDEBUG */ 1850 #define FUNC_ENTER_CHECK_NAME(asrt) 1851 #endif /* NDEBUG */ 1852 1853 1854 #define FUNC_ENTER_COMMON(asrt) \ 1855 hbool_t err_occurred = FALSE; \ 1856 FUNC_ENTER_CHECK_NAME(asrt); 1857 1858 #define FUNC_ENTER_COMMON_NOERR(asrt) \ 1859 FUNC_ENTER_CHECK_NAME(asrt); 1860 1861 /* Threadsafety initialization code for API routines */ 1862 #define FUNC_ENTER_API_THREADSAFE \ 1863 /* Initialize the thread-safe code */ \ 1864 H5_FIRST_THREAD_INIT \ 1865 \ 1866 /* Grab the mutex for the library */ \ 1867 H5_API_UNSET_CANCEL \ 1868 H5_API_LOCK 1869 1870 /* Local variables for API routines */ 1871 #define FUNC_ENTER_API_VARS \ 1872 MPE_LOG_VARS \ 1873 H5TRACE_DECL 1874 1875 #define FUNC_ENTER_API_COMMON \ 1876 FUNC_ENTER_API_VARS \ 1877 FUNC_ENTER_COMMON(H5_IS_API(FUNC)); \ 1878 FUNC_ENTER_API_THREADSAFE; 1879 1880 #define FUNC_ENTER_API_INIT(err) \ 1881 /* Initialize the library */ \ 1882 if(!(H5_INIT_GLOBAL)) { \ 1883 H5_INIT_GLOBAL = TRUE; \ 1884 if(H5_init_library() < 0) \ 1885 HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, err, \ 1886 "library initialization failed") \ 1887 } \ 1888 \ 1889 /* Initialize the interface, if appropriate */ \ 1890 H5_INTERFACE_INIT(err) \ 1891 \ 1892 /* Push the name of this function on the function stack */ \ 1893 H5_PUSH_FUNC \ 1894 \ 1895 BEGIN_MPE_LOG 1896 1897 /* Use this macro for all "normal" API functions */ 1898 #define FUNC_ENTER_API(err) {{ \ 1899 FUNC_ENTER_API_COMMON \ 1900 FUNC_ENTER_API_INIT(err); \ 1901 /* Clear thread error stack entering public functions */ \ 1902 H5E_clear_stack(NULL); \ 1903 { 1904 1905 /* 1906 * Use this macro for API functions that shouldn't clear the error stack 1907 * like H5Eprint and H5Ewalk. 1908 */ 1909 #define FUNC_ENTER_API_NOCLEAR(err) {{ \ 1910 FUNC_ENTER_API_COMMON \ 1911 FUNC_ENTER_API_INIT(err); \ 1912 { 1913 1914 /* 1915 * Use this macro for API functions that shouldn't perform _any_ initialization 1916 * of the library or an interface, just perform tracing, etc. Examples 1917 * are: H5check_version, etc. 1918 * 1919 */ 1920 #define FUNC_ENTER_API_NOINIT {{ \ 1921 FUNC_ENTER_API_COMMON \ 1922 H5_PUSH_FUNC \ 1923 BEGIN_MPE_LOG \ 1924 { 1925 1926 /* 1927 * Use this macro for API functions that shouldn't perform _any_ initialization 1928 * of the library or an interface or push themselves on the function 1929 * stack, just perform tracing, etc. Examples 1930 * are: H5close, H5check_version, etc. 1931 * 1932 */ 1933 #define FUNC_ENTER_API_NOINIT_NOERR_NOFS {{ \ 1934 FUNC_ENTER_API_VARS \ 1935 FUNC_ENTER_COMMON_NOERR(H5_IS_API(FUNC)); \ 1936 FUNC_ENTER_API_THREADSAFE; \ 1937 BEGIN_MPE_LOG \ 1938 { 1939 1940 /* Note: this macro only works when there's _no_ interface initialization routine for the module */ 1941 #define FUNC_ENTER_NOAPI_INIT(err) \ 1942 /* Initialize the interface, if appropriate */ \ 1943 H5_INTERFACE_INIT(err) \ 1944 \ 1945 /* Push the name of this function on the function stack */ \ 1946 H5_PUSH_FUNC 1947 1948 /* Use this macro for all "normal" non-API functions */ 1949 #define FUNC_ENTER_NOAPI(err) { \ 1950 FUNC_ENTER_COMMON(!H5_IS_API(FUNC)); \ 1951 FUNC_ENTER_NOAPI_INIT(err) \ 1952 { 1953 1954 /* Use this macro for all "normal" package-level functions */ 1955 #define FUNC_ENTER_PACKAGE { \ 1956 FUNC_ENTER_COMMON(H5_IS_PKG(FUNC)); \ 1957 H5_PUSH_FUNC \ 1958 { 1959 1960 /* Use this macro for package-level functions which propgate errors, but don't issue them */ 1961 #define FUNC_ENTER_PACKAGE_NOERR { \ 1962 FUNC_ENTER_COMMON_NOERR(H5_IS_PKG(FUNC)); \ 1963 H5_PUSH_FUNC \ 1964 { 1965 1966 /* Use this macro for all "normal" staticly-scoped functions */ 1967 #define FUNC_ENTER_STATIC { \ 1968 FUNC_ENTER_COMMON(H5_IS_PKG(FUNC)); \ 1969 H5_PUSH_FUNC \ 1970 { 1971 1972 /* Use this macro for staticly-scoped functions which propgate errors, but don't issue them */ 1973 #define FUNC_ENTER_STATIC_NOERR { \ 1974 FUNC_ENTER_COMMON_NOERR(H5_IS_PKG(FUNC)); \ 1975 H5_PUSH_FUNC \ 1976 { 1977 1978 /* Use this macro for all non-API functions, which propagate errors, but don't issue them */ 1979 #define FUNC_ENTER_NOAPI_NOERR { \ 1980 FUNC_ENTER_COMMON_NOERR(!H5_IS_API(FUNC)); \ 1981 FUNC_ENTER_NOAPI_INIT(-) \ 1982 { 1983 1984 /* 1985 * Use this macro for non-API functions which fall into these categories: 1986 * - static functions, since they must be called from a function in the 1987 * interface, the library and interface must already be 1988 * initialized. 1989 * - functions which are called during library shutdown, since we don't 1990 * want to re-initialize the library. 1991 */ 1992 #define FUNC_ENTER_NOAPI_NOINIT { \ 1993 FUNC_ENTER_COMMON(!H5_IS_API(FUNC)); \ 1994 H5_PUSH_FUNC \ 1995 { 1996 1997 /* 1998 * Use this macro for non-API functions which fall into these categories: 1999 * - static functions, since they must be called from a function in the 2000 * interface, the library and interface must already be 2001 * initialized. 2002 * - functions which are called during library shutdown, since we don't 2003 * want to re-initialize the library. 2004 * - functions that propagate, but don't issue errors 2005 */ 2006 #define FUNC_ENTER_NOAPI_NOINIT_NOERR { \ 2007 FUNC_ENTER_COMMON_NOERR(!H5_IS_API(FUNC)); \ 2008 H5_PUSH_FUNC \ 2009 { 2010 2011 /* 2012 * Use this macro for non-API functions which fall into these categories: 2013 * - functions which shouldn't push their name on the function stack 2014 * (so far, just the H5CS routines themselves) 2015 * 2016 * This macro is used for functions which fit the above categories _and_ 2017 * also don't use the 'FUNC' variable (i.e. don't push errors on the error stack) 2018 * 2019 */ 2020 #define FUNC_ENTER_NOAPI_NOERR_NOFS { \ 2021 FUNC_ENTER_COMMON_NOERR(!H5_IS_API(FUNC)); \ 2022 { 2023 2024 /*------------------------------------------------------------------------- 2025 * Purpose: Register function exit for code profiling. This should be 2026 * the last statement executed by a function. 2027 * 2028 * Programmer: Quincey Koziol 2029 * 2030 *------------------------------------------------------------------------- 2031 */ 2032 /* Threadsafety termination code for API routines */ 2033 #define FUNC_LEAVE_API_THREADSAFE \ 2034 H5_API_UNLOCK \ 2035 H5_API_SET_CANCEL 2036 2037 #define FUNC_LEAVE_API(ret_value) \ 2038 FINISH_MPE_LOG \ 2039 H5TRACE_RETURN(ret_value); \ 2040 H5_POP_FUNC \ 2041 if(err_occurred) \ 2042 (void)H5E_dump_api_stack(TRUE); \ 2043 FUNC_LEAVE_API_THREADSAFE \ 2044 return(ret_value); \ 2045 } /*end scope from end of FUNC_ENTER*/ \ 2046 }} /*end scope from beginning of FUNC_ENTER*/ 2047 2048 /* Use this macro to match the FUNC_ENTER_API_NOFS macro */ 2049 #define FUNC_LEAVE_API_NOFS(ret_value) \ 2050 FINISH_MPE_LOG \ 2051 H5TRACE_RETURN(ret_value); \ 2052 FUNC_LEAVE_API_THREADSAFE \ 2053 return(ret_value); \ 2054 } /*end scope from end of FUNC_ENTER*/ \ 2055 }} /*end scope from beginning of FUNC_ENTER*/ 2056 2057 #define FUNC_LEAVE_NOAPI(ret_value) \ 2058 H5_POP_FUNC \ 2059 return(ret_value); \ 2060 } /*end scope from end of FUNC_ENTER*/ \ 2061 } /*end scope from beginning of FUNC_ENTER*/ 2062 2063 #define FUNC_LEAVE_NOAPI_VOID \ 2064 H5_POP_FUNC \ 2065 return; \ 2066 } /*end scope from end of FUNC_ENTER*/ \ 2067 } /*end scope from beginning of FUNC_ENTER*/ 2068 2069 /* 2070 * Use this macro for non-API functions which fall into these categories: 2071 * - functions which didn't push their name on the function stack 2072 * (so far, just the H5CS routines themselves) 2073 */ 2074 #define FUNC_LEAVE_NOAPI_NOFS(ret_value) \ 2075 return(ret_value); \ 2076 } /*end scope from end of FUNC_ENTER*/ \ 2077 } /*end scope from beginning of FUNC_ENTER*/ 2078 2079 2080 /* Macro for "glueing" together items, for re-scanning macros */ 2081 #define H5_GLUE(x,y) x##y 2082 #define H5_GLUE3(x,y,z) x##y##z 2083 #define H5_GLUE4(w,x,y,z) w##x##y##z 2084 2085 /* Compile-time "assert" macro */ 2086 #define HDcompile_assert(e) ((void)sizeof(char[ !!(e) ? 1 : -1])) 2087 /* Variants that are correct, but generate compile-time warnings in some circumstances: 2088 #define HDcompile_assert(e) do { enum { compile_assert__ = 1 / (e) }; } while(0) 2089 #define HDcompile_assert(e) do { typedef struct { unsigned int b: (e); } x; } while(0) 2090 */ 2091 2092 /* Private functions, not part of the publicly documented API */ 2093 H5_DLL herr_t H5_init_library(void); 2094 H5_DLL void H5_term_library(void); 2095 2096 /* Functions to terminate interfaces */ 2097 H5_DLL int H5A_term_interface(void); 2098 H5_DLL int H5AC_term_interface(void); 2099 H5_DLL int H5D_term_interface(void); 2100 H5_DLL int H5E_term_interface(void); 2101 H5_DLL int H5F_term_interface(void); 2102 H5_DLL int H5FS_term_interface(void); 2103 H5_DLL int H5G_term_interface(void); 2104 H5_DLL int H5I_term_interface(void); 2105 H5_DLL int H5L_term_interface(void); 2106 H5_DLL int H5P_term_interface(void); 2107 H5_DLL int H5PL_term_interface(void); 2108 H5_DLL int H5R_term_interface(void); 2109 H5_DLL int H5S_term_interface(void); 2110 H5_DLL int H5T_term_interface(void); 2111 H5_DLL int H5Z_term_interface(void); 2112 2113 /* Checksum functions */ 2114 H5_DLL uint32_t H5_checksum_fletcher32(const void *data, size_t len); 2115 H5_DLL uint32_t H5_checksum_crc(const void *data, size_t len); 2116 H5_DLL uint32_t H5_checksum_lookup3(const void *data, size_t len, uint32_t initval); 2117 H5_DLL uint32_t H5_checksum_metadata(const void *data, size_t len, uint32_t initval); 2118 H5_DLL uint32_t H5_hash_string(const char *str); 2119 2120 /* Functions for building paths, etc. */ 2121 H5_DLL herr_t H5_build_extpath(const char *name, char **extpath /*out*/); 2122 H5_DLL herr_t H5_combine_path(const char *path1, const char *path2, char **full_name /*out*/); 2123 2124 /* Functions for debugging */ 2125 H5_DLL herr_t H5_buffer_dump(FILE *stream, int indent, const uint8_t *buf, 2126 const uint8_t *marker, size_t buf_offset, size_t buf_size); 2127 2128 #endif /* _H5private_H */ 2129 2130