summaryrefslogtreecommitdiff
path: root/usr.sbin/bind/lib/isc/win32/ntfile.c
blob: 3ab2ff2baaf7b2fbc2fd9d23624b96d2cc893481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (C) 2001  Internet Software Consortium.
 *
 * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 * INTERNET SOFTWARE CONSORTIUM 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.
 */

/* $ISC: ntfile.c,v 1.5 2001/07/16 04:09:45 gson Exp $ */

/*
 * This file has been necessitated by the fact that the iov array is local
 * to the module, so passing the FILE ptr to a file I/O function in a
 * different module or DLL will cause the application to fail to find the
 * I/O channel and the application will terminate. The standard file I/O
 * functions are redefined to call these routines instead and there will
 * be just the one iov to deal with.
 */

#include <config.h>

#include <io.h>

#include <isc/ntfile.h>

FILE *
isc_ntfile_fopen(const char *filename, const char *mode) {
	return (fopen(filename, mode));
}

int 
isc_ntfile_fclose(FILE *f) {
	return (fclose(f));
}

int 
isc_ntfile_fseek(FILE *f, long offset, int whence) {
	return (fseek(f, offset, whence));
}

size_t 
isc_ntfile_fread(void *ptr, size_t size, size_t nmemb, FILE *f) {
	return (fread(ptr, size, nmemb, f));
}

size_t 
isc_ntfile_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *f) {
	int r;
	r = fwrite(ptr, size, nmemb, f);
	fflush(f);
	return (r);
}

int 
isc_ntfile_flush(FILE *f) {
	return (fflush(f));
}

int 
isc_ntfile_sync(FILE *f) {
	return (_commit(_fileno(f)));
}

FILE * 
isc_ntfile_getaddress(int r) {
	return (&_iob[r]);
}

int 
isc_ntfile_printf(const char *format, ...) {
	int r;
	FILE *fp = stdout;
	va_list ap;
	va_start(ap, format);
	r = vfprintf(fp, format, ap);
	va_end(ap);
	fflush(fp);
	return (r);
}

int 
isc_ntfile_fprintf(FILE *fp, const char *format, ...) {
	int r;
	va_list ap;
	va_start(ap, format);
	r = vfprintf(fp, format, ap);
	va_end(ap);
	fflush(fp);
	return (r);
}

int 
isc_ntfile_vfprintf(FILE *fp, const char *format, va_list alist) {
	int r;
	r = vfprintf(fp, format, alist);
	fflush(fp);
	return (r);
}

int
isc_ntfile_fputc(int iv, FILE *fp) {
	int r;
	r = fputc(iv, fp);
	fflush(fp);
	return (r);
}

int
isc_ntfile_fputs(const char *bf, FILE *fp) {
	int r;
	r = fputs(bf, fp);
	fflush(fp);
	return (r);
}

int
isc_ntfile_fgetc(FILE *fp) {
	return (fgetc(fp));
}

int
isc_ntfile_fgetpos(FILE *fp, fpos_t *pos) {
	return (fgetpos(fp, pos));
}

char * 
isc_ntfile_fgets(char *ch, int r, FILE *fp) {
	return (fgets(ch,r, fp));
}

int
isc_ntfile_getc(FILE *fp) {
	return (getc(fp));
}

FILE *
isc_ntfile_freopen(const char *path, const char *mode, FILE *fp) {
	return (freopen(path, mode,fp));
}

FILE *
isc_ntfile_fdopen(int handle, const char *mode) {
	return (fdopen(handle, mode));
}

/*
 * open(), close(), read(), write(), fsync()
 * sockets are file descriptors in UNIX.  This is not so in NT
 * We keep track of what is a socket and what is an FD to
 * make everything flow right.
 */
int 
isc_ntfile_open(const char *fn, int flags, ...){
	va_list args;
	int pmode;
	int fd;

 	/* Extract the cmd parameter */
	va_start(args, flags);
	pmode = va_arg(args, int);
	fd = _open(fn, flags, pmode);
	return fd;
}

int
isc_ntfile_close(int fd){
	return (_close(fd));
}

int 
isc_ntfile_read(int fd, char *buf, int len) {
	return (_read(fd, buf, len));
}

int
isc_ntfile_write(int fd, char *buf, int len){
	int r;
	r = _write(fd, buf, len);
	_commit(fd);
	return (r);
}