[svn-r15150] Purpose: Separate Windows function macro definitions to win32defs.h

Description:
In library code, we try not to use system calls directly, but instead use the HD{function} macro instead.  This way, we can map special versions of the call on particular systems.  Previously, it was all done in H5private.h.  However, in an effort to clean up platform-specific definitions, we move all of the Windows macros into a separate file, win32defs.h.  This way, we can use the non-Posix versions that Visual Studio sends warnings about.

Some macros are set specifically in the platform-specific header files.  Then, any macros left unset will be set by the "default" implementation in H5private.h.

This checkin also cleans up various source files to use the HD* macros when possible.

Tested:
VS2005 on WinXP
VS.NET on WinXP
h5committest (kagiso, linew, smirom)
This commit is contained in:
Scott Wegner 2008-06-05 13:52:19 -05:00
parent 92d070ab39
commit 532e23b808
18 changed files with 946 additions and 451 deletions

View File

@ -741,6 +741,7 @@
./src/Makefile.in
./src/hdf5.h
./src/libhdf5.settings.in
./src/win32defs.h
./test/COPYING
./test/Makefile.am

View File

@ -326,9 +326,9 @@ printf("Before getrusage() call\n");
for (i=0; i<nwrite; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
offset = lseek (fd, (off_t)0, SEEK_SET);
offset = HDlseek (fd, (off_t)0, SEEK_SET);
assert (0==offset);
n = write (fd, the_data, (size_t)(size[0]*size[1]));
n = HDwrite (fd, the_data, (size_t)(size[0]*size[1]));
assert (n>=0 && (size_t)n==size[0]*size[1]);
}
#ifdef H5_HAVE_GETRUSAGE
@ -405,9 +405,9 @@ printf("Before getrusage() call\n");
for (i=0; i<nread; i++) {
putc (PROGRESS, stderr);
fflush (stderr);
offset = lseek (fd, (off_t)0, SEEK_SET);
offset = HDlseek (fd, (off_t)0, SEEK_SET);
assert (0==offset);
n = read (fd, the_data, (size_t)(size[0]*size[1]));
n = HDread (fd, the_data, (size_t)(size[0]*size[1]));
assert (n>=0 && (size_t)n==size[0]*size[1]);
}
#ifdef H5_HAVE_GETRUSAGE

View File

