Commit | Line | Data |
---|---|---|
0d78ca85 | 1 | /*- |
af39f981 KB |
2 | * Copyright (c) 1979, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
0d78ca85 KB |
4 | * |
5 | * %sccs.include.redist.c% | |
6 | */ | |
a58c9769 | 7 | |
0d78ca85 | 8 | #ifndef lint |
af39f981 | 9 | static char sccsid[] = "@(#)RESET.c 8.1 (Berkeley) %G%"; |
0d78ca85 | 10 | #endif /* not lint */ |
a58c9769 KM |
11 | |
12 | #include "h00vars.h" | |
a58c9769 KM |
13 | |
14 | RESET(filep, name, maxnamlen, datasize) | |
15 | ||
16 | register struct iorec *filep; | |
17 | char *name; | |
492cc5d3 KM |
18 | long maxnamlen; |
19 | long datasize; | |
a58c9769 KM |
20 | { |
21 | if (name == NULL && filep == INPUT && filep->fname[0] == '\0') { | |
270a57c8 | 22 | if (fseek(filep->fbuf, (long)0, 0) == -1) { |
86997b19 | 23 | PERROR("Could not reset ", filep->pfname); |
a58c9769 KM |
24 | return; |
25 | } | |
b56aaddc KM |
26 | filep->funit &= ~EOFF; |
27 | filep->funit |= (SYNC | EOLN); | |
a58c9769 KM |
28 | return; |
29 | } | |
30 | filep = GETNAME(filep, name, maxnamlen, datasize); | |
31 | filep->fbuf = fopen(filep->fname, "r"); | |
32 | if (filep->fbuf == NULL) { | |
5f3d789e KM |
33 | /* |
34 | * This allows unnamed temp files to be opened even if | |
35 | * they have not been rewritten yet. We decided to remove | |
36 | * this feature since the standard requires that files be | |
37 | * defined before being reset. | |
38 | * | |
a58c9769 KM |
39 | if (filep->funit & TEMP) { |
40 | filep->funit |= (EOFF | SYNC | FREAD); | |
41 | return; | |
42 | } | |
5f3d789e | 43 | */ |
86997b19 | 44 | PERROR("Could not open ", filep->pfname); |
a58c9769 KM |
45 | return; |
46 | } | |
47 | filep->funit |= (SYNC | FREAD); | |
66cd3f19 KM |
48 | if (filep->funit & FTEXT) |
49 | filep->funit |= EOLN; | |
a58c9769 KM |
50 | if (filep->fblk > PREDEF) { |
51 | setbuf(filep->fbuf, &filep->buf[0]); | |
52 | } | |
53 | } |