sl@0: /* FCLOSE.C sl@0: * sl@0: * Portions Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: */ sl@0: sl@0: /* sl@0: FUNCTION sl@0: <>---close a file sl@0: sl@0: INDEX sl@0: fclose sl@0: sl@0: ANSI_SYNOPSIS sl@0: #include sl@0: int fclose(FILE *<[fp]>); sl@0: sl@0: TRAD_SYNOPSIS sl@0: #include sl@0: int fclose(<[fp]>) sl@0: FILE *<[fp]>; sl@0: sl@0: DESCRIPTION sl@0: If the file or stream identified by <[fp]> is open, <> closes sl@0: it, after first ensuring that any pending data is written (by calling sl@0: <)>>). sl@0: sl@0: RETURNS sl@0: <> returns <<0>> if successful (including when <[fp]> is sl@0: <> or not an open file); otherwise, it returns <>. sl@0: sl@0: PORTABILITY sl@0: <> is required by ANSI C. sl@0: sl@0: Required OS subroutines: <>, <>, <>, <>, sl@0: <>, <>, <>. sl@0: */ sl@0: sl@0: /* sl@0: * Copyright (c) 1990 The Regents of the University of California. sl@0: * All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms are permitted sl@0: * provided that the above copyright notice and this paragraph are sl@0: * duplicated in all such forms and that any documentation, sl@0: * advertising materials, and other materials related to such sl@0: * distribution and use acknowledge that the software was developed sl@0: * by the University of California, Berkeley. The name of the sl@0: * University may not be used to endorse or promote products derived sl@0: * from this software without specific prior written permission. sl@0: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR sl@0: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED sl@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include "LOCAL.H" sl@0: sl@0: /* sl@0: * Close a file. sl@0: */ sl@0: sl@0: /** sl@0: Close a stream. sl@0: Close the file associated with the specified stream sl@0: after flushing all buffers associated with it. sl@0: @return If the stream is successfully closed 0 is returned. sl@0: If any error EOF is returned. sl@0: @param fp Pointer to FILE structure specifying the stream to be closed. sl@0: */ sl@0: EXPORT_C int fclose (FILE * fp) sl@0: { sl@0: int r; sl@0: sl@0: if (fp == NULL) sl@0: return (0); /* on NULL */ sl@0: sl@0: CHECK_INIT (fp); sl@0: sl@0: if (fp->_flags == 0) /* not open! */ sl@0: return (0); sl@0: r = fp->_flags & __SWR ? fflush (fp) : 0; sl@0: if (fp->_close != NULL && (*fp->_close) (fp->_cookie) < 0) sl@0: r = EOF; sl@0: if (fp->_flags & __SMBF) sl@0: _free_r (fp->_data, (char *) fp->_bf._base); sl@0: if (HASUB (fp)) sl@0: FREEUB (fp); sl@0: if (HASLB (fp)) sl@0: FREELB (fp); sl@0: fp->_flags = 0; /* release this FILE for reuse */ sl@0: return (r); sl@0: }