File: fileio.h

package info (click to toggle)
gopher 2.3-2
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,364 kB
  • ctags: 2,030
  • sloc: ansic: 22,451; perl: 1,950; sh: 1,510; makefile: 397; asm: 1
file content (185 lines) | stat: -rw-r--r-- 5,023 bytes parent folder | download | duplicates (2)
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
/********************************************************************
 * $Author: lindner $
 * $Revision: 3.16 $
 * $Date: 1996/01/04 18:25:00 $
 * $Source: /home/arcwelder/GopherSrc/CVS/gopher+/object/fileio.h,v $
 * $State: Exp $
 *
 * Paul Lindner, University of Minnesota CIS.
 *
 * Copyright 1991, 92, 93, 94 by the Regents of the University of Minnesota
 * see the file "Copyright" in the distribution for conditions of use.
 *********************************************************************
 * MODULE: fileio.h
 * Abstration of socket/file input output routines.
 *********************************************************************
 * Revision History:
 * $Log: fileio.h,v $
 * Revision 3.16  1996/01/04  18:25:00  lindner
 * Updates for autoconf
 *
 * Revision 3.15  1995/09/25  22:07:24  lindner
 * Ansification
 *
 * Revision 3.14  1995/04/15  06:51:18  lindner
 * Use interruptable_read
 *
 * Revision 3.13  1995/02/06  22:12:52  lindner
 * Smaller max for fileio structs
 *
 * Revision 3.12  1994/10/18  21:39:06  lindner
 * NeXT doesn't have mmap
 *
 * Revision 3.11  1994/09/29  19:54:24  lindner
 * Add definition for Memory mapped I/O
 *
 * Revision 3.10  1994/08/19  16:29:37  lindner
 * Add definition for memory mapped I/O
 *
 * Revision 3.9  1994/07/21  17:30:44  lindner
 * Mods for Xenix
 *
 * Revision 3.8  1994/04/25  03:40:07  lindner
 * VMS socket stuff still wasn't working..
 *
 * Revision 3.7  1994/04/22  06:42:02  lindner
 * better compatibility checking
 *
 * Revision 3.6  1994/04/13  04:28:23  lindner
 * add vms compatible.h
 *
 * Revision 3.5  1994/04/01  04:43:55  lindner
 * fixes for VMS includes
 *
 * Revision 3.4  1994/03/17  04:36:32  lindner
 * Fix for UCX
 *
 * Revision 3.3  1994/03/11  00:09:14  lindner
 * Fix for UCX
 *
 * Revision 3.2  1994/03/08  03:21:18  lindner
 * Mods for opening processes without sh
 *
 * Revision 3.1  1994/02/20  16:20:50  lindner
 * New object based versions of buffered io routines
 *
 *
 *********************************************************************/

#ifndef FILEIO_H
#define FILEIO_H

#include "STRstring.h"
#include "boolean.h"
#include "Stdlib.h"

#ifdef VMS
#  include <processes.h>
#  include <unixio.h>
#  include <file.h>
#else
#  ifdef M_XENIX
#    include <sys/stream.h>
#    include <sys/fcntl.h>
#    include <sys/ptem.h>
#  else
#    include <fcntl.h>
#  endif
#endif /* VMS */
#include "compatible.h"

struct fileio_struct 
{
     int     bufindex;
     int     bufdatasize;
     int     bytepos;
     char    *buf;

     boolean issocket;
     
     String  *filename;
     int     fd;
     pid_t   pid;
};

typedef struct fileio_struct FileIO;


#define FIOBUFSIZE   4096
#define FIOMAXOFILES 64

#define FIOisSocket(a)      ((a)->issocket)
#define FIOgetPid(a)        ((a)->pid)
#define FIOgetfd(a)         ((a)->fd)
#define FIOgetFilename(a)   (STRget((a)->filename))
#define FIOgetBufIndex(a)   ((a)->bufindex)
#define FIOgetBufDsize(a)   ((a)->bufdatasize)


#define FIOsetfd(a,b)       ((a)->fd=(b))
#define FIOsetPid(a,b)      ((a)->pid=(b))
#define FIOsetSocket(a,b)   ((a)->issocket=(b))
#define FIOsetFilename(a,b) (STRset((a)->filename,(b)))
#define FIOsetBufIndex(a,b) ((a)->bufindex = (b))
#define FIOsetBufDsize(a,b) ((a)->bufdatasize = (b))

#define FIOisMMAPable(a)    (FIOgetFilename(a) != NULL)

/*
 * Optionally use BSD memory mapped I/O
 */

#if defined(HAVE_MMAP)
#  define MMAP_IO
#endif

/*
 * More elegant way of doing socket writes than ifdefs everywhere
 */

#if defined(VMS)
    int DCLsystem(/* char */);
#   define system(a) DCLsystem(a)

    /**  Note that Multinet already has socket_*  **/
#   if defined(WOLLONGONG) || defined(CMUIP) || defined(NETLIB)
#       define socket_write netwrite
#       define socket_read  netread
#       define socket_close netclose
#   endif
#   if defined(UCX)
#       define socket_write write
#       define socket_read  read
#       define socket_close close
#   endif
    /**  Note that Wollongong is like Multinet for EPIPE handling  **/
#   if defined(UCX) || defined(CMUIP) || defined(NETLIB)
#       define FIO_NOMULTIEOF
#   endif

#else
    /* Unix systems */
#   define socket_write write
#   define socket_read  interruptable_read
#   define socket_close close
#endif


/** Forward Declarations **/

FileIO *FIOopenUFS(char *fname, int flags, int mode);
FileIO *FIOopenfd(int fd, int issocket);
FileIO *FIOopenProcess(char *prog, char **args, char   *rw);
FileIO *FIOopenCmdline(char *cmd, char *rw);
int     FIOclose(FileIO *fio);
int     FIOwriten(FileIO *fio, char *ptr, int nbytes);
int     FIOwritestring(FileIO *, char *);
int     FIOreadbuf(FileIO *fio, char *newbuf, int newbuflen);
int     FIOreadn(FileIO *fio, char   *ptr, int nbytes);
int     FIOreadline(FileIO *fio, char *ptr, int maxlen);
int     FIOreadlinezap(FileIO *fio, char *ptr, int maxlen);
int     FIOreadtoken(FileIO *fio, char *ptr, int maxlen, char zechar);
int     FIOwaitpid(FileIO *fio);
int     FIOsystem(char *cmd);
void    FIOdestroy(FileIO *fio);
#endif