Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
359 | serge | 1 | /**************************************************************************** |
2 | * |
||
3 | * Open Watcom Project |
||
4 | * |
||
5 | * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
||
6 | * |
||
7 | * ======================================================================== |
||
8 | * |
||
9 | * This file contains Original Code and/or Modifications of Original |
||
10 | * Code as defined in and that are subject to the Sybase Open Watcom |
||
11 | * Public License version 1.0 (the 'License'). You may not use this file |
||
12 | * except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
||
13 | * ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
||
14 | * provided with the Original Code and Modifications, and is also |
||
15 | * available at www.sybase.com/developer/opensource. |
||
16 | * |
||
17 | * The Original Code and all software distributed under the License are |
||
18 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||
19 | * EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
||
20 | * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
||
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
||
22 | * NON-INFRINGEMENT. Please see the License for the specific language |
||
23 | * governing rights and limitations under the License. |
||
24 | * |
||
25 | * ======================================================================== |
||
26 | * |
||
27 | * Description: Implementation of fflush() helper routine. |
||
28 | * |
||
29 | ****************************************************************************/ |
||
30 | |||
31 | |||
32 | #include "variety.h" |
||
33 | #include |
||
34 | #include |
||
35 | #include |
||
36 | #include |
||
37 | #include "fileacc.h" |
||
38 | #include "rtdata.h" |
||
39 | #include "seterrno.h" |
||
40 | #include "qwrite.h" |
||
41 | #include "lseek.h" |
||
42 | #include "flush.h" |
||
43 | |||
44 | #if defined( __NETWARE__ ) && defined( _THIN_LIB ) |
||
45 | |||
46 | /* Take flush from LibC */ |
||
47 | _WCRTLINK int __flush( FILE *fp ) |
||
48 | { |
||
49 | return( fflush( fp ) ); |
||
50 | } |
||
51 | |||
52 | #else |
||
53 | |||
54 | _WCRTLINK int __flush( FILE *fp ) |
||
55 | { |
||
56 | int len; |
||
57 | long offset; |
||
58 | int ret; |
||
59 | char *ptr; |
||
60 | unsigned amount; |
||
61 | |||
62 | ret = 0; |
||
63 | _AccessFile( fp ); |
||
64 | if( fp->_flag & _DIRTY ) { |
||
65 | fp->_flag &= ~_DIRTY; |
||
66 | if( (fp->_flag & _WRITE) && (_FP_BASE(fp) != NULL) ) { |
||
67 | ptr = _FP_BASE(fp); |
||
68 | amount = fp->_cnt; |
||
69 | while( amount != 0 && ret == 0 ) { |
||
70 | len = __qwrite( fileno( fp ), ptr, amount ); /* 02-aug-90 */ |
||
71 | if( len == -1 ) { |
||
72 | fp->_flag |= _SFERR; |
||
73 | ret = EOF; |
||
74 | } |
||
75 | #ifndef __UNIX__ |
||
76 | else if( len == 0 ) { |
||
77 | __set_errno( ENOSPC ); /* 12-nov-88 */ |
||
78 | fp->_flag |= _SFERR; |
||
79 | ret = EOF; |
||
80 | } |
||
81 | #endif |
||
82 | ptr += len; |
||
83 | amount -= len; |
||
84 | } |
||
85 | } |
||
86 | } else if( _FP_BASE(fp) != NULL ) { /* not dirty */ |
||
87 | /* fseek( fp, ftell(fp), SEEK_SET ); */ |
||
88 | fp->_flag &= ~_EOF; |
||
89 | if( !(fp->_flag & _ISTTY) ) { |
||
90 | offset = fp->_cnt; |
||
91 | if( offset != 0 ) { /* 10-aug-89 JD */ |
||
92 | offset = __lseek( fileno( fp ), -offset, SEEK_CUR ); |
||
93 | } |
||
94 | if( offset == -1 ) { |
||
95 | fp->_flag |= _SFERR; |
||
96 | ret = EOF; |
||
97 | } |
||
98 | } |
||
99 | } |
||
100 | fp->_ptr = _FP_BASE(fp); /* reset ptr to start of buffer */ |
||
101 | fp->_cnt = 0; |
||
102 | #if !defined( __NETWARE__ ) && !defined( __OSI__ ) |
||
103 | if( ret == 0 && (_FP_EXTFLAGS(fp) & _COMMIT) ) { |
||
104 | if( fsync( fileno( fp ) ) == -1 ) { |
||
105 | ret = EOF; |
||
106 | } |
||
107 | } |
||
108 | #endif |
||
109 | _ReleaseFile( fp ); |
||
110 | return( ret ); |
||
111 | } |
||
112 | |||
113 | #endif |