ReactOS 0.4.15-dev-7788-g1ad9096
fcons.c
Go to the documentation of this file.
1/* @(#)fcons.c 2.20 10/11/06 Copyright 1986, 1995-2010 J. Schilling */
2/*
3 * Copyright (c) 1986, 1995-2010 J. Schilling
4 */
5/*
6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License, Version 1.0 only
8 * (the "License"). You may not use this file except in compliance
9 * with the License.
10 *
11 * See the file CDDL.Schily.txt in this distribution for details.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file CDDL.Schily.txt from this distribution.
15 */
16
17#include "schilyio.h"
18
19/*
20 * Note that because of a definition in schilyio.h we are using
21 * fseeko()/ftello() instead of fseek()/ftell() if available.
22 */
23
24LOCAL char *fmtab[] = {
25 "", /* 0 FI_NONE */
26 "r", /* 1 FI_READ */
27 "w", /* 2 FI_WRITE **1) */
28 "r+", /* 3 FI_READ | FI_WRITE */
29 "b", /* 4 FI_NONE | FI_BINARY */
30 "rb", /* 5 FI_READ | FI_BINARY */
31 "wb", /* 6 FI_WRITE | FI_BINARY **1) */
32 "r+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
33
34/* + FI_APPEND */ "", /* 0 FI_NONE */
35/* ... */ "r", /* 1 FI_READ */
36 "a", /* 2 FI_WRITE **1) */
37 "a+", /* 3 FI_READ | FI_WRITE */
38 "b", /* 4 FI_NONE | FI_BINARY */
39 "rb", /* 5 FI_READ | FI_BINARY */
40 "ab", /* 6 FI_WRITE | FI_BINARY **1) */
41 "a+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
42 };
43/*
44 * NOTES:
45 * 1) fdopen() guarantees not to create/trunc files in this case
46 *
47 * "w" will create/trunc files with fopen()
48 * "a" will create files with fopen()
49 */
50
51
54 register FILE *fd;
55 int f;
56 int flag;
57{
58 int my_gflag = _io_glflag;
59
60 if (fd == (FILE *)NULL)
61 fd = fdopen(f,
63
64 if (fd != (FILE *)NULL) {
65 if (flag & FI_APPEND) {
66 (void) fseek(fd, (off_t)0, SEEK_END);
67 }
68 if (flag & FI_UNBUF) {
69 setbuf(fd, NULL);
70 my_gflag |= _JS_IOUNBUF;
71 }
72 set_my_flag(fd, my_gflag); /* must clear it if fd is reused */
73 return (fd);
74 }
75 if (flag & FI_CLOSE)
76 close(f);
77
78 return ((FILE *)NULL);
79}
#define close
Definition: acwin.h:98
#define SEEK_END
Definition: cabinet.c:29
#define NULL
Definition: types.h:112
__kernel_off_t off_t
Definition: linux.h:201
EXPORT FILE * _fcons(FILE *fd, int f, int flag)
Definition: fcons.c:53
LOCAL char * fmtab[]
Definition: fcons.c:24
EXPORT int _io_glflag
Definition: flag.c:31
GLfloat f
Definition: glext.h:7540
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
_Check_return_ _CRTIMP FILE *__cdecl fdopen(_In_ int _FileHandle, _In_z_ const char *_Format)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_CRTIMP void __cdecl setbuf(_Inout_ FILE *_File, _Inout_updates_opt_(BUFSIZ) _Post_readable_size_(0) char *_Buffer)
#define LOCAL(type)
Definition: jmorecfg.h:289
#define f
Definition: ke_i.h:83
#define FI_BINARY
Definition: schilyio.h:87
#define _JS_IOUNBUF
Definition: schilyio.h:100
#define FI_APPEND
Definition: schilyio.h:88
#define FI_READ
Definition: schilyio.h:85
#define set_my_flag(p, v)
Definition: schilyio.h:140
#define FI_UNBUF
Definition: schilyio.h:92
#define FI_CLOSE
Definition: schilyio.h:93
#define FI_WRITE
Definition: schilyio.h:86
static int fd
Definition: io.c:51