Mercurial > ecos
annotate packages/language/c/libc/current/src/stdio/common/fclose.cxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 //=========================================================================== |
| 2 // | |
| 3 // fclose.cxx | |
| 4 // | |
| 5 // Implementation of C library file close function as per ANSI 7.9.5.1 | |
| 6 // | |
| 7 //=========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //=========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): jlarmour |
| 35 // Contributors: jlarmour | |
| 36 // Date: 1999-01-21 | |
| 37 // Purpose: Implements ISO C fclose() function | |
| 0 | 38 // Description: |
| 39 // Usage: | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 43 //=========================================================================== | |
| 44 | |
| 45 // CONFIGURATION | |
| 46 | |
| 47 #include <pkgconf/libc.h> // Configuration header | |
| 48 | |
| 49 | |
| 2 | 50 // Do we want the stdio stuff? And we can't have fclose() without fopen() |
| 51 #if defined(CYGPKG_LIBC_STDIO) && defined(CYGPKG_LIBC_STDIO_OPEN) | |
| 0 | 52 |
| 53 // INCLUDES | |
| 54 | |
| 55 #include <cyg/infra/cyg_type.h> // Common project-wide type definitions | |
| 56 #include <stddef.h> // NULL and size_t from compiler | |
| 57 #include <errno.h> // Error codes | |
| 58 #include <stdio.h> // header for fclose() | |
| 59 #include "clibincl/stdlibsupp.hxx" // _free() | |
| 2 | 60 #include "clibincl/stdiofiles.hxx" // C library files |
| 0 | 61 #include "clibincl/stream.hxx" // C libray streams |
| 62 #include "clibincl/stdiosupp.hxx" // support for stdio | |
| 63 | |
| 64 | |
| 65 // EXPORTED SYMBOLS | |
| 66 | |
| 67 externC int | |
| 2 | 68 fclose( FILE * ) CYGBLD_ATTRIB_WEAK_ALIAS(_fclose); |
| 0 | 69 |
| 70 | |
| 71 // FUNCTIONS | |
| 72 | |
| 73 | |
| 74 externC int | |
| 75 _fclose( FILE *stream ) | |
| 76 { | |
| 77 Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream; | |
| 78 int i; | |
| 79 | |
| 2 | 80 Cyg_libc_stdio_files::lock(); |
| 0 | 81 |
| 82 // find the stream in the table | |
| 83 for (i=0; i < FOPEN_MAX; i++) | |
| 84 { | |
| 2 | 85 if (real_stream == Cyg_libc_stdio_files::get_file_stream(i)) |
| 0 | 86 break; |
| 87 } // for | |
| 88 | |
| 89 if (i == FOPEN_MAX) // didn't find it | |
| 90 { | |
| 91 errno = EBADF; | |
| 92 | |
| 93 return EOF; | |
| 94 } // if | |
| 2 | 95 |
| 96 // FIXME: should use delete? | |
| 0 | 97 // Explicitly call destructor - this flushes the output too |
| 98 real_stream->~Cyg_StdioStream(); | |
| 99 | |
| 100 // and free it | |
| 101 _free(real_stream); | |
| 102 | |
| 103 // and mark the stream available for use | |
| 2 | 104 Cyg_libc_stdio_files::set_file_stream(i, NULL); |
| 0 | 105 |
| 2 | 106 Cyg_libc_stdio_files::unlock(); |
| 0 | 107 |
| 108 return 0; | |
| 109 | |
| 110 } // _fclose() | |
| 111 | |
| 2 | 112 #endif // if defined(CYGPKG_LIBC_STDIO) && defined(CYGPKG_LIBC_STDIO_OPEN) |
| 0 | 113 |
| 114 // EOF fclose.cxx |
