string.h is ANSI C include file
[unix-history] / usr / src / usr.bin / f77 / libI77 / util.c
CommitLineData
3443cb26 1/*
161423a6
RE
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
3443cb26 5 *
161423a6
RE
6 * @(#)util.c 5.1 %G%
7 */
8
9/*
3443cb26
DW
10 * utility routines
11 */
12
3443cb26
DW
13#include "fio.h"
14
fe1e75aa 15extern short ccntrl_, blzero_;
3443cb26 16
3443cb26
DW
17nowreading(x) unit *x;
18{
ff26b80a 19 return(now_acc(x,"r"));
3443cb26
DW
20}
21
22nowwriting(x) unit *x;
ff26b80a
DW
23{
24 return(now_acc(x,"a"));
25}
26
5e52dbf7 27LOCAL now_acc(x,mode)
ff26b80a 28unit *x; char *mode;
3443cb26
DW
29{
30 long loc;
ff26b80a
DW
31
32 if (!x->ufnm)
33 {
34 errno = EBADF;
35 return(NO);
36 }
37 if (x->useek)
38 loc=ftell(x->ufd);
39 if (freopen(x->ufnm,mode,x->ufd))
40 {
41 if (x->useek)
42 fseek(x->ufd,loc,0);
43 x->uwrt = (*mode=='a');
44 return(YES);
45 }
46 if (x->ufd = fopen(x->ufnm, (*mode=='a')? "r":"a"))
47 if (x->useek)
48 fseek(x->ufd,loc,0);
49 return(NO);
3443cb26
DW
50}
51
52g_char(a,alen,b) char *a,*b; ftnlen alen;
53{ char *x=a+alen-1, *y=b+alen-1;
54 while (x >= a && *x == ' ') {x--; y--;}
55 *(y+1) = '\0';
56 while (x >= a) *y-- = *x--;
57}
58
59b_char(from, to, tolen) char *from, *to; ftnlen tolen;
60{ int i=0;
61 while (*from && i < tolen) {
62 *to++ = *from++;
63 i++;
64 }
65 while (i++ < tolen)
66 *to++ = ' ';
67}
68
3443cb26
DW
69char
70last_char(f) FILE *f;
71{
72 fseek(f,-2L,1);
73 if(ftell(f)) return(getc(f));
74 else return('\n');
75}