| 1 | #include <sys/types.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <errno.h>
|
|---|
| 4 | #ifndef NULL
|
|---|
| 5 | /* ANSI C */
|
|---|
| 6 | #include <stddef.h>
|
|---|
| 7 | #endif
|
|---|
| 8 | #ifdef STDC_HEADERS
|
|---|
| 9 | #include <string.h>
|
|---|
| 10 | #endif
|
|---|
| 11 |
|
|---|
| 12 | #ifndef SEEK_SET
|
|---|
| 13 | #define SEEK_SET 0
|
|---|
| 14 | #define SEEK_CUR 1
|
|---|
| 15 | #define SEEK_END 2
|
|---|
| 16 | #endif
|
|---|
| 17 |
|
|---|
| 18 | /* Only use fseeko/ftello if they are both there. */
|
|---|
| 19 |
|
|---|
| 20 | #if defined (HAVE_FSEEKO) && defined (HAVE_FTELLO)
|
|---|
| 21 | #define FSEEK fseeko
|
|---|
| 22 | #define FTELL ftello
|
|---|
| 23 | #else
|
|---|
| 24 | #define FSEEK fseek
|
|---|
| 25 | #define FTELL ftell
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | #if defined (MSDOS) && !defined (GO32)
|
|---|
| 29 | #ifndef NON_UNIX_STDIO
|
|---|
| 30 | #define NON_UNIX_STDIO
|
|---|
| 31 | #endif
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | #ifdef UIOLEN_int
|
|---|
| 35 | typedef int uiolen;
|
|---|
| 36 | #else
|
|---|
| 37 | typedef long uiolen;
|
|---|
| 38 | #endif
|
|---|
| 39 |
|
|---|
| 40 | /*units*/
|
|---|
| 41 | typedef struct
|
|---|
| 42 | { FILE *ufd; /*0=unconnected*/
|
|---|
| 43 | char *ufnm;
|
|---|
| 44 | #if !(defined (MSDOS) && !defined (GO32))
|
|---|
| 45 | long uinode;
|
|---|
| 46 | int udev;
|
|---|
| 47 | #endif
|
|---|
| 48 | int url; /*0=sequential*/
|
|---|
| 49 | flag useek; /*true=can backspace, use dir, ...*/
|
|---|
| 50 | flag ufmt;
|
|---|
| 51 | flag urw; /* (1 for can read) | (2 for can write) */
|
|---|
| 52 | flag ublnk;
|
|---|
| 53 | flag uend;
|
|---|
| 54 | flag uwrt; /*last io was write*/
|
|---|
| 55 | flag uscrtch;
|
|---|
| 56 | } unit;
|
|---|
| 57 |
|
|---|
| 58 | extern int f__init;
|
|---|
| 59 | extern cilist *f__elist; /*active external io list*/
|
|---|
| 60 | extern flag f__reading,f__external,f__sequential,f__formatted;
|
|---|
| 61 | #undef Void
|
|---|
| 62 | #ifdef KR_headers
|
|---|
| 63 | #define Void /*void*/
|
|---|
| 64 | extern int (*f__getn)(); /* for formatted input */
|
|---|
| 65 | extern void (*f__putn)(); /* for formatted output */
|
|---|
| 66 | extern void x_putc();
|
|---|
| 67 | extern long f__inode();
|
|---|
| 68 | extern VOID sig_die();
|
|---|
| 69 | extern int (*f__donewrec)(), t_putc(), x_wSL();
|
|---|
| 70 | extern int c_sfe(), err__fl(), xrd_SL(), f__putbuf();
|
|---|
| 71 | #else
|
|---|
| 72 | #define Void void
|
|---|
| 73 | #ifdef __cplusplus
|
|---|
| 74 | extern "C" {
|
|---|
| 75 | #endif
|
|---|
| 76 | extern int (*f__getn)(void); /* for formatted input */
|
|---|
| 77 | extern void (*f__putn)(int); /* for formatted output */
|
|---|
| 78 | extern void x_putc(int);
|
|---|
| 79 | extern long f__inode(char*,int*);
|
|---|
| 80 | extern void sig_die(char*,int);
|
|---|
| 81 | extern void f__fatal(int,char*);
|
|---|
| 82 | extern int t_runc(alist*);
|
|---|
| 83 | extern int f__nowreading(unit*), f__nowwriting(unit*);
|
|---|
| 84 | extern int fk_open(int,int,ftnint);
|
|---|
| 85 | extern int en_fio(void);
|
|---|
| 86 | extern void f_init(void);
|
|---|
| 87 | extern int (*f__donewrec)(void), t_putc(int), x_wSL(void);
|
|---|
| 88 | extern void b_char(char*,char*,ftnlen), g_char(char*,ftnlen,char*);
|
|---|
| 89 | extern int c_sfe(cilist*), z_rnew(void);
|
|---|
| 90 | extern int isatty(int);
|
|---|
| 91 | extern int err__fl(int,int,char*);
|
|---|
| 92 | extern int xrd_SL(void);
|
|---|
| 93 | extern int f__putbuf(int);
|
|---|
| 94 | #ifdef __cplusplus
|
|---|
| 95 | }
|
|---|
| 96 | #endif
|
|---|
| 97 | #endif
|
|---|
| 98 | extern int (*f__doend)(Void);
|
|---|
| 99 | extern FILE *f__cf; /*current file*/
|
|---|
| 100 | extern unit *f__curunit; /*current unit*/
|
|---|
| 101 | extern unit f__units[];
|
|---|
| 102 | #define err(f,m,s) do {if(f) {f__init &= ~2; errno= m;} else f__fatal(m,s); return(m);} while(0)
|
|---|
| 103 | #define errfl(f,m,s) do {return err__fl((int)f,m,s);} while(0)
|
|---|
| 104 |
|
|---|
| 105 | /*Table sizes*/
|
|---|
| 106 | #define MXUNIT 100
|
|---|
| 107 |
|
|---|
| 108 | extern int f__recpos; /*position in current record*/
|
|---|
| 109 | extern int f__cursor; /* offset to move to */
|
|---|
| 110 | extern int f__hiwater; /* so TL doesn't confuse us */
|
|---|
| 111 |
|
|---|
| 112 | #define WRITE 1
|
|---|
| 113 | #define READ 2
|
|---|
| 114 | #define SEQ 3
|
|---|
| 115 | #define DIR 4
|
|---|
| 116 | #define FMT 5
|
|---|
| 117 | #define UNF 6
|
|---|
| 118 | #define EXT 7
|
|---|
| 119 | #define INT 8
|
|---|
| 120 |
|
|---|
| 121 | #define buf_end(x) (x->_flag & _IONBF ? x->_ptr : x->_base + BUFSIZ)
|
|---|