2 * Copyright (C) 2004, 2007, 2011-2013 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
25 #include <isc/stdio.h>
29 #include "errno2result.h"
32 isc_stdio_open(const char *filename, const char *mode, FILE **fp) {
35 f = fopen(filename, mode);
37 return (isc__errno2result(errno));
39 return (ISC_R_SUCCESS);
43 isc_stdio_close(FILE *f) {
48 return (ISC_R_SUCCESS);
50 return (isc__errno2result(errno));
54 isc_stdio_seek(FILE *f, off_t offset, int whence) {
57 r = fseeko(f, offset, whence);
59 return (ISC_R_SUCCESS);
61 return (isc__errno2result(errno));
65 isc_stdio_tell(FILE *f, off_t *offsetp) {
68 REQUIRE(offsetp != NULL);
73 return (ISC_R_SUCCESS);
75 return (isc__errno2result(errno));
79 isc_stdio_read(void *ptr, size_t size, size_t nmemb, FILE *f, size_t *nret) {
80 isc_result_t result = ISC_R_SUCCESS;
84 r = fread(ptr, size, nmemb, f);
89 result = isc__errno2result(errno);
97 isc_stdio_write(const void *ptr, size_t size, size_t nmemb, FILE *f,
100 isc_result_t result = ISC_R_SUCCESS;
104 r = fwrite(ptr, size, nmemb, f);
106 result = isc__errno2result(errno);
113 isc_stdio_flush(FILE *f) {
118 return (ISC_R_SUCCESS);
120 return (isc__errno2result(errno));
124 * OpenBSD has deprecated ENOTSUP in favor of EOPNOTSUPP.
126 #if defined(EOPNOTSUPP) && !defined(ENOTSUP)
127 #define ENOTSUP EOPNOTSUPP
131 isc_stdio_sync(FILE *f) {
134 r = fsync(fileno(f));
136 * fsync is not supported on sockets and pipes which
137 * result in EINVAL / ENOTSUP.
139 if (r == 0 || errno == EINVAL || errno == ENOTSUP)
140 return (ISC_R_SUCCESS);
142 return (isc__errno2result(errno));