Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pcc / dist / pcc-libs / libI77 / err.c
blob9483a49e283c14a8cbb8fc32f35cf33f123d210c
1 /* $Id: err.c,v 1.1.1.1 2008/08/24 05:34:47 gmcgarry Exp $ */
2 /*
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
17 * International, Inc.
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/types.h>
36 #include <sys/stat.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
42 #include "fio.h"
44 #define STR(x) (x==NULL?"":x)
46 /*global definitions*/
47 unit units[MXUNIT]; /*unit table*/
48 flag init; /*0 on entry, 1 after initializations*/
49 cilist *elist; /*active external io list*/
50 flag reading; /*1 if reading, 0 if writing*/
51 flag cplus,cblank;
52 char *fmtbuf;
53 flag external; /*1 if external io, 0 if internal */
54 int (*doed)(struct syl *p, void *ptr, ftnlen len);
55 int (*doend)(void),(*donewrec)(void),(*dorevert)(void);
56 flag sequential; /*1 if sequential io, 0 if direct*/
57 flag formatted; /*1 if formatted io, 0 if unformatted*/
58 int (*getn)(void),(*putn)(int); /*for formatted io*/
59 FILE *cf; /*current file*/
60 unit *curunit; /*current unit*/
61 int recpos; /*place in current record*/
62 int cursor,scale;
64 int canseek(FILE *f);
66 /*error messages*/
67 char *F_err[] =
69 "error in format",
70 "illegal unit number",
71 "formatted io not allowed",
72 "unformatted io not allowed",
73 "direct io not allowed",
74 "sequential io not allowed",
75 "can't backspace file",
76 "null file name",
77 "can't stat file",
78 "unit not connected",
79 "off end of record",
80 "truncation failed in endfile",
81 "incomprehensible list input",
82 "out of free space",
83 "unit not connected",
84 "read unexpected character",
85 "blank logical input field",
87 #define MAXERR (sizeof(F_err)/sizeof(char *)+100)
89 void
90 fatal(int n, char *s)
92 if(n<100 && n>=0) perror(s); /*SYSDEP*/
93 else if(n>=(int)MAXERR)
94 { fprintf(stderr,"%s: illegal error number %d\n",s,n);
96 else if(n<0) fprintf(stderr,"%s: end of file %d\n",s,n);
97 else
98 fprintf(stderr,"%s: %s\n",s,F_err[n-100]);
99 fprintf(stderr,"apparent state: unit %d named %s\n",curunit-units,
100 STR(curunit->ufnm));
101 fprintf(stderr,"last format: %s\n",STR(fmtbuf));
102 fprintf(stderr,"lately %s %s %s %s IO\n",reading?"reading":"writing",
103 sequential?"sequential":"direct",formatted?"formatted":"unformatted",
104 external?"external":"internal");
105 abort();
108 /*initialization routine*/
109 void
110 f_init()
111 { unit *p;
112 init=1;
113 p= &units[0];
114 p->ufd=stderr;
115 p->useek=canseek(stderr);
116 p->ufmt=1;
117 p->uwrt=1;
118 p = &units[5];
119 p->ufd=stdin;
120 p->useek=canseek(stdin);
121 p->ufmt=1;
122 p->uwrt=0;
123 p= &units[6];
124 p->ufd=stdout;
125 p->useek=canseek(stdout);
126 p->ufmt=1;
127 p->uwrt=1;
131 canseek(FILE *f) /*SYSDEP*/
132 { struct stat x;
133 fstat(fileno(f),&x);
134 if(x.st_nlink > 0 /*pipe*/ && !isatty(fileno(f)))
136 return(1);
138 return(0);
142 nowreading(unit *x)
144 long loc;
145 x->uwrt=0;
146 loc=ftell(x->ufd);
147 freopen(x->ufnm,"r",x->ufd);
148 return fseek(x->ufd,loc,0);
152 nowwriting(x) unit *x;
154 long loc;
155 loc=ftell(x->ufd);
156 x->uwrt=1;
157 freopen(x->ufnm,"a",x->ufd);
158 return fseek(x->ufd,loc,0);