Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / lib / isc / win32 / stdio.c
blob25ec423f0962f238cec3186265f5e0e7d7dba734
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2007 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.
20 /* Id: stdio.c,v 1.6 2007/06/19 23:47:19 tbox Exp */
22 #include <config.h>
24 #include <io.h>
25 #include <errno.h>
27 #include <isc/stdio.h>
29 #include "errno2result.h"
31 isc_result_t
32 isc_stdio_open(const char *filename, const char *mode, FILE **fp) {
33 FILE *f;
35 f = fopen(filename, mode);
36 if (f == NULL)
37 return (isc__errno2result(errno));
38 *fp = f;
39 return (ISC_R_SUCCESS);
42 isc_result_t
43 isc_stdio_close(FILE *f) {
44 int r;
46 r = fclose(f);
47 if (r == 0)
48 return (ISC_R_SUCCESS);
49 else
50 return (isc__errno2result(errno));
53 isc_result_t
54 isc_stdio_seek(FILE *f, long offset, int whence) {
55 int r;
57 r = fseek(f, offset, whence);
58 if (r == 0)
59 return (ISC_R_SUCCESS);
60 else
61 return (isc__errno2result(errno));
64 isc_result_t
65 isc_stdio_read(void *ptr, size_t size, size_t nmemb, FILE *f, size_t *nret) {
66 isc_result_t result = ISC_R_SUCCESS;
67 size_t r;
69 clearerr(f);
70 r = fread(ptr, size, nmemb, f);
71 if (r != nmemb) {
72 if (feof(f))
73 result = ISC_R_EOF;
74 else
75 result = isc__errno2result(errno);
77 if (nret != NULL)
78 *nret = r;
79 return (result);
82 isc_result_t
83 isc_stdio_write(const void *ptr, size_t size, size_t nmemb, FILE *f,
84 size_t *nret)
86 isc_result_t result = ISC_R_SUCCESS;
87 size_t r;
89 clearerr(f);
90 r = fwrite(ptr, size, nmemb, f);
91 if (r != nmemb)
92 result = isc__errno2result(errno);
93 if (nret != NULL)
94 *nret = r;
95 return (result);
98 isc_result_t
99 isc_stdio_flush(FILE *f) {
100 int r;
102 r = fflush(f);
103 if (r == 0)
104 return (ISC_R_SUCCESS);
105 else
106 return (isc__errno2result(errno));
109 isc_result_t
110 isc_stdio_sync(FILE *f) {
111 int r;
113 r = _commit(_fileno(f));
114 if (r == 0)
115 return (ISC_R_SUCCESS);
116 else
117 return (isc__errno2result(errno));