1 /* $NetBSD: stdio.c,v 1.7 2015/07/08 17:29:00 christos Exp $ */
4 * Copyright (C) 2004, 2007, 2011-2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
27 #include <isc/stdio.h>
31 #include "errno2result.h"
34 isc_stdio_open(const char *filename
, const char *mode
, FILE **fp
) {
37 f
= fopen(filename
, mode
);
39 return (isc__errno2result(errno
));
41 return (ISC_R_SUCCESS
);
45 isc_stdio_close(FILE *f
) {
50 return (ISC_R_SUCCESS
);
52 return (isc__errno2result(errno
));
56 isc_stdio_seek(FILE *f
, off_t offset
, int whence
) {
60 r
= fseeko(f
, offset
, whence
);
62 r
= fseek(f
, offset
, whence
);
65 return (ISC_R_SUCCESS
);
67 return (isc__errno2result(errno
));
71 isc_stdio_tell(FILE *f
, off_t
*offsetp
) {
74 REQUIRE(offsetp
!= NULL
);
83 return (ISC_R_SUCCESS
);
85 return (isc__errno2result(errno
));
89 isc_stdio_read(void *ptr
, size_t size
, size_t nmemb
, FILE *f
, size_t *nret
) {
90 isc_result_t result
= ISC_R_SUCCESS
;
94 r
= fread(ptr
, size
, nmemb
, f
);
99 result
= isc__errno2result(errno
);
107 isc_stdio_write(const void *ptr
, size_t size
, size_t nmemb
, FILE *f
,
110 isc_result_t result
= ISC_R_SUCCESS
;
114 r
= fwrite(ptr
, size
, nmemb
, f
);
116 result
= isc__errno2result(errno
);
123 isc_stdio_flush(FILE *f
) {
128 return (ISC_R_SUCCESS
);
130 return (isc__errno2result(errno
));
134 * OpenBSD has deprecated ENOTSUP in favor of EOPNOTSUPP.
136 #if defined(EOPNOTSUPP) && !defined(ENOTSUP)
137 #define ENOTSUP EOPNOTSUPP
141 isc_stdio_sync(FILE *f
) {
144 r
= fsync(fileno(f
));
146 * fsync is not supported on sockets and pipes which
147 * result in EINVAL / ENOTSUP.
149 if (r
== 0 || errno
== EINVAL
|| errno
== ENOTSUP
)
150 return (ISC_R_SUCCESS
);
152 return (isc__errno2result(errno
));