Rev 4874 | Rev 6536 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | /* read.c -- read bytes from a input device. |
|
- | 2 | * |
|
- | 3 | * Copyright (c) 1995 Cygnus Support |
|
1 | #include |
4 | * |
- | 5 | * The authors hereby grant permission to use, copy, modify, distribute, |
|
- | 6 | * and license this software and its documentation for any purpose, provided |
|
- | 7 | * that existing copyright notices are retained in all copies and that this |
|
- | 8 | * notice is included verbatim in any distributions. No written agreement, |
|
- | 9 | * license, or royalty fee is required for any of the authorized uses. |
|
- | 10 | * Modifications to this software may be copyrighted by their authors |
|
- | 11 | * and need not follow the licensing terms described here, provided that |
|
- | 12 | * the new terms are clearly indicated on the first page of each file where |
|
- | 13 | * they apply. |
|
- | 14 | */ |
|
- | 15 | #include |
|
- | 16 | #include |
|
2 | #include |
17 | #include |
- | 18 | #include |
|
- | 19 | #include |
|
3 | 20 | #include |
|
- | 21 | #include "glue.h" |
|
- | 22 | #include "io.h" |
|
- | 23 | ||
- | 24 | #undef erro |
|
- | 25 | extern int errno; |
|
- | 26 | ||
- | 27 | ssize_t read(int fd, void *buf, size_t cnt) |
|
- | 28 | { |
|
- | 29 | _ssize_t ret; |
|
- | 30 | ||
- | 31 | _ssize_t read_len, total_len; |
|
- | 32 | unsigned reduce_idx, finish_idx; |
|
- | 33 | unsigned iomode_flags; |
|
- | 34 | char *buffer = buf; |
|
- | 35 | int rc; |
|
- | 36 | int h; |
|
- | 37 | unsigned amount_read; |
|
- | 38 | int err; |
|
- | 39 | ||
- | 40 | __io_handle *ioh; |
|
- | 41 | ||
- | 42 | if( (fd < 0) || (fd >=64) ) |
|
- | 43 | { |
|
- | 44 | errno = EBADF; |
|
- | 45 | return -1; |
|
- | 46 | }; |
|
- | 47 | ||
- | 48 | ioh = &__io_tab[fd]; |
|
- | 49 | ||
- | 50 | iomode_flags = ioh->mode; |
|
- | 51 | ||
- | 52 | if( iomode_flags == 0 ) |
|
- | 53 | { |
|
- | 54 | errno = EBADF; |
|
- | 55 | return( -1 ); |
|
- | 56 | } |
|
- | 57 | ||
- | 58 | if( !(iomode_flags & _READ) ) |
|
- | 59 | { |
|
- | 60 | errno = EACCES; |
|
- | 61 | return( -1 ); |
|
- | 62 | } |
|
- | 63 | ||
- | 64 | if( iomode_flags & _BINARY ) /* if binary mode */ |
|
- | 65 | { |
|
- | 66 | err = read_file(ioh->name, buffer, ioh->offset, cnt, &amount_read); |
|
- | 67 | ioh->offset+= amount_read; |
|
- | 68 | total_len = amount_read; |
|
- | 69 | ||
- | 70 | if(err) |
|
- | 71 | if ( amount_read == 0) |
|
- | 72 | return (-1); |
|
- | 73 | } |
|
- | 74 | else |
|
- | 75 | { |
|
- | 76 | total_len = 0; |
|
- | 77 | read_len = cnt; |
|
- | 78 | do |
|
- | 79 | { |
|
- | 80 | err=read_file(ioh->name,buffer, ioh->offset, cnt, &amount_read); |
|
- | 81 | ioh->offset+=amount_read; |
|
- | 82 | ||
- | 83 | if( amount_read == 0 ) |
|
- | 84 | break; /* EOF */ |
|
Line -... | Line 85... | ||
- | 85 | ||
4 | int read_file(const char *path, void *buff, |
86 | reduce_idx = 0; |
5 | size_t offset, size_t count, size_t *reads) |
87 | finish_idx = reduce_idx; |
6 | { |
88 | for( ; reduce_idx < amount_read; ++reduce_idx ) |
7 | int retval; |
- | |
8 | int d0; |
- | |
9 | __asm__ __volatile__( |
- | |
10 | "pushl $0 \n\t" |
- | |
11 | "pushl $0 \n\t" |
- | |
12 | "movl %%eax, 1(%%esp) \n\t" |
89 | { |
13 | "pushl %%ebx \n\t" |
- | |
14 | "pushl %%edx \n\t" |
- | |
15 | "pushl $0 \n\t" |
- | |
16 | "pushl %%ecx \n\t" |
- | |
17 | "pushl $0 \n\t" |
90 | if( buffer[ reduce_idx ] == 0x1a ) /* EOF */ |
18 | "movl %%esp, %%ebx \n\t" |
91 | { |
19 | "mov $70, %%eax \n\t" |
92 | lseek(fd, ((long)reduce_idx - (long)amount_read)+1L, SEEK_CUR ); |
20 | "int $0x40 \n\t" |
- | |
21 | "testl %%esi, %%esi \n\t" |
93 | total_len += finish_idx; |
22 | "jz 1f \n\t" |
94 | return( total_len ); |
23 | "movl %%ebx, (%%esi) \n\t" |
95 | } |
24 | "1:" |
- | |
25 | "addl $28, %%esp \n\t" |
- | |
26 | :"=a" (retval) |
96 | if( buffer[ reduce_idx ] != '\r' ) |
27 | :"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(reads)); |
97 | { |
28 | return retval; |
- | |
29 | }; |
98 | buffer[ finish_idx++ ] = buffer[ reduce_idx ]; |
- | 99 | }; |
|
Line -... | Line 100... | ||
- | 100 | } |
|
- | 101 | ||
- | 102 | total_len += finish_idx; |
|
- | 103 | buffer += finish_idx; |
|
- | 104 | read_len -= finish_idx; |
|
- | 105 | if( iomode_flags & _ISTTY ) |
|
- | 106 | { |
|
- | 107 | break; |
|
- | 108 | } |
|
- | 109 | } while( read_len != 0 ); |
|
- | 110 | } |