Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pcc / dist / pcc-libs / libI77 / close.c
blob8bdedd72b6aabeb413951c4f74c3403016c3f289
1 /* $Id: close.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 <stdlib.h>
36 #include <unistd.h>
38 #include "fio.h"
40 int
41 f_clos(cllist *a)
42 { unit *b;
43 if(a->cunit >= MXUNIT) return(0);
44 b= &units[a->cunit];
45 if(b->ufd==NULL) return(0);
46 b->uend=0;
47 if(a->csta!=0)
48 switch(*a->csta)
50 default:
51 keep:
52 case 'k':
53 if(b->uwrt) t_runc(b);
54 fclose(b->ufd);
55 if(b->ufnm!=0) free(b->ufnm);
56 b->ufnm=NULL;
57 b->ufd=NULL;
58 return(0);
59 case 'd':
60 delete:
61 fclose(b->ufd);
62 if(b->ufnm!=0)
63 { unlink(b->ufnm); /*SYSDEP*/
64 free(b->ufnm);
66 b->ufnm=NULL;
67 b->ufd=NULL;
68 return(0);
70 else if(b->uscrtch==1) goto delete;
71 else goto keep;
74 void
75 f_exit()
76 { int i;
77 cllist xx;
78 xx.cerr=1;
79 xx.csta=NULL;
80 for(i=0;i<MXUNIT;i++)
82 xx.cunit=i;
83 f_clos(&xx);
87 void
88 flush_()
89 { int i;
90 for(i=0;i<MXUNIT;i++)
91 if(units[i].ufd != NULL) fflush(units[i].ufd);