source: trunk/athena/bin/discuss/libds/tfile.c @ 12459

Revision 12459, 2.6 KB checked in by danw, 26 years ago (diff)
comment out text after #else and #endif
Line 
1/*
2 *
3 *      Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology
4 *      Developed by the MIT Student Information Processing Board (SIPB).
5 *      For copying information, see the file mit-copyright.h in this release.
6 *
7 */
8/*
9 *
10 *      $Id: tfile.c,v 1.7 1999-02-08 14:47:12 danw Exp $
11 *
12 * tfile.c -- a new implementation of tfile's.
13 *
14 *
15 */
16#ifndef lint
17static char rcsid_tfile_c[] =
18    "$Id: tfile.c,v 1.7 1999-02-08 14:47:12 danw Exp $";
19#endif /* lint */
20
21#include <stdio.h>
22#include <errno.h>
23#include <discuss/tfile.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26
27#define min(A, B) ((A) < (B) ? (A) : (B))
28#define NIL 0
29#define SUCCESS 1
30
31extern char *malloc ();
32extern int errno;
33
34tfile tcreate (tfs, infop, info, proc)
35int tfs;
36char *infop;
37int info;
38int (*proc)();
39{
40     tfile tf;
41
42     tf = (tfile) malloc (sizeof (struct _tfile));
43     if (tf ==  NIL)
44          return (NIL);
45
46     tf -> proc = proc;
47     tf -> size = tfs;
48     tf -> info = info;
49     tf -> infop = infop;
50
51     return (tf);
52}
53
54/*
55 *
56 * tfsize (tf)  -- return size of a file.
57 *
58 */
59int tfsize (tf)
60tfile tf;
61{
62     return (tf -> size);
63}
64
65topen(tf,mode,result)
66tfile tf;
67char *mode;
68int *result;
69{
70     if (tf == NIL || tf -> proc == NIL) {
71          *result = EINVAL;
72          return (-1);
73     }
74
75     return ((*(tf -> proc)) (TFOPEN, &(tf -> infop), &(tf -> info), mode, 0, result));
76
77}
78
79tclose(tf,result)
80tfile tf;
81int *result;
82{
83     if (tf == NIL || tf -> proc == NIL) {
84          *result = EINVAL;
85          return (-1);
86     }
87
88     return ((*(tf -> proc)) (TFCLOSE, &(tf -> infop), &(tf -> info), 0, 0, result));
89}
90
91int tread(tf,bufp,wanted,result)
92tfile tf;
93char *bufp;
94int wanted;
95int *result;
96{
97     if (tf == NIL || tf -> proc == NIL) {
98          *result = EINVAL;
99          return (-1);
100     }
101
102     return ((*(tf -> proc)) (TFREAD, &(tf -> infop), &(tf -> info), bufp, wanted,result));
103}
104
105int twrite(tf,bufp,wanted,result)
106tfile tf;
107char *bufp;
108int wanted;
109int *result;
110{
111     if (tf == NIL || tf -> proc == NIL) {
112          *result = EINVAL;
113          return (-1);
114     }
115
116     return ((*(tf -> proc)) (TFWRITE, &(tf -> infop), &(tf -> info), bufp, wanted, result));
117}
118
119int tcontrol(tf,op,cinfop,result)
120tfile tf;
121int op;
122char *cinfop;
123int *result;
124{
125     if (tf == NIL || tf -> proc == NIL) {
126          *result = EINVAL;
127          return (-1);
128     }
129
130     return ((*(tf -> proc)) (TFCONTROL, &(tf -> infop), &(tf -> info), cinfop, op, result));
131}
132
133int tdestroy (tf)
134tfile tf;
135{
136     int dummy;
137
138     if (tf == NIL) {
139          return (-1);
140     }
141
142     if (tf -> proc != NIL)
143          (void) (*(tf -> proc)) (TFDESTROY, &(tf -> infop), &(tf -> info), 0, 0, &dummy);
144     tf -> proc = NIL;
145     free (tf);
146
147     return(0);
148}
Note: See TracBrowser for help on using the repository browser.