sl@0
|
1 |
/* FCLOSE.C
|
sl@0
|
2 |
*
|
sl@0
|
3 |
* Portions Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*/
|
sl@0
|
6 |
|
sl@0
|
7 |
/*
|
sl@0
|
8 |
FUNCTION
|
sl@0
|
9 |
<<fclose>>---close a file
|
sl@0
|
10 |
|
sl@0
|
11 |
INDEX
|
sl@0
|
12 |
fclose
|
sl@0
|
13 |
|
sl@0
|
14 |
ANSI_SYNOPSIS
|
sl@0
|
15 |
#include <stdio.h>
|
sl@0
|
16 |
int fclose(FILE *<[fp]>);
|
sl@0
|
17 |
|
sl@0
|
18 |
TRAD_SYNOPSIS
|
sl@0
|
19 |
#include <stdio.h>
|
sl@0
|
20 |
int fclose(<[fp]>)
|
sl@0
|
21 |
FILE *<[fp]>;
|
sl@0
|
22 |
|
sl@0
|
23 |
DESCRIPTION
|
sl@0
|
24 |
If the file or stream identified by <[fp]> is open, <<fclose>> closes
|
sl@0
|
25 |
it, after first ensuring that any pending data is written (by calling
|
sl@0
|
26 |
<<fflush(<[fp]>)>>).
|
sl@0
|
27 |
|
sl@0
|
28 |
RETURNS
|
sl@0
|
29 |
<<fclose>> returns <<0>> if successful (including when <[fp]> is
|
sl@0
|
30 |
<<NULL>> or not an open file); otherwise, it returns <<EOF>>.
|
sl@0
|
31 |
|
sl@0
|
32 |
PORTABILITY
|
sl@0
|
33 |
<<fclose>> is required by ANSI C.
|
sl@0
|
34 |
|
sl@0
|
35 |
Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
|
sl@0
|
36 |
<<read>>, <<sbrk>>, <<write>>.
|
sl@0
|
37 |
*/
|
sl@0
|
38 |
|
sl@0
|
39 |
/*
|
sl@0
|
40 |
* Copyright (c) 1990 The Regents of the University of California.
|
sl@0
|
41 |
* All rights reserved.
|
sl@0
|
42 |
*
|
sl@0
|
43 |
* Redistribution and use in source and binary forms are permitted
|
sl@0
|
44 |
* provided that the above copyright notice and this paragraph are
|
sl@0
|
45 |
* duplicated in all such forms and that any documentation,
|
sl@0
|
46 |
* advertising materials, and other materials related to such
|
sl@0
|
47 |
* distribution and use acknowledge that the software was developed
|
sl@0
|
48 |
* by the University of California, Berkeley. The name of the
|
sl@0
|
49 |
* University may not be used to endorse or promote products derived
|
sl@0
|
50 |
* from this software without specific prior written permission.
|
sl@0
|
51 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
sl@0
|
52 |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
sl@0
|
53 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
|
sl@0
|
56 |
#include <stdio_r.h>
|
sl@0
|
57 |
#include <stdlib_r.h>
|
sl@0
|
58 |
#include "LOCAL.H"
|
sl@0
|
59 |
|
sl@0
|
60 |
/*
|
sl@0
|
61 |
* Close a file.
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
Close a stream.
|
sl@0
|
66 |
Close the file associated with the specified stream
|
sl@0
|
67 |
after flushing all buffers associated with it.
|
sl@0
|
68 |
@return If the stream is successfully closed 0 is returned.
|
sl@0
|
69 |
If any error EOF is returned.
|
sl@0
|
70 |
@param fp Pointer to FILE structure specifying the stream to be closed.
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
EXPORT_C int fclose (FILE * fp)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
int r;
|
sl@0
|
75 |
|
sl@0
|
76 |
if (fp == NULL)
|
sl@0
|
77 |
return (0); /* on NULL */
|
sl@0
|
78 |
|
sl@0
|
79 |
CHECK_INIT (fp);
|
sl@0
|
80 |
|
sl@0
|
81 |
if (fp->_flags == 0) /* not open! */
|
sl@0
|
82 |
return (0);
|
sl@0
|
83 |
r = fp->_flags & __SWR ? fflush (fp) : 0;
|
sl@0
|
84 |
if (fp->_close != NULL && (*fp->_close) (fp->_cookie) < 0)
|
sl@0
|
85 |
r = EOF;
|
sl@0
|
86 |
if (fp->_flags & __SMBF)
|
sl@0
|
87 |
_free_r (fp->_data, (char *) fp->_bf._base);
|
sl@0
|
88 |
if (HASUB (fp))
|
sl@0
|
89 |
FREEUB (fp);
|
sl@0
|
90 |
if (HASLB (fp))
|
sl@0
|
91 |
FREELB (fp);
|
sl@0
|
92 |
fp->_flags = 0; /* release this FILE for reuse */
|
sl@0
|
93 |
return (r);
|
sl@0
|
94 |
}
|