1 /*-
2 * Copyright (c) 2014-2018 MongoDB, Inc.
3 * Copyright (c) 2008-2014 WiredTiger, Inc.
4 * All rights reserved.
5 *
6 * See the file LICENSE for redistribution information.
7 */
8
9 #include "wt_internal.h"
10
11 /*
12 * __stdio_close --
13 * ANSI C close/fclose.
14 */
15 static int
__stdio_close(WT_SESSION_IMPL * session,WT_FSTREAM * fs)16 __stdio_close(WT_SESSION_IMPL *session, WT_FSTREAM *fs)
17 {
18 WT_RET_MSG(session, ENOTSUP, "%s: close", fs->name);
19 }
20
21 /*
22 * __stdio_flush --
23 * POSIX fflush.
24 */
25 static int
__stdio_flush(WT_SESSION_IMPL * session,WT_FSTREAM * fs)26 __stdio_flush(WT_SESSION_IMPL *session, WT_FSTREAM *fs)
27 {
28 if (fflush(fs->fp) == 0)
29 return (0);
30 WT_RET_MSG(session, __wt_errno(), "%s: flush", fs->name);
31 }
32
33 /*
34 * __stdio_getline --
35 * ANSI C getline.
36 */
37 static int
__stdio_getline(WT_SESSION_IMPL * session,WT_FSTREAM * fs,WT_ITEM * buf)38 __stdio_getline(WT_SESSION_IMPL *session, WT_FSTREAM *fs, WT_ITEM *buf)
39 {
40 WT_UNUSED(buf);
41 WT_RET_MSG(session, ENOTSUP, "%s: getline", fs->name);
42 }
43
44 /*
45 * __stdio_printf --
46 * ANSI C vfprintf.
47 */
48 static int
__stdio_printf(WT_SESSION_IMPL * session,WT_FSTREAM * fs,const char * fmt,va_list ap)49 __stdio_printf(
50 WT_SESSION_IMPL *session, WT_FSTREAM *fs, const char *fmt, va_list ap)
51 {
52 if (vfprintf(fs->fp, fmt, ap) >= 0)
53 return (0);
54 WT_RET_MSG(session, EIO, "%s: printf", fs->name);
55 }
56
57 /*
58 * __stdio_init --
59 * Initialize stdio functions.
60 */
61 static void
__stdio_init(WT_FSTREAM * fs,const char * name,FILE * fp)62 __stdio_init(WT_FSTREAM *fs, const char *name, FILE *fp)
63 {
64 fs->name = name;
65 fs->fp = fp;
66
67 fs->close = __stdio_close;
68 fs->fstr_flush = __stdio_flush;
69 fs->fstr_getline = __stdio_getline;
70 fs->fstr_printf = __stdio_printf;
71 }
72
73 /*
74 * __wt_os_stdio --
75 * Initialize the stdio configuration.
76 */
77 void
__wt_os_stdio(WT_SESSION_IMPL * session)78 __wt_os_stdio(WT_SESSION_IMPL *session)
79 {
80 __stdio_init(WT_STDERR(session), "stderr", stderr);
81 __stdio_init(WT_STDOUT(session), "stdout", stdout);
82 }
83