Mercurial > flash_v2
annotate packages/language/c/libc/current/src/stdio/common/fflush.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 // fflush.cxx | |
| 4 // | |
| 5 // Implementation of C library file flush function as per ANSI 7.9.5.2 | |
| 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: Provides ISO C fflush() function | |
| 0 | 38 // Description: |
| 39 // Usage: | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 43 //======================================================================== | |
| 44 | |
| 45 // CONFIGURATION | |
| 46 | |
| 47 #include <pkgconf/libc.h> // Configuration header | |
| 48 | |
| 2 | 49 // Do we want the stdio stuff? |
| 50 #ifdef CYGPKG_LIBC_STDIO | |
| 0 | 51 |
| 52 // INCLUDES | |
| 53 | |
| 54 #include <cyg/infra/cyg_type.h> // Common project-wide type definitions | |
| 55 #include <stddef.h> // NULL and size_t from compiler | |
| 56 #include <errno.h> // Error codes | |
| 57 #include <stdio.h> // header for fflush() | |
| 58 #include "clibincl/stream.hxx" // C library streams | |
| 2 | 59 #include "clibincl/stdiofiles.hxx" // C library files |
| 0 | 60 #include "clibincl/stdiosupp.hxx" // support for stdio |
| 61 | |
| 62 | |
| 63 // EXPORTED SYMBOLS | |
| 64 | |
| 65 externC int | |
| 2 | 66 fflush( FILE * ) CYGBLD_ATTRIB_WEAK_ALIAS(_fflush); |
| 0 | 67 |
| 68 | |
| 69 // FUNCTIONS | |
| 70 | |
| 2 | 71 // flush all but one stream |
| 72 externC Cyg_ErrNo | |
| 73 cyg_libc_stdio_flush_all_but( Cyg_StdioStream *not_this_stream ) | |
| 74 { | |
| 75 cyg_bool files_flushed[FOPEN_MAX] = { false }; // sets all to 0 | |
| 76 cyg_bool loop_again; | |
| 77 cyg_ucount32 i; | |
| 78 Cyg_ErrNo err=ENOERR; | |
| 79 Cyg_StdioStream *stream; | |
| 80 | |
| 81 do { | |
| 82 loop_again = false; | |
| 83 | |
| 84 for (i=0; (i<FOPEN_MAX) && !err; i++) { | |
| 85 if (files_flushed[i] == false) { | |
| 86 | |
| 87 stream = Cyg_libc_stdio_files::get_file_stream(i); | |
| 88 | |
| 89 if ((stream == NULL) || (stream == not_this_stream)) { | |
| 90 // if it isn't a valid stream, set its entry in the | |
| 91 // list of files flushed since we don't want to | |
| 92 // flush it | |
| 93 // Ditto if its the one we're meant to miss | |
| 94 | |
| 95 files_flushed[i] = true; | |
| 96 } // if | |
| 97 else { | |
| 98 // valid stream | |
| 99 | |
| 100 if ( stream->trylock_me() ) { | |
| 101 err = stream->flush_output_unlocked(); | |
| 102 stream->unlock_me(); | |
| 103 files_flushed[i] = true; | |
| 104 } // if | |
| 105 else | |
| 106 loop_again = true; | |
| 107 } // else | |
| 108 } // if | |
| 109 } // for | |
| 110 } // do | |
| 111 while(loop_again && !err); | |
| 112 | |
| 113 return err; | |
| 114 } // cyg_libc_stdio_flush_all_but() | |
| 0 | 115 |
| 116 externC int | |
| 117 _fflush( FILE *stream ) | |
| 118 { | |
| 119 Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream; | |
| 2 | 120 Cyg_ErrNo err; |
| 0 | 121 |
| 122 if (stream == NULL) { // tells us to flush ALL streams | |
| 2 | 123 err = cyg_libc_stdio_flush_all_but(NULL); |
| 0 | 124 } // if |
| 125 else { | |
| 126 err = real_stream->flush_output(); | |
| 127 } // else | |
| 128 | |
| 129 if (err) { | |
| 130 errno = err; | |
| 131 return EOF; | |
| 132 } // if | |
| 133 | |
| 134 return 0; | |
| 135 | |
| 136 } // _fflush() | |
| 137 | |
| 2 | 138 #endif // ifdef CYGPKG_LIBC_STDIO |
| 0 | 139 |
| 140 // EOF fflush.cxx |
