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

Revision 22404, 2.6 KB checked in by ghudson, 19 years ago (diff)
Eliminate declarations of system functions which cause warnings or errors. Fix some broken ss library calls.
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.8 2006-03-10 07:11:38 ghudson 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.8 2006-03-10 07:11:38 ghudson Exp $";
19#endif /* lint */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <errno.h>
24#include <discuss/tfile.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27
28#define min(A, B) ((A) < (B) ? (A) : (B))
29#define NIL 0
30#define SUCCESS 1
31
32tfile tcreate (tfs, infop, info, proc)
33int tfs;
34char *infop;
35int info;
36int (*proc)();
37{
38     tfile tf;
39
40     tf = (tfile) malloc (sizeof (struct _tfile));
41     if (tf ==  NIL)
42          return (NIL);
43
44     tf -> proc = proc;
45     tf -> size = tfs;
46     tf -> info = info;
47     tf -> infop = infop;
48
49     return (tf);
50}
51
52/*
53 *
54 * tfsize (tf)  -- return size of a file.
55 *
56 */
57int tfsize (tf)
58tfile tf;
59{
60     return (tf -> size);
61}
62
63topen(tf,mode,result)
64tfile tf;
65char *mode;
66int *result;
67{
68     if (tf == NIL || tf -> proc == NIL) {
69          *result = EINVAL;
70          return (-1);
71     }
72
73     return ((*(tf -> proc)) (TFOPEN, &(tf -> infop), &(tf -> info), mode, 0, result));
74
75}
76
77tclose(tf,result)
78tfile tf;
79int *result;
80{
81     if (tf == NIL || tf -> proc == NIL) {
82          *result = EINVAL;
83          return (-1);
84     }
85
86     return ((*(tf -> proc)) (TFCLOSE, &(tf -> infop), &(tf -> info), 0, 0, result));
87}
88
89int tread(tf,bufp,wanted,result)
90tfile tf;
91char *bufp;
92int wanted;
93int *result;
94{
95     if (tf == NIL || tf -> proc == NIL) {
96          *result = EINVAL;
97          return (-1);
98     }
99
100     return ((*(tf -> proc)) (TFREAD, &(tf -> infop), &(tf -> info), bufp, wanted,result));
101}
102
103int twrite(tf,bufp,wanted,result)
104tfile tf;
105char *bufp;
106int wanted;
107int *result;
108{
109     if (tf == NIL || tf -> proc == NIL) {
110          *result = EINVAL;
111          return (-1);
112     }
113
114     return ((*(tf -> proc)) (TFWRITE, &(tf -> infop), &(tf -> info), bufp, wanted, result));
115}
116
117int tcontrol(tf,op,cinfop,result)
118tfile tf;
119int op;
120char *cinfop;
121int *result;
122{
123     if (tf == NIL || tf -> proc == NIL) {
124          *result = EINVAL;
125          return (-1);
126     }
127
128     return ((*(tf -> proc)) (TFCONTROL, &(tf -> infop), &(tf -> info), cinfop, op, result));
129}
130
131int tdestroy (tf)
132tfile tf;
133{
134     int dummy;
135
136     if (tf == NIL) {
137          return (-1);
138     }
139
140     if (tf -> proc != NIL)
141          (void) (*(tf -> proc)) (TFDESTROY, &(tf -> infop), &(tf -> info), 0, 0, &dummy);
142     tf -> proc = NIL;
143     free (tf);
144
145     return(0);
146}
Note: See TracBrowser for help on using the repository browser.