@@ -118,6 +118,24 @@ static int gets_lineno;
118
118
static int init_p = 0 , next_p = 0 ;
119
119
static VALUE lineno = INT2FIX (0 );
120
120
121
+ #ifdef _STDIO_USES_IOSTREAM /* GNU libc */
122
+ # ifdef _IO_fpos_t
123
+ # define STDIO_READ_DATA_PENDING (fp ) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
124
+ # else
125
+ # define STDIO_READ_DATA_PENDING (fp ) ((fp)->_gptr < (fp)->_egptr)
126
+ # endif
127
+ #elif defined(FILE_COUNT )
128
+ # define STDIO_READ_DATA_PENDING (fp ) ((fp)->FILE_COUNT > 0)
129
+ #elif defined(FILE_READEND )
130
+ # define STDIO_READ_DATA_PENDING (fp ) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
131
+ #elif defined(__BEOS__ )
132
+ # define STDIO_READ_DATA_PENDING (fp ) (fp->_state._eof == 0)
133
+ #elif defined(__VMS )
134
+ # define STDIO_READ_DATA_PENDING (fp ) (((unsigned int)(*(fp))->_cnt) > 0)
135
+ #else
136
+ # define STDIO_READ_DATA_PENDING (fp ) (!feof(fp))
137
+ #endif
138
+
121
139
#if defined(__VMS )
122
140
#define fopen (file_spec , mode ) fopen(file_spec, mode, "rfm=stmlf")
123
141
#define open (file_spec , flags , mode ) open(file_spec, flags, mode, "rfm=stmlf")
296
314
rb_read_pending (fp )
297
315
FILE * fp ;
298
316
{
299
- /* xxx: return READ_DATA_PENDING(fp); */
300
- return 1 ;
317
+ return STDIO_READ_DATA_PENDING (fp );
301
318
}
302
319
303
320
int
@@ -310,12 +327,9 @@ void
310
327
rb_read_check (fp )
311
328
FILE * fp ;
312
329
{
313
- /* xxx:
314
- if (!READ_DATA_PENDING(fp)) {
330
+ if (!STDIO_READ_DATA_PENDING (fp )) {
315
331
rb_thread_wait_fd (fileno (fp ));
316
332
}
317
- */
318
- return ;
319
333
}
320
334
321
335
void
@@ -1829,19 +1843,16 @@ int
1829
1843
rb_getc (f )
1830
1844
FILE * f ;
1831
1845
{
1832
- /*xxx
1833
1846
int c ;
1834
1847
1835
- if (!READ_DATA_PENDING (f)) {
1848
+ if (!STDIO_READ_DATA_PENDING (f )) {
1836
1849
rb_thread_wait_fd (fileno (f ));
1837
1850
}
1838
1851
TRAP_BEG ;
1839
1852
c = getc (f );
1840
1853
TRAP_END ;
1841
1854
1842
1855
return c ;
1843
- */
1844
- return -1 ;
1845
1856
}
1846
1857
1847
1858
/*
@@ -1937,14 +1948,16 @@ fptr_finalize(fptr, noraise)
1937
1948
return ;
1938
1949
}
1939
1950
if (fptr -> stdio_file ) {
1940
- if (fclose (fptr -> stdio_file ) < 0 && !noraise ) { /* fptr->stdio_file is freed anyway */
1951
+ if (fclose (fptr -> stdio_file ) < 0 && !noraise ) {
1952
+ /* fptr->stdio_file is deallocated anyway */
1941
1953
fptr -> stdio_file = 0 ;
1942
1954
fptr -> fd = -1 ;
1943
1955
rb_sys_fail (fptr -> path );
1944
1956
}
1945
1957
}
1946
1958
else if (0 <= fptr -> fd ) {
1947
- if (close (fptr -> fd ) < 0 && !noraise ) { /* fptr->fd is still not closed */
1959
+ if (close (fptr -> fd ) < 0 && !noraise ) {
1960
+ /* fptr->fd is still not closed */
1948
1961
rb_sys_fail (fptr -> path );
1949
1962
}
1950
1963
}
0 commit comments