@ -628,7 +628,7 @@ H5FD_log_close(H5FD_t *_file)
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
HDgettimeofday(&timeval_start,NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
if (close(file->fd)<0)
if (HDclose(file->fd)<0)
HGOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file")
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
@ -1331,7 +1331,7 @@ H5FD_log_flush(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing)
if(file->eoa>file->eof) {
if(-1 == file_seek(file->fd, (file_offset_t)(file->eoa - 1), SEEK_SET))
HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
if(write(file->fd, "", (size_t)1) != 1)
if(HDwrite(file->fd, "", (size_t)1) != 1)
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed")
file->eof = file->eoa;
file->pos = file->eoa;

File diff suppressed because it is too large Load Diff

56
src/win32defs.h Normal file
View File

@ -0,0 +1,56 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Programmer: Scott Wegner
* June 3, 2008
*
* Purpose: This file is used to map HDF macros to Windows functions. This
* should get included H5private mappings, so as to override them.
* Any macro not mapped here, however, will receive a similar mapping
* inside H5private.h
*
*/
#ifdef _WIN32
typedef struct _stati64 h5_stat_t;
typedef __int64 h5_stat_size_t;
#define HDaccess(F,M) _access(F,M)
#define HDclose(F) _close(F)
#define HDdup(F) _dup(F)
#define HDfdopen(N,S) _fdopen(N,S)
#define HDfileno(F) _fileno(F)
#define HDfstat(F,B) _fstati64(F,B)
#define HDisatty(F) _isatty(F)
#define HDstat(S,B) _stati64(S,B)
#define HDgetcwd(S,Z) _getcwd(S,Z)
#define HDgetdcwd(D,S,Z) _getdcwd(D,S,Z)
#define HDgetdrive() _getdrive()
#define HDlseek(F,O,W) _lseeki64(F,O,W)
#define HDmemset(X,C,Z) memset((void*)(X),C,Z)
#define HDmkdir(S,M) _mkdir(S)
#define HDopen(S,F,M) _open(S,F|_O_BINARY,M)
#define HDread(F,M,Z) _read(F,M,Z)
#define HDsetvbuf(F,S,M,Z) setvbuf(F,S,M,(Z>1?Z:2))
#define HDstrdup(S) _strdup(S)
#define HDsnprintf _snprintf /*varargs*/
#define HDtzset() _tzset()
#define HDunlink(S) _unlink(S)
#define HDvsnprintf(S,N,FMT,A) _vsnprintf(S,N,FMT,A)
#define HDwrite(F,M,Z) _write(F,M,Z)
#endif /* _WIN32 */

View File

@ -1731,11 +1731,11 @@ test_compound_10(void)
for(i=0; i<ARRAY_DIM; i++) {
wdata[i].i1 = i*10+i;
wdata[i].str = strdup("C string A");
wdata[i].str = HDstrdup("C string A");
wdata[i].str[9] += i;
wdata[i].i2 = i*1000+i*10;
wdata[i].text.p = (void*)strdup("variable-length text A\0");
wdata[i].text.p = (void*)HDstrdup("variable-length text A\0");
len = wdata[i].text.len = strlen((char*)wdata[i].text.p)+1;
((char*)(wdata[i].text.p))[len-2] += i;
((char*)(wdata[i].text.p))[len-1] = '\0';

View File

@ -56,26 +56,26 @@ same_contents (const char *name1, const char *name2)
ssize_t n1, n2;
char buf1[1024], buf2[1024];
fd1 = open (name1, O_RDONLY);
fd2 = open (name2, O_RDONLY);
fd1 = HDopen(name1, O_RDONLY, 0666);
fd2 = HDopen(name2, O_RDONLY, 0666);
assert (fd1>=0 && fd2>=0);
while (1) {
n1 = read (fd1, buf1, sizeof(buf1));
n2 = read (fd2, buf2, sizeof(buf2));
n1 = HDread(fd1, buf1, sizeof(buf1));
n2 = HDread(fd2, buf2, sizeof(buf2));
assert (n1>=0 && (size_t)n1<=sizeof(buf1));
assert (n2>=0 && (size_t)n2<=sizeof(buf2));
assert (n1==n2);
if (n1<=0 && n2<=0) break;
if (memcmp (buf1, buf2, (size_t)n1)) {
close (fd1);
close (fd2);
HDclose(fd1);
HDclose(fd2);
return 0;
}
}
close (fd1);
close (fd2);
HDclose(fd1);
HDclose(fd2);
return 1;
}
@ -619,15 +619,15 @@ test_2 (hid_t fapl)
part[j] = (int)(i*25+j);
}
sprintf (filename, "extern_%lua.raw", (unsigned long)i+1);
fd = HDopen (filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
assert (fd>=0);
/* n = lseek (fd, (off_t)(i*10), SEEK_SET);
*/
n = write(fd,temparray,(size_t)i*10);
n = HDwrite(fd,temparray,(size_t)i*10);
assert (n>=0 && (size_t)n==i*10);
n = write (fd, part, sizeof(part));
n = HDwrite(fd, part, sizeof(part));
assert (n==sizeof(part));
close (fd);
HDclose(fd);
}
/*
@ -752,14 +752,14 @@ test_3 (hid_t fapl)
/* Make sure the output files are fresh*/
for (i=1; i<=4; i++) {
sprintf(filename, "extern_%db.raw", i);
if ((fd= open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
if ((fd= HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
H5_FAILED();
printf(" cannot open %s: %s\n", filename, strerror(errno));
goto error;
}
write(fd, temparray, (i-1)*10);
close (fd);
HDwrite(fd, temparray, (i-1)*10);
HDclose(fd);
}
/* Create the dataset */

View File

@ -1883,8 +1883,8 @@ test_extend(hid_t fapl, const char *base_name, H5D_layout_t layout)
hsize_t nelmts;
nelmts = max_size[0]*max_size[1]*max_size[2]*max_size[3]*max_size[4];
if((fd=open(FILE_NAME_RAW, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0 ||
close(fd) < 0) goto error;
if((fd=HDopen(FILE_NAME_RAW, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0 ||
HDclose(fd) < 0) goto error;
if(H5Pset_external(dcpl, FILE_NAME_RAW, (off_t)0, (hsize_t)nelmts*sizeof(int)) < 0)
goto error;
}

View File

@ -258,7 +258,7 @@ test_fill(size_t nx, size_t ny, size_t nz,
if (acc != ref_value) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
/*
* Print debugging info unless output
* is going directly to a terminal.
@ -504,7 +504,7 @@ test_copy(int mode,
}
if (acc != ref_value) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
/*
* Print debugging info unless output is
* going directly to a terminal.
@ -547,7 +547,7 @@ test_copy(int mode,
if (acc+(unsigned)dx*(unsigned)dy*(unsigned)dz !=
ref_value + nx*ny*nz) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
/*
* Print debugging info unless output is
* going directly to a terminal.
@ -675,7 +675,7 @@ test_multifill(size_t nx)
}
if (s[0]) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
AT();
printf(" fill={%d,%g,%d}\n ",
fill.left, fill.mid, fill.right);
@ -757,7 +757,7 @@ test_endian(size_t nx)
for (j = 0; j < 4; j++) {
if (src[i * 4 + j] != dst[i * 4 + 3 - j]) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
/*
* Print debugging info unless output is going directly
* to a terminal.
@ -851,7 +851,7 @@ test_transpose(size_t nx, size_t ny)
for (j = 0; j < ny; j++) {
if (src[i * ny + j] != dst[j * nx + i]) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
AT();
printf(" diff at i=%lu, j=%lu\n",
(unsigned long)i, (unsigned long)j);
@ -948,7 +948,7 @@ test_sub_super(size_t nx, size_t ny)
for (j = 0; j < ny; j++) {
if (full[4 * i * ny + 2 * j] != half[i * ny + j]) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
AT();
printf(" full[%lu][%lu] != half[%lu][%lu]\n",
(unsigned long)i*2,
@ -1025,7 +1025,7 @@ test_sub_super(size_t nx, size_t ny)
}
if (s[0]) {
puts("*FAILED*");
if (!isatty(1)) {
if (!HDisatty(1)) {
AT();
printf(" %s\n Half is:\n", s);
print_array(half, nx, ny, (size_t)1);
@ -1409,7 +1409,7 @@ main(int argc, char *argv[])
if (nerrors) {
printf("***** %d HYPERSLAB TEST%s FAILED! *****\n",
nerrors, 1 == nerrors ? "" : "S");
if (isatty(1)) {
if (HDisatty(1)) {
printf("(Redirect output to a pager or a file to see "
"debug output)\n");
}

View File

@ -4184,7 +4184,7 @@ main(int argc, const char *argv[])
char * ns;
char *indx;
ns = strdup(xmlnsprefix);
ns = HDstrdup(xmlnsprefix);
indx = strrchr(ns,(int)':');
if (indx) *indx = '\0';

View File

@ -85,7 +85,7 @@ parse_command_line (int argc, const char *argv[])
switch ((char) opt)
{
case 'c':
nbytes = strdup (opt_arg);
nbytes = HDstrdup (opt_arg);
break;
case '?':
default:
@ -126,7 +126,7 @@ main (int argc, const char *argv[])
usage (progname);
exit (EXIT_FAILURE);
}
filename = strdup (argv[opt_ind]);
filename = HDstrdup (argv[opt_ind]);
size = 0;
res = sscanf (nbytes, "%u", &size);
@ -148,7 +148,7 @@ main (int argc, const char *argv[])
buf = malloc ((unsigned)(size + 1));
if (buf == NULL)
{
close (fd);
HDclose (fd);
exit (EXIT_FAILURE);
}
@ -158,7 +158,7 @@ main (int argc, const char *argv[])
{
if (buf)
free (buf);
close (fd);
HDclose (fd);
exit (EXIT_FAILURE);
}
@ -166,6 +166,6 @@ main (int argc, const char *argv[])
if (buf)
free (buf);
close (fd);
HDclose (fd);
return (EXIT_SUCCESS);
}

View File

@ -119,13 +119,13 @@ parse_command_line (int argc, const char *argv[])
switch ((char) opt)
{
case 'o':
output_file = strdup (opt_arg);
output_file = HDstrdup (opt_arg);
break;
case 'i':
input_file = strdup (opt_arg);
input_file = HDstrdup (opt_arg);
break;
case 'u':
ub_file = strdup (opt_arg);
ub_file = HDstrdup (opt_arg);
break;
case 'c':
do_clobber = TRUE;
@ -342,9 +342,9 @@ main (int argc, const char *argv[])
where = write_pad (ofid, where);
close (ufid);
close (h5fid);
close (ofid);
HDclose (ufid);
HDclose (h5fid);
HDclose (ofid);
return d_status;
}

View File

@ -321,7 +321,7 @@ gent_ub(const char * filename, size_t ub_size, size_t ub_fill)
HDwrite(fd, buf, ub_size);
close(fd);
HDclose(fd);
}
}
@ -349,7 +349,7 @@ create_textfile(const char *name, size_t size)
HDwrite(fd, buf, size);
close(fd);
HDclose(fd);
}
#ifdef notdef
@ -375,7 +375,7 @@ create_binfile(char *name, off_t size)
HDwrite(fd,buf,size);
close(fd);
HDclose(fd);
}
#endif

View File

@ -112,13 +112,13 @@ parse_command_line(int argc, const char *argv[])
while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
switch ((char)opt) {
case 'o':
output_file = strdup (opt_arg);
output_file = HDstrdup (opt_arg);
break;
case 'i':
input_file = strdup (opt_arg);
input_file = HDstrdup (opt_arg);
break;
case 'u':
ub_file = strdup (opt_arg);
ub_file = HDstrdup (opt_arg);
break;
case 'd':
do_delete = TRUE;
@ -239,7 +239,7 @@ main(int argc, const char *argv[])
if (ub_file == NULL) {
/* write to sdtout */
ufid = dup(1);
ufid = HDdup(1);
} else {
ufid = HDopen(ub_file,O_WRONLY|O_CREAT|O_TRUNC, 0644 );
@ -277,9 +277,9 @@ main(int argc, const char *argv[])
copy_to_file( ifid, h5fid, (ssize_t) usize, (ssize_t)(fsize - (ssize_t)usize) );
close(ufid);
close(h5fid);
close(ifid);
HDclose(ufid);
HDclose(h5fid);
HDclose(ifid);
return d_status;
}

View File

@ -148,7 +148,7 @@ main (int argc, const char *argv[])
return (EXIT_FAILURE);
}
ifname = strdup (argv[opt_ind]);
ifname = HDstrdup (argv[opt_ind]);
testval = H5Fis_hdf5 (ifname);

View File

@ -184,7 +184,7 @@ int main(void)
H5Tclose(cmp3);
H5Pclose(plist);
H5Fclose(fil);
unlink(fname);
HDunlink(fname);
fflush(stdout);
return result;
}

View File

@ -320,7 +320,7 @@ main (int argc, char *argv[])
need_write = FALSE;
} else if (src_offset<src_act_size) {
n = (size_t)MIN ((off_t)n, src_act_size-src_offset);
if ((nio=read (src, buf, n))<0) {
if ((nio=HDread (src, buf, n))<0) {
perror ("read");
exit (1);
} else if ((size_t)nio!=n) {
@ -347,7 +347,7 @@ main (int argc, char *argv[])
perror ("HDlseek");
exit (1);
}
if ((nio=write (dst, buf, n))<0) {
if ((nio=HDwrite (dst, buf, n))<0) {
perror ("write");
exit (1);
} else if ((size_t)nio!=n) {
@ -369,7 +369,7 @@ main (int argc, char *argv[])
*/
src_offset += n;
if (src_offset==src_act_size) {
close (src);
HDclose (src);
if (!src_is_family) {
dst_offset += n;
break;
@ -407,7 +407,7 @@ main (int argc, char *argv[])
perror ("HDHDlseek");
exit (1);
}
if (read (dst, buf, 1)<0) {
if (HDread (dst, buf, 1)<0) {
perror ("read");
exit (1);
}
@ -415,12 +415,12 @@ main (int argc, char *argv[])
perror ("HDlseek");
exit (1);
}
if (write (dst, buf, 1)<0) {
if (HDwrite (dst, buf, 1)<0) {
perror ("write");
exit (1);
}
}
close (dst);
HDclose (dst);
sprintf (dst_name, dst_gen_name, ++dst_membno);
if ((dst=HDopen (dst_name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) {
perror (dst_name);
@ -442,7 +442,7 @@ main (int argc, char *argv[])
perror ("HDlseek");
exit (1);
}
if (read (dst, buf, 1)<0) {
if (HDread (dst, buf, 1)<0) {
perror ("read");
exit (1);
}
@ -450,12 +450,12 @@ main (int argc, char *argv[])
perror ("HDlseek");
exit (1);
}
if (write (dst, buf, 1)<0) {
if (HDwrite (dst, buf, 1)<0) {
perror ("write");
exit (1);
}
}
close (dst);
HDclose (dst);
/* Modify family driver information saved in superblock through private property.
* These private properties are for this tool only. */

View File

@ -6,6 +6,6 @@
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
/>
</VisualStudioPropertySheet>