1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/FCLOSE.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,94 @@
1.4 +/* FCLOSE.C
1.5 + *
1.6 + * Portions Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies).
1.7 + * All rights reserved.
1.8 + */
1.9 +
1.10 +/*
1.11 +FUNCTION
1.12 +<<fclose>>---close a file
1.13 +
1.14 +INDEX
1.15 + fclose
1.16 +
1.17 +ANSI_SYNOPSIS
1.18 + #include <stdio.h>
1.19 + int fclose(FILE *<[fp]>);
1.20 +
1.21 +TRAD_SYNOPSIS
1.22 + #include <stdio.h>
1.23 + int fclose(<[fp]>)
1.24 + FILE *<[fp]>;
1.25 +
1.26 +DESCRIPTION
1.27 +If the file or stream identified by <[fp]> is open, <<fclose>> closes
1.28 +it, after first ensuring that any pending data is written (by calling
1.29 +<<fflush(<[fp]>)>>).
1.30 +
1.31 +RETURNS
1.32 +<<fclose>> returns <<0>> if successful (including when <[fp]> is
1.33 +<<NULL>> or not an open file); otherwise, it returns <<EOF>>.
1.34 +
1.35 +PORTABILITY
1.36 +<<fclose>> is required by ANSI C.
1.37 +
1.38 +Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
1.39 +<<read>>, <<sbrk>>, <<write>>.
1.40 + */
1.41 +
1.42 +/*
1.43 + * Copyright (c) 1990 The Regents of the University of California.
1.44 + * All rights reserved.
1.45 + *
1.46 + * Redistribution and use in source and binary forms are permitted
1.47 + * provided that the above copyright notice and this paragraph are
1.48 + * duplicated in all such forms and that any documentation,
1.49 + * advertising materials, and other materials related to such
1.50 + * distribution and use acknowledge that the software was developed
1.51 + * by the University of California, Berkeley. The name of the
1.52 + * University may not be used to endorse or promote products derived
1.53 + * from this software without specific prior written permission.
1.54 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1.55 + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1.56 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1.57 + */
1.58 +
1.59 +#include <stdio_r.h>
1.60 +#include <stdlib_r.h>
1.61 +#include "LOCAL.H"
1.62 +
1.63 +/*
1.64 + * Close a file.
1.65 + */
1.66 +
1.67 +/**
1.68 +Close a stream.
1.69 +Close the file associated with the specified stream
1.70 +after flushing all buffers associated with it.
1.71 +@return If the stream is successfully closed 0 is returned.
1.72 +If any error EOF is returned.
1.73 +@param fp Pointer to FILE structure specifying the stream to be closed.
1.74 +*/
1.75 +EXPORT_C int fclose (FILE * fp)
1.76 +{
1.77 + int r;
1.78 +
1.79 + if (fp == NULL)
1.80 + return (0); /* on NULL */
1.81 +
1.82 + CHECK_INIT (fp);
1.83 +
1.84 + if (fp->_flags == 0) /* not open! */
1.85 + return (0);
1.86 + r = fp->_flags & __SWR ? fflush (fp) : 0;
1.87 + if (fp->_close != NULL && (*fp->_close) (fp->_cookie) < 0)
1.88 + r = EOF;
1.89 + if (fp->_flags & __SMBF)
1.90 + _free_r (fp->_data, (char *) fp->_bf._base);
1.91 + if (HASUB (fp))
1.92 + FREEUB (fp);
1.93 + if (HASLB (fp))
1.94 + FREELB (fp);
1.95 + fp->_flags = 0; /* release this FILE for reuse */
1.96 + return (r);
1.97 +}