fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / libf2c / libI77 / backspace.c
blobc31e71147b50b02579cab5a6505e1afbd38025d4
1 #include "config.h"
2 #include <sys/types.h>
3 #include "f2c.h"
4 #include "fio.h"
5 integer
6 f_back (alist * a)
8 unit *b;
9 off_t v, w, x, y, z;
10 uiolen n;
11 FILE *f;
13 f__curunit = b = &f__units[a->aunit]; /* curunit for error messages */
14 if (f__init & 2)
15 f__fatal (131, "I/O recursion");
16 if (a->aunit >= MXUNIT || a->aunit < 0)
17 err (a->aerr, 101, "backspace");
18 if (b->useek == 0)
19 err (a->aerr, 106, "backspace");
20 if (b->ufd == NULL)
22 fk_open (1, 1, a->aunit);
23 return (0);
25 if (b->uend == 1)
27 b->uend = 0;
28 return (0);
30 if (b->uwrt)
32 t_runc (a);
33 if (f__nowreading (b))
34 err (a->aerr, errno, "backspace");
36 f = b->ufd; /* may have changed in t_runc() */
37 if (b->url > 0)
39 x = FTELL (f);
40 y = x % b->url;
41 if (y == 0)
42 x--;
43 x /= b->url;
44 x *= b->url;
45 FSEEK (f, x, SEEK_SET);
46 return (0);
49 if (b->ufmt == 0)
51 FSEEK (f, -(off_t) sizeof (uiolen), SEEK_CUR);
52 fread ((char *) &n, sizeof (uiolen), 1, f);
53 FSEEK (f, -(off_t) n - 2 * sizeof (uiolen), SEEK_CUR);
54 return (0);
56 w = x = FTELL (f);
57 z = 0;
58 loop:
59 while (x)
61 x -= x < 64 ? x : 64;
62 FSEEK (f, x, SEEK_SET);
63 for (y = x; y < w; y++)
65 if (getc (f) != '\n')
66 continue;
67 v = FTELL (f);
68 if (v == w)
70 if (z)
71 goto break2;
72 goto loop;
74 z = v;
76 err (a->aerr, (EOF), "backspace");
78 break2:
79 FSEEK (f, z, SEEK_SET);
80 return 0;