ReactOS 0.4.16-dev-122-g325d74c
flag.c
Go to the documentation of this file.
1/* @(#)flag.c 2.14 10/11/06 Copyright 1986-2010 J. Schilling */
2/*
3 * Copyright (c) 1986-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#include <schily/stdlib.h>
19
20#ifdef DO_MYFLAG
21
22#define FL_INIT 10
23
24#if defined(IS_MACOS_X)
25/*
26 * The MAC OS X linker does not grok "common" varaibles.
27 * Make _io_glflag a "data" variable.
28 */
29EXPORT int _io_glflag = 0; /* global default flag */
30#else
31EXPORT int _io_glflag; /* global default flag */
32#endif
33LOCAL int _fl_inc = 10; /* increment to expand flag struct */
34EXPORT int _fl_max = FL_INIT; /* max fd currently in _io_myfl */
35LOCAL _io_fl _io_smyfl[FL_INIT]; /* initial static space */
36EXPORT _io_fl *_io_myfl = _io_smyfl; /* init to static space */
37
39
40LOCAL int
42 FILE *fp;
43{
44 register int f = fileno(fp);
45 register int n = _fl_max;
46 register _io_fl *np;
47
48 while (n <= f)
49 n += _fl_inc;
50
51 if (_io_myfl == _io_smyfl) {
52 np = (_io_fl *) malloc(n * sizeof (*np));
53 fillbytes(np, n * sizeof (*np), '\0');
54 movebytes(_io_smyfl, np, sizeof (_io_smyfl)/sizeof (*np));
55 } else {
56 np = (_io_fl *) realloc(_io_myfl, n * sizeof (*np));
57 if (np)
58 fillbytes(&np[_fl_max], (n-_fl_max)*sizeof (*np), '\0');
59 }
60 if (np) {
61 _io_myfl = np;
62 _fl_max = n;
63 return (_io_get_my_flag(fp));
64 } else {
65 return (_JS_IONORAISE);
66 }
67}
68
69EXPORT int
71 register FILE *fp;
72{
73 register int f = fileno(fp);
74 register _io_fl *fl;
75
76 if (f >= _fl_max)
77 return (_more_flags(fp));
78
79 fl = &_io_myfl[f];
80
81 if (fl->fl_io == 0 || fl->fl_io == fp)
82 return (fl->fl_flags);
83
84 while (fl && fl->fl_io != fp)
85 fl = fl->fl_next;
86
87 if (fl == 0)
88 return (0);
89
90 return (fl->fl_flags);
91}
92
93EXPORT void
95 FILE *fp;
96 int flag;
97{
98 register int f = fileno(fp);
99 register _io_fl *fl;
100 register _io_fl *fl2;
101
102 if (f >= _fl_max)
103 (void) _more_flags(fp);
104
105 fl = &_io_myfl[f];
106
107 if (fl->fl_io != (FILE *)0) {
108 fl2 = fl;
109
110 while (fl && fl->fl_io != fp)
111 fl = fl->fl_next;
112 if (fl == 0) {
113 if ((fl = (_io_fl *) malloc(sizeof (*fl))) == 0)
114 return;
115 fl->fl_next = fl2->fl_next;
116 fl2->fl_next = fl;
117 }
118 }
119 fl->fl_io = fp;
120 fl->fl_flags = flag;
121}
122
123EXPORT void
125 FILE *fp;
126 int flag;
127{
128 int oflag = _io_get_my_flag(fp);
129
130 oflag |= flag;
131
132 _io_set_my_flag(fp, oflag);
133}
134
135#endif /* DO_MYFLAG */
#define fileno
Definition: acwin.h:102
#define realloc
Definition: debug_ros.c:6
#define malloc
Definition: debug_ros.c:4
EXPORT char * fillbytes(void *tov, ssize_t cnt, char val)
Definition: fillbytes.c:36
LOCAL int _fl_inc
Definition: flag.c:33
LOCAL int _more_flags(FILE *fp)
Definition: flag.c:41
EXPORT int _fl_max
Definition: flag.c:34
LOCAL _io_fl _io_smyfl[FL_INIT]
Definition: flag.c:35
EXPORT void _io_add_my_flag(FILE *fp, int flag)
Definition: flag.c:124
EXPORT void _io_set_my_flag(FILE *fp, int flag)
Definition: flag.c:94
#define FL_INIT
Definition: flag.c:22
EXPORT int _io_glflag
Definition: flag.c:31
EXPORT int _io_get_my_flag(FILE *fp)
Definition: flag.c:70
EXPORT _io_fl * _io_myfl
Definition: flag.c:36
GLdouble n
Definition: glext.h:7729
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
#define LOCAL(type)
Definition: jmorecfg.h:289
#define f
Definition: ke_i.h:83
EXPORT char * movebytes(void *fromv, void *tov, ssize_t cnt) const
Definition: movebytes.c:30
#define __PR(a)
Definition: prototyp.h:106
#define _JS_IONORAISE
Definition: schilyio.h:99
struct _io_flags * fl_next
Definition: schilyio.h:107
_In_ FLONG fl
Definition: winddi.h:1279