mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-15 08:30:11 +08:00
90fd1406bc
Re: GH Issue https://github.com/Unidata/netcdf-c/issues/1900 Apparently the clock_gettime() function is not always available. It is used in unit_test/tst_exhash.c and unit_test/tst_xcache.c. To solve this, a number of things were changed: * Move the timing code to a new file unit_tests/timer_utils.[ch] * Modify the timing code to choose one of several timing methods depending on availability. The prioritized order is as follows: 1. If Windows, use the QueryPerformanceCounter mechanism else 2. Use clock_gettime if available else 3. Use gettimeofday if available else 4. Use getrusage if available Note that the resolution of 3 and 4 is less than 1 or 2. Misc. Other Changes: * Move the test in CMakeLists.txt that disables unit tests for WIN32 to unit_test/CMakeLists.txt since some unit tests actually work under Visual Studio. * Fix some of the unit tests to work under visual studio * Fix problem with using remove() in zmap_nzf.c * Remove some warning about use of EXTERNL
96 lines
2.4 KiB
C
96 lines
2.4 KiB
C
/*
|
|
* Copyright 2018, University Corporation for Atmospheric Research
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
*/
|
|
#ifndef _NCWINIO_H_
|
|
#define _NCWINIO_H_
|
|
|
|
#include "config.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#ifdef HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
#ifdef HAVE_DIRENT_H
|
|
#include <dirent.h>
|
|
#endif
|
|
#ifdef HAVE_FCNTL_H
|
|
#include <fcntl.h>
|
|
#endif
|
|
#include "ncexternl.h"
|
|
|
|
#ifndef WINPATH
|
|
#ifdef _WIN32
|
|
#define WINPATH 1
|
|
#endif
|
|
#ifdef __MINGW32__
|
|
#define WINPATH 1
|
|
#endif
|
|
#endif
|
|
|
|
/* Define wrapper constants for use with NCaccess */
|
|
#ifdef _WIN32
|
|
#define ACCESS_MODE_EXISTS 0
|
|
#define ACCESS_MODE_R 4
|
|
#define ACCESS_MODE_W 2
|
|
#define ACCESS_MODE_RW 6
|
|
#ifndef O_RDONLY
|
|
#define O_RDONLY _O_RDONLY
|
|
#define O_RDWR _O_RDWR
|
|
#define O_APPEND _O_APPEND
|
|
#define O_BINARY _O_BINARY
|
|
#define O_CREAT _O_CREAT
|
|
#define O_EXCL _O_EXCL
|
|
#endif
|
|
#else
|
|
#define ACCESS_MODE_EXISTS (F_OK)
|
|
#define ACCESS_MODE_R (R_OK)
|
|
#define ACCESS_MODE_W (W_OK)
|
|
#define ACCESS_MODE_RW (R_OK|W_OK)
|
|
#endif
|
|
|
|
/* Path Converter */
|
|
EXTERNL char* NCpathcvt(const char* path);
|
|
|
|
/* path -> URL Path converter */
|
|
EXTERNL char* NCurlpath(const char* path);
|
|
|
|
/* Fix path in case it was escaped by shell */
|
|
EXTERNL char* NCdeescape(const char* name);
|
|
|
|
#ifdef WINPATH
|
|
/* path converter wrappers*/
|
|
EXTERNL FILE* NCfopen(const char* path, const char* flags);
|
|
EXTERNL int NCopen3(const char* path, int flags, int mode);
|
|
EXTERNL int NCopen2(const char* path, int flags);
|
|
EXTERNL int NCaccess(const char* path, int mode);
|
|
EXTERNL int NCremove(const char* path);
|
|
EXTERNL int NCmkdir(const char* path, int mode);
|
|
EXTERNL int NCrmdir(const char* path);
|
|
EXTERNL char* NCcwd(char* cwdbuf, size_t len);
|
|
#ifdef HAVE_DIRENT_H
|
|
EXTERNL DIR* NCopendir(const char* path);
|
|
EXTERNL int NCclosedir(DIR* ent);
|
|
#endif
|
|
#else /*!WINPATH*/
|
|
#define NCfopen(path,flags) fopen((path),(flags))
|
|
#define NCopen3(path,flags,mode) open((path),(flags),(mode))
|
|
#define NCopen2(path,flags) open((path),(flags))
|
|
#define NCremove(path) remove(path)
|
|
#define NCaccess(path,mode) access(path,mode)
|
|
#define NCcwd(buf, len) getcwd(buf,len)
|
|
#define NCmkdir(path, mode) mkdir(path,mode)
|
|
#define NCrmdir(path) rmdir(path)
|
|
#ifdef HAVE_DIRENT_H
|
|
#define NCopendir(path) opendir(path)
|
|
#define NCclosedir(ent) closedir(ent)
|
|
#endif
|
|
#endif /*!WINPATH*/
|
|
|
|
/* Platform independent */
|
|
#define NCclose(fd) close(fd)
|
|
|
|
EXTERNL int NChasdriveletter(const char* path);
|
|
|
|
#endif /* _NCWINIO_H_ */
|