Rev 614 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
614 | 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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
||
28 | * DESCRIBE IT HERE! |
||
29 | * |
||
30 | ****************************************************************************/ |
||
31 | |||
32 | |||
33 | #include "variety.h" |
||
34 | #include |
||
35 | #include |
||
36 | #include |
||
37 | #include |
||
38 | #include "iomode.h" |
||
39 | #include "fileacc.h" |
||
40 | #include "rtcheck.h" |
||
41 | #include "rtdata.h" |
||
42 | #include "seterrno.h" |
||
43 | #include "lseek.h" |
||
727 | serge | 44 | #include "kolibri.h" |
614 | serge | 45 | |
46 | typedef struct |
||
47 | { |
||
48 | char *name; |
||
49 | unsigned int offset; |
||
50 | }__file_handle; |
||
51 | |||
52 | _WCRTLINK int read( int handle, void *buf, unsigned len ) |
||
53 | { |
||
54 | unsigned read_len, total_len; |
||
55 | unsigned reduce_idx, finish_idx; |
||
56 | unsigned iomode_flags; |
||
57 | char *buffer = buf; |
||
58 | BOOL rc; |
||
59 | HANDLE h; |
||
60 | unsigned amount_read; |
||
727 | serge | 61 | int err; |
62 | |||
614 | serge | 63 | __file_handle *fh; |
64 | |||
727 | serge | 65 | |
614 | serge | 66 | __handle_check( handle, -1 ); |
67 | __ChkTTYIOMode( handle ); |
||
68 | iomode_flags = __GetIOMode( handle ); |
||
69 | if( iomode_flags == 0 ) |
||
70 | { |
||
71 | __set_errno( EBADF ); |
||
72 | return( -1 ); |
||
73 | } |
||
74 | if( !(iomode_flags & _READ) ) |
||
75 | { |
||
76 | __set_errno( EACCES ); /* changed from EBADF to EACCES 23-feb-89 */ |
||
77 | return( -1 ); |
||
78 | } |
||
79 | |||
80 | |||
81 | fh = (__file_handle*) __getOSHandle( handle ); |
||
82 | |||
83 | if( iomode_flags & _BINARY ) /* if binary mode */ |
||
84 | { |
||
85 | |||
727 | serge | 86 | err=read_file(fh->name,buffer,fh->offset,len,&amount_read); |
87 | fh->offset+=amount_read; |
||
88 | total_len = amount_read; |
||
89 | |||
90 | if(err) |
||
614 | serge | 91 | if ( amount_read == 0) |
92 | return (-1); |
||
727 | serge | 93 | |
614 | serge | 94 | } |
95 | else |
||
96 | { |
||
97 | total_len = 0; |
||
98 | read_len = len; |
||
99 | do |
||
100 | { |
||
727 | serge | 101 | err=read_file(fh->name,buffer,fh->offset,len,&amount_read); |
102 | fh->offset+=amount_read; |
||
103 | |||
104 | if( amount_read == 0 ) |
||
105 | break; /* EOF */ |
||
106 | |||
614 | serge | 107 | reduce_idx = 0; |
108 | finish_idx = reduce_idx; |
||
109 | for( ; reduce_idx < amount_read; ++reduce_idx ) |
||
110 | { |
||
111 | if( buffer[ reduce_idx ] == 0x1a ) /* EOF */ |
||
112 | { |
||
113 | __lseek( handle, |
||
114 | ((long)reduce_idx - (long)amount_read)+1L, |
||
115 | SEEK_CUR ); |
||
116 | total_len += finish_idx; |
||
117 | return( total_len ); |
||
118 | } |
||
119 | if( buffer[ reduce_idx ] != '\r' ) |
||
120 | { |
||
121 | buffer[ finish_idx++ ] = buffer[ reduce_idx ]; |
||
122 | }; |
||
123 | } |
||
124 | |||
125 | total_len += finish_idx; |
||
126 | buffer += finish_idx; |
||
127 | read_len -= finish_idx; |
||
128 | if( iomode_flags & _ISTTY ) |
||
129 | { |
||
130 | break; /* 04-feb-88, FWC */ |
||
131 | } |
||
132 | } while( read_len != 0 ); |
||
133 | } |
||
134 | return( total_len ); |
||
135 | }> |
||
136 |