2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-10-15 14:08:26 +00:00
Files
bind/lib/isc/win32/stdio.c
Evan Hunt f42c0dcca8 [master] win32 fixes
3605.	[port]		win32: Addressed several compatibility issues
			with newer versions of Visual Studio. [RT #33916]

Squashed commit of the following:

commit 4127af15f85da90cf2bd3a0c5a558daae89e833a
Author: Francis Dupont <fdupont@isc.org>
Date:   Tue Jun 25 22:41:53 2013 +0200

    make the last change to be text

commit 21ef4891b9ee3e3aefb45d4c80d5cb7ec78f264f
Author: Curtis Blackburn <ckb@isc.org>
Date:   Tue Jun 25 12:35:08 2013 -0500

    [rt33916] re-worded for easier reading

commit 83828e47e62fea4070441e645ba8fed338255ceb
Author: Francis Dupont <fdupont@isc.org>
Date:   Mon Jun 24 16:08:11 2013 +0200

    introduce a VCRedistPath env var

commit 0337f2554f168993a65945e78c2879e9bfca5293
Author: Francis Dupont <fdupont@isc.org>
Date:   Sun Jun 23 01:23:26 2013 +0200

    _adjust_fdiv for VS < 2010

commit 375fdd5c06be276b0ff0ad589c0e22b809339fe9
Author: Francis Dupont <fdupont@isc.org>
Date:   Thu Jun 20 16:27:04 2013 +0200

    move to MSVC v1600 as it still breaks on VS 2010

commit bfcaf72071e9d8df1d0ce0c5f05b69acd51bf698
Author: Francis Dupont <fdupont@isc.org>
Date:   Thu Jun 20 15:57:35 2013 +0200

    WIN32: avoid addrinfo redef

commit 18504c3e50b11e66a0b573c7cb3d61094bfa5b52
Author: Francis Dupont <fdupont@isc.org>
Date:   Thu Jun 20 15:54:38 2013 +0200

    WIN32: fseek/ftell

commit f9a4fdccc5ab1c74c64412fb76da7dfd161787b2
Author: Francis Dupont <fdupont@isc.org>
Date:   Thu Jun 20 15:13:01 2013 +0200

    fix WIN32 error redefs in net.h (isc ad lwres libs)
2013-06-26 14:38:35 -07:00

135 lines
2.8 KiB
C

/*
* Copyright (C) 2004, 2007, 2013 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000, 2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: stdio.c,v 1.6 2007/06/19 23:47:19 tbox Exp $ */
#include <config.h>
#include <io.h>
#include <errno.h>
#include <isc/stdio.h>
#include <isc/util.h>
#include "errno2result.h"
isc_result_t
isc_stdio_open(const char *filename, const char *mode, FILE **fp) {
FILE *f;
f = fopen(filename, mode);
if (f == NULL)
return (isc__errno2result(errno));
*fp = f;
return (ISC_R_SUCCESS);
}
isc_result_t
isc_stdio_close(FILE *f) {
int r;
r = fclose(f);
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}
isc_result_t
isc_stdio_seek(FILE *f, off_t offset, int whence) {
/* based on the fact off_t is typedef to long */
int r;
r = fseek(f, offset, whence);
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}
isc_result_t
isc_stdio_tell(FILE *f, off_t *offsetp) {
/* based on the fact off_t is typedef to long */
long r;
REQUIRE(offsetp != NULL);
r = ftell(f);
if (r >= 0) {
*offsetp = r;
return (ISC_R_SUCCESS);
} else
return (isc__errno2result(errno));
}
isc_result_t
isc_stdio_read(void *ptr, size_t size, size_t nmemb, FILE *f, size_t *nret) {
isc_result_t result = ISC_R_SUCCESS;
size_t r;
clearerr(f);
r = fread(ptr, size, nmemb, f);
if (r != nmemb) {
if (feof(f))
result = ISC_R_EOF;
else
result = isc__errno2result(errno);
}
if (nret != NULL)
*nret = r;
return (result);
}
isc_result_t
isc_stdio_write(const void *ptr, size_t size, size_t nmemb, FILE *f,
size_t *nret)
{
isc_result_t result = ISC_R_SUCCESS;
size_t r;
clearerr(f);
r = fwrite(ptr, size, nmemb, f);
if (r != nmemb)
result = isc__errno2result(errno);
if (nret != NULL)
*nret = r;
return (result);
}
isc_result_t
isc_stdio_flush(FILE *f) {
int r;
r = fflush(f);
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}
isc_result_t
isc_stdio_sync(FILE *f) {
int r;
r = _commit(_fileno(f));
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}