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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <config.h>
include <fio.h>
.help nullfile
.nf ___________________________________________________________________________
NULLFILE -- Text and binary file drivers for the nullfile, "dev$null".
These special drivers behave like regular text or binary drivers but
have the special property that no i/o occurs, i.e., all output is discarded,
making it appear as if the write was successful, and EOF is returned for
all attempts to read from the file.
.endhelp ______________________________________________________________________
define MAX_NULLFILES (LAST_FD-FIRST_FD+1)
define SZ_DEFINBUF 1 # buffer size when reading
define SZ_DEFOUTBUF 2048 # buffer size when writing
define NU_INUSE 01B
define NU_READ 02B
define NU_WRITE 04B
# ZOPNNU -- Open a nullfile. Used for both binary and text nullfiles.
procedure zopnnu (osfn, mode, chan)
char osfn[ARB] # osfn version of dev$null, presumably
int mode # not used
int chan # assigned channel (output)
bool first_time
int nu
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
data first_time /true/
begin
# First time initialization.
if (first_time) {
do nu = 1, MAX_NULLFILES
flags[nu] = 0
first_time = false
}
# Find open slot.
for (nu=1; nu <= MAX_NULLFILES; nu=nu+1)
if (flags[nu] == 0)
break
if (nu > MAX_NULLFILES) {
chan = ERR
return
}
switch (mode) {
case READ_ONLY:
flags[nu] = NU_INUSE + NU_READ
case READ_WRITE:
flags[nu] = NU_INUSE + NU_READ + NU_WRITE
default:
flags[nu] = NU_INUSE + NU_WRITE
}
count[nu] = 0
chan = nu
end
# ZCLSNU -- Close a null file. Used for both text and binary null files.
procedure zclsnu (chan, status)
int chan
int status
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
if (flags[chan] == 0)
status = ERR
else {
flags[chan] = 0
status = OK
}
end
# ZSTTNU -- Status of a null file. Used for both text and binary null files.
procedure zsttnu (chan, param, lvalue)
int chan
int param
long lvalue
int and()
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
switch (param) {
case FSTT_BLKSIZE:
lvalue = 0
case FSTT_FILSIZE:
lvalue = 0
case FSTT_OPTBUFSIZE, FSTT_MAXBUFSIZE:
if (and (flags[chan], NU_WRITE) != 0)
lvalue = SZ_DEFOUTBUF
else
lvalue = SZ_DEFINBUF
}
end
# ZARDNU, ZAWRNU, ZAWTNU -- Binary file i/o to the null file.
procedure zardnu (chan, buf, maxbytes, loffset)
int chan, maxbytes
char buf[ARB]
long loffset
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
count[chan] = 0
end
procedure zawrnu (chan, buf, nbytes, loffset)
int chan, nbytes
char buf[ARB]
long loffset
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
count[chan] = nbytes
end
procedure zawtnu (chan, status)
int chan, status
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
if (flags[chan] != 0)
status = count[chan]
else
status = ERR
end
# ZGETNU, ZPUTNU, ZFLSNU, ZSEKNU, ZNOTNU -- Text file i/o to the null file.
procedure zgetnu (chan, buf, maxch, status)
int chan, maxch, status
char buf[ARB]
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
if (flags[chan] != 0)
status = 0
else
status = ERR
end
procedure zputnu (chan, buf, nchars, status)
int chan, nchars, status
char buf[ARB]
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
if (flags[chan] != 0)
status = nchars
else
status = ERR
end
procedure zflsnu (chan, status)
int chan
int status
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
if (flags[chan] != 0)
status = OK
else
status = ERR
end
procedure zseknu (chan, loffset, status)
int chan, status
long loffset
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
if (flags[chan] != 0)
status = OK
else
status = ERR
end
procedure znotnu (chan, loffset)
int chan
long loffset
int flags[MAX_NULLFILES]
int count[MAX_NULLFILES]
common /znucom/ flags, count
begin
if (flags[chan] != 0)
loffset = 0
else
loffset = ERR
end
|