Hacks to get the libio package working:

- all wide character functions have been disabled or removed
- ftrylockfile() does not yet work
- reformatted code to be readable (sometimes needed for changes)

Note, this code is not able to be simply updated with newer glibc releases! Sorry.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5429 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2003-11-21 17:01:42 +00:00
parent 081576bd3d
commit 290ba80867
22 changed files with 448 additions and 337 deletions

View File

@ -1,15 +1,17 @@
SubDir OBOS_TOP src kernel libroot posix glibc libio ;
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include arch $(OBOS_ARCH) ;
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc stdio-common ;
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc libio ;
#SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc stdio-common ;
#SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc libio ;
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include ;
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc locale ;
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc ;
SubDirCcFlags -imacrolibc-symbols.h ;
# ToDo: for now, all wide character functions are disabled
# For now, all wide character functions are disabled,
# obprintf() is also disabled, because we don't have
# obstack functionality
KernelMergeObject posix_gnu_libio.o :
<$(SOURCE_GRIST)>clearerr.c
@ -22,24 +24,19 @@ KernelMergeObject posix_gnu_libio.o :
<$(SOURCE_GRIST)>fileno.c
<$(SOURCE_GRIST)>filedoalloc.c
<$(SOURCE_GRIST)>fileops.c
<$(SOURCE_GRIST)>flockfile.c
<$(SOURCE_GRIST)>fputc.c
<$(SOURCE_GRIST)>fputc_u.c
# <$(SOURCE_GRIST)>fputwc.c
# <$(SOURCE_GRIST)>fputwc_u.c
# <$(SOURCE_GRIST)>freopen.c
<$(SOURCE_GRIST)>fseek.c
<$(SOURCE_GRIST)>fseeko.c
<$(SOURCE_GRIST)>ftello.c
<$(SOURCE_GRIST)>fwide.c
<$(SOURCE_GRIST)>fwprintf.c
# <$(SOURCE_GRIST)>fwscanf.c
<$(SOURCE_GRIST)>genops.c
<$(SOURCE_GRIST)>getc.c
<$(SOURCE_GRIST)>getc_u.c
<$(SOURCE_GRIST)>getchar.c
<$(SOURCE_GRIST)>getchar_u.c
# <$(SOURCE_GRIST)>getwc.c
# <$(SOURCE_GRIST)>getwc_u.c
<$(SOURCE_GRIST)>iofclose.c
<$(SOURCE_GRIST)>iofdopen.c
<$(SOURCE_GRIST)>iofflush.c
@ -49,18 +46,16 @@ KernelMergeObject posix_gnu_libio.o :
<$(SOURCE_GRIST)>iofopen.c
<$(SOURCE_GRIST)>iofputs.c
<$(SOURCE_GRIST)>iofputs_u.c
# <$(SOURCE_GRIST)>iofputws.c
# <$(SOURCE_GRIST)>iofputws_u.c
<$(SOURCE_GRIST)>iofread.c
<$(SOURCE_GRIST)>iofread_u.c
# <$(SOURCE_GRIST)>iofsetpos.c
<$(SOURCE_GRIST)>ioftell.c
<$(SOURCE_GRIST)>iofwrite.c
<$(SOURCE_GRIST)>iofwrite_u.c
# <$(SOURCE_GRIST)>iofwide.c
<$(SOURCE_GRIST)>iofwide.c
<$(SOURCE_GRIST)>iogetdelim.c
<$(SOURCE_GRIST)>iogetline.c
# <$(SOURCE_GRIST)>iogets.c
<$(SOURCE_GRIST)>iogetwline.c
<$(SOURCE_GRIST)>iogets.c
<$(SOURCE_GRIST)>iopadn.c
<$(SOURCE_GRIST)>ioputs.c
<$(SOURCE_GRIST)>ioseekoff.c
@ -68,33 +63,46 @@ KernelMergeObject posix_gnu_libio.o :
<$(SOURCE_GRIST)>iosetbuffer.c
<$(SOURCE_GRIST)>iosetvbuf.c
<$(SOURCE_GRIST)>ioungetc.c
# <$(SOURCE_GRIST)>ioungetwc.c
<$(SOURCE_GRIST)>iovdprintf.c
<$(SOURCE_GRIST)>iovsprintf.c
<$(SOURCE_GRIST)>iovsscanf.c
# <$(SOURCE_GRIST)>iovswscanf.c
# <$(SOURCE_GRIST)>iowpadn.c
<$(SOURCE_GRIST)>obprintf.c
# <$(SOURCE_GRIST)>obprintf.c
<$(SOURCE_GRIST)>peekc.c
<$(SOURCE_GRIST)>putc.c
<$(SOURCE_GRIST)>putc_u.c
<$(SOURCE_GRIST)>putchar.c
<$(SOURCE_GRIST)>putchar_u.c
# <$(SOURCE_GRIST)>putwc.c
# <$(SOURCE_GRIST)>putwc_u.c
# <$(SOURCE_GRIST)>putwchar.c
# <$(SOURCE_GRIST)>putwchar_u.c
<$(SOURCE_GRIST)>rewind.c
<$(SOURCE_GRIST)>setbuf.c
<$(SOURCE_GRIST)>setlinebuf.c
<$(SOURCE_GRIST)>stdfiles.c
<$(SOURCE_GRIST)>stdio.c
<$(SOURCE_GRIST)>strops.c
# <$(SOURCE_GRIST)>swprintf.c
# <$(SOURCE_GRIST)>swscanf.c
<$(SOURCE_GRIST)>vasprintf.c
<$(SOURCE_GRIST)>vscanf.c
<$(SOURCE_GRIST)>vsnprintf.c
<$(SOURCE_GRIST)>wfile_stubs.c
# wide character
# <$(SOURCE_GRIST)>fputwc.c
# <$(SOURCE_GRIST)>fputwc_u.c
# <$(SOURCE_GRIST)>fwprintf.c
# <$(SOURCE_GRIST)>fwscanf.c
# <$(SOURCE_GRIST)>getwc.c
# <$(SOURCE_GRIST)>getwc_u.c
# <$(SOURCE_GRIST)>iofputws.c
# <$(SOURCE_GRIST)>iofputws_u.c
# <$(SOURCE_GRIST)>iogetwline.c
# <$(SOURCE_GRIST)>ioungetwc.c
# <$(SOURCE_GRIST)>iovswscanf.c
# <$(SOURCE_GRIST)>iowpadn.c
# <$(SOURCE_GRIST)>putwc.c
# <$(SOURCE_GRIST)>putwc_u.c
# <$(SOURCE_GRIST)>putwchar.c
# <$(SOURCE_GRIST)>putwchar_u.c
# <$(SOURCE_GRIST)>swprintf.c
# <$(SOURCE_GRIST)>swscanf.c
# <$(SOURCE_GRIST)>vswprintf.c
# <$(SOURCE_GRIST)>vwprintf.c
# <$(SOURCE_GRIST)>vwscanf.c

View File

@ -42,12 +42,14 @@
#ifdef __STDC__
#include <stdlib.h>
#endif
#if 0
#if _LIBC
# include "../wcsmbs/wcsmbsload.h"
# include "../iconv/gconv_charset.h"
# include "../iconv/gconv_int.h"
# include <shlib-compat.h>
#endif
#endif
#ifndef errno
extern int errno;
#endif
@ -55,13 +57,12 @@ extern int errno;
# define __set_errno(Val) errno = (Val)
#endif
#ifdef _LIBC
# define open(Name, Flags, Prot) __open (Name, Flags, Prot)
/*# define open(Name, Flags, Prot) __open (Name, Flags, Prot)
# define close(FD) __close (FD)
# define lseek(FD, Offset, Whence) __lseek (FD, Offset, Whence)
# define read(FD, Buf, NBytes) __read (FD, Buf, NBytes)
# define write(FD, Buf, NBytes) __write (FD, Buf, NBytes)
# define write(FD, Buf, NBytes) __write (FD, Buf, NBytes)*/
# define _IO_do_write _IO_new_do_write /* For macro uses. */
#else
# define _IO_new_do_write _IO_do_write
@ -79,11 +80,11 @@ extern int errno;
# define _IO_new_file_xsputn _IO_file_xsputn
#endif
#if 0
#ifdef _LIBC
extern struct __gconv_trans_data __libio_translit attribute_hidden;
#endif
#endif
/* An fstream can be in at most one of put mode, get mode, or putback mode.
Putback mode is a variant of get mode.
@ -179,6 +180,7 @@ _IO_new_file_close_it (fp)
_IO_setg (fp, NULL, NULL, NULL);
_IO_setp (fp, NULL, NULL);
}
#if 0
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
else
{
@ -188,6 +190,7 @@ _IO_new_file_close_it (fp)
_IO_wsetg (fp, NULL, NULL, NULL);
_IO_wsetp (fp, NULL, NULL);
}
#endif
#endif
INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);
@ -250,12 +253,9 @@ _IO_file_open (fp, filename, posix_mode, prot, read_write, is32not64)
}
libc_hidden_def (_IO_file_open)
_IO_FILE *
_IO_new_file_fopen (fp, filename, mode, is32not64)
_IO_FILE *fp;
const char *filename;
const char *mode;
int is32not64;
_IO_new_file_fopen(_IO_FILE *fp, const char *filename, const char *mode, int is32not64)
{
int oflags = 0, omode;
int read_write;
@ -263,7 +263,7 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
int i;
_IO_FILE *result;
#ifdef _LIBC
const char *cs;
// const char *cs;
const char *last_recognized;
#endif
@ -329,7 +329,7 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
result = _IO_file_open (fp, filename, omode|oflags, oprot, read_write,
is32not64);
#if 0
#ifdef _LIBC
if (result != NULL)
{
@ -405,6 +405,7 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
}
}
#endif /* GNU libc */
#endif
return result;
}
@ -449,28 +450,26 @@ INTDEF2(_IO_new_file_setbuf, _IO_file_setbuf)
_IO_FILE *
_IO_file_setbuf_mmap (fp, p, len)
_IO_FILE *fp;
char *p;
_IO_ssize_t len;
_IO_file_setbuf_mmap(_IO_FILE *fp, char *p, _IO_ssize_t len)
{
_IO_FILE *result;
_IO_FILE *result;
/* Change the function table. */
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &INTUSE(_IO_file_jumps);
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
/* Change the function table. */
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &INTUSE(_IO_file_jumps);
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
/* And perform the normal operation. */
result = _IO_new_file_setbuf (fp, p, len);
/* And perform the normal operation. */
result = _IO_new_file_setbuf(fp, p, len);
/* If the call failed, restore to using mmap. */
if (result == NULL)
{
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_file_jumps_mmap;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_mmap;
}
#if HAVE_MMAP
/* If the call failed, restore to using mmap. */
if (result == NULL) {
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &_IO_file_jumps_mmap;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_mmap;
}
#endif
return result;
return result;
}
static int new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
@ -703,22 +702,25 @@ mmap_remap_check (_IO_FILE *fp)
}
else
{
/* Life is no longer good for mmap. Punt it. */
(void) __munmap (fp->_IO_buf_base,
fp->_IO_buf_end - fp->_IO_buf_base);
punt:
fp->_IO_buf_base = fp->_IO_buf_end = NULL;
_IO_setg (fp, NULL, NULL, NULL);
if (fp->_mode <= 0)
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &INTUSE(_IO_file_jumps);
else
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_wfile_jumps;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
/* Life is no longer good for mmap. Punt it. */
__munmap (fp->_IO_buf_base, fp->_IO_buf_end - fp->_IO_buf_base);
return 1;
}
punt:
fp->_IO_buf_base = fp->_IO_buf_end = NULL;
_IO_setg (fp, NULL, NULL, NULL);
if (fp->_mode <= 0)
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &INTUSE(_IO_file_jumps);
else
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &_IO_wfile_jumps;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
return 1;
}
}
/* Special callback replacing the underflow callbacks if we mmap the file. */
int
_IO_file_underflow_mmap (_IO_FILE *fp)
@ -737,78 +739,81 @@ _IO_file_underflow_mmap (_IO_FILE *fp)
return EOF;
}
static void
decide_maybe_mmap (_IO_FILE *fp)
{
/* We use the file in read-only mode. This could mean we can
mmap the file and use it without any copying. But not all
file descriptors are for mmap-able objects and on 32-bit
machines we don't want to map files which are too large since
this would require too much virtual memory. */
struct _G_stat64 st;
if (_IO_SYSSTAT (fp, &st) == 0
&& S_ISREG (st.st_mode) && st.st_size != 0
/* Limit the file size to 1MB for 32-bit machines. */
&& (sizeof (ptrdiff_t) > 4 || st.st_size < 1*1024*1024)
/* Sanity check. */
&& (fp->_offset == _IO_pos_BAD || fp->_offset <= st.st_size))
{
/* Try to map the file. */
void *p;
static void
decide_maybe_mmap(_IO_FILE *fp)
{
/* We use the file in read-only mode. This could mean we can
* mmap the file and use it without any copying. But not all
* file descriptors are for mmap-able objects and on 32-bit
* machines we don't want to map files which are too large since
* this would require too much virtual memory.
*/
struct _G_stat64 st;
if (_IO_SYSSTAT(fp, &st) == 0
&& S_ISREG (st.st_mode) && st.st_size != 0
/* Limit the file size to 1MB for 32-bit machines. */
&& (sizeof(ptrdiff_t) > 4 || st.st_size < 1*1024*1024)
/* Sanity check. */
&& (fp->_offset == _IO_pos_BAD || fp->_offset <= st.st_size))
{
/* Try to map the file. */
void *p;
# ifdef _G_MMAP64
p = _G_MMAP64 (NULL, st.st_size, PROT_READ, MAP_SHARED, fp->_fileno, 0);
p = _G_MMAP64(NULL, st.st_size, PROT_READ, MAP_SHARED, fp->_fileno, 0);
# else
p = __mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fp->_fileno, 0);
p = __mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fp->_fileno, 0);
# endif
if (p != MAP_FAILED)
{
/* OK, we managed to map the file. Set the buffer up and use a
special jump table with simplified underflow functions which
never tries to read anything from the file. */
if (
if (p != MAP_FAILED) {
/* OK, we managed to map the file. Set the buffer up and use a
* special jump table with simplified underflow functions which
* never tries to read anything from the file.
*/
if (
# ifdef _G_LSEEK64
_G_LSEEK64
# else
__lseek
# endif
(fp->_fileno, st.st_size, SEEK_SET) != st.st_size)
{
(void) __munmap (p, st.st_size);
fp->_offset = _IO_pos_BAD;
}
else
{
INTUSE(_IO_setb) (fp, p, (char *) p + st.st_size, 0);
(fp->_fileno, st.st_size, SEEK_SET) != st.st_size) {
(void) __munmap (p, st.st_size);
fp->_offset = _IO_pos_BAD;
} else {
INTUSE(_IO_setb) (fp, p, (char *) p + st.st_size, 0);
if (fp->_offset == _IO_pos_BAD)
fp->_offset = 0;
if (fp->_offset == _IO_pos_BAD)
fp->_offset = 0;
_IO_setg (fp, p, p + fp->_offset, p + st.st_size);
fp->_offset = st.st_size;
_IO_setg (fp, p, p + fp->_offset, p + st.st_size);
fp->_offset = st.st_size;
if (fp->_mode <= 0)
_IO_JUMPS ((struct _IO_FILE_plus *)fp) = &_IO_file_jumps_mmap;
else
_IO_JUMPS ((struct _IO_FILE_plus *)fp) = &_IO_wfile_jumps_mmap;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_mmap;
if (fp->_mode <= 0)
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &_IO_file_jumps_mmap;
else
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &_IO_wfile_jumps_mmap;
return;
}
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_mmap;
return;
}
}
}
}
/* We couldn't use mmap, so revert to the vanilla file operations. */
/* We couldn't use mmap, so revert to the vanilla file operations. */
if (fp->_mode <= 0)
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &INTUSE(_IO_file_jumps);
else
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_wfile_jumps;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
if (fp->_mode <= 0)
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &INTUSE(_IO_file_jumps);
else
_IO_JUMPS((struct _IO_FILE_plus *)fp) = &_IO_wfile_jumps;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
}
int
_IO_file_underflow_maybe_mmap (_IO_FILE *fp)
{

View File

@ -0,0 +1,34 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include "libioP.h"
#undef _IO_flockfile
#undef _IO_funlockfile
void
_IO_flockfile(_IO_FILE *stream)
{
__libc_lock_lock_recursive(*stream->_lock);
}
void
_IO_funlockfile(_IO_FILE *stream)
{
__libc_lock_unlock_recursive(*stream->_lock);
}
int
_IO_ftrylockfile(_IO_FILE *stream)
{
// ToDo: that code has probably never been tested!
//return __libc_lock_trylock_recursive(*stream->_lock);
return 1;
}

View File

@ -68,8 +68,8 @@ freopen (filename, mode, fp)
{
INTUSE(_IO_file_close_it) (fp);
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &INTUSE(_IO_file_jumps);
if (fp->_vtable_offset == 0 && fp->_wide_data != NULL)
fp->_wide_data->_wide_vtable = &INTUSE(_IO_wfile_jumps);
// if (fp->_vtable_offset == 0 && fp->_wide_data != NULL)
// fp->_wide_data->_wide_vtable = &INTUSE(_IO_wfile_jumps);
result = INTUSE(_IO_file_fopen) (fp, filename, mode, 1);
if (result != NULL)
result = __fopen_maybe_mmap (result);

View File

@ -54,8 +54,8 @@ freopen64 (filename, mode, fp)
}
INTUSE(_IO_file_close_it) (fp);
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &INTUSE(_IO_file_jumps);
if (fp->_vtable_offset == 0 && fp->_wide_data != NULL)
fp->_wide_data->_wide_vtable = &INTUSE(_IO_wfile_jumps);
// if (fp->_vtable_offset == 0 && fp->_wide_data != NULL)
// fp->_wide_data->_wide_vtable = &INTUSE(_IO_wfile_jumps);
result = INTUSE(_IO_file_fopen) (fp, filename, mode, 0);
if (result != NULL)
result = __fopen_maybe_mmap (result);

View File

@ -23,34 +23,36 @@
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception. */
in files containing the exception.
*/
#include <libioP.h>
#include <stdio.h>
#include <wchar.h>
int
fwide (fp, mode)
_IO_FILE *fp;
int mode;
fwide(_IO_FILE *fp, int mode)
{
int result;
int result;
/* Normalize the value. */
mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1);
/* Normalize the value. */
mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1);
if (mode == 0 || fp->_mode != 0)
/* The caller simply wants to know about the current orientation
or the orientation already has been determined. */
return fp->_mode;
if (mode == 0 || fp->_mode != 0) {
// The caller simply wants to know about the current orientation
// or the orientation already has been determined.
return fp->_mode;
}
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
_IO_cleanup_region_start((void (*) __P ((void *)))_IO_funlockfile, fp);
_IO_flockfile(fp);
result = _IO_fwide (fp, mode);
result = _IO_fwide(fp, mode);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
_IO_funlockfile(fp);
_IO_cleanup_region_end(0);
return result;
return result;
}

View File

@ -23,16 +23,16 @@
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception. */
in files containing the exception.
*/
/* Generic or default I/O operations. */
#include "libioP.h"
#ifdef __STDC__
#include <stdlib.h>
#endif
#include <string.h>
#ifdef _IO_MTSAFE_IO
static _IO_lock_t list_all_lock = _IO_lock_initializer;
#endif
@ -43,6 +43,7 @@ static int _IO_list_all_stamp;
static _IO_FILE *run_fp;
#if 0
static void
flush_cleanup (void *not_used)
{
@ -52,10 +53,11 @@ flush_cleanup (void *not_used)
_IO_lock_unlock (list_all_lock);
#endif
}
#endif
void
_IO_un_link (fp)
struct _IO_FILE_plus *fp;
_IO_un_link(struct _IO_FILE_plus *fp)
{
if (fp->file._flags & _IO_LINKED)
{
@ -226,17 +228,18 @@ _IO_switch_to_put_mode (fp)
}
#endif
int
__overflow (f, ch)
_IO_FILE *f;
int ch;
__overflow(_IO_FILE *file, int character)
{
/* This is a single-byte stream. */
if (f->_mode == 0)
_IO_fwide (f, -1);
return _IO_OVERFLOW (f, ch);
/* This is a single-byte stream. */
if (file->_mode == 0)
_IO_fwide(file, -1);
return _IO_OVERFLOW(file, character);
}
libc_hidden_def (__overflow)
libc_hidden_def(__overflow)
static int save_for_backup __P ((_IO_FILE *fp, char *end_p))
#ifdef _LIBC
@ -319,71 +322,75 @@ save_for_backup (fp, end_p)
return 0;
}
int
__underflow (fp)
_IO_FILE *fp;
{
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
if (fp->_vtable_offset == 0 && _IO_fwide (fp, -1) != -1)
return EOF;
#endif
if (fp->_mode == 0)
_IO_fwide (fp, -1);
if (_IO_in_put_mode (fp))
if (INTUSE(_IO_switch_to_get_mode) (fp) == EOF)
return EOF;
if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char *) fp->_IO_read_ptr;
if (_IO_in_backup (fp))
{
_IO_switch_to_main_get_area (fp);
if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char *) fp->_IO_read_ptr;
}
if (_IO_have_markers (fp))
{
if (save_for_backup (fp, fp->_IO_read_end))
return EOF;
}
else if (_IO_have_backup (fp))
INTUSE(_IO_free_backup_area) (fp);
return _IO_UNDERFLOW (fp);
}
libc_hidden_def (__underflow)
int
__uflow (fp)
_IO_FILE *fp;
__underflow(_IO_FILE *file)
{
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
if (fp->_vtable_offset == 0 && _IO_fwide (fp, -1) != -1)
return EOF;
if (file->_vtable_offset == 0 && _IO_fwide(file, -1) != -1)
return EOF;
#endif
if (fp->_mode == 0)
_IO_fwide (fp, -11);
if (_IO_in_put_mode (fp))
if (INTUSE(_IO_switch_to_get_mode) (fp) == EOF)
return EOF;
if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char *) fp->_IO_read_ptr++;
if (_IO_in_backup (fp))
{
_IO_switch_to_main_get_area (fp);
if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char *) fp->_IO_read_ptr++;
if (file->_mode == 0)
_IO_fwide(file, -1);
if (_IO_in_put_mode(file) && INTUSE(_IO_switch_to_get_mode)(file) == EOF)
return EOF;
if (file->_IO_read_ptr < file->_IO_read_end)
return *(unsigned char *)file->_IO_read_ptr;
if (_IO_in_backup(file)) {
_IO_switch_to_main_get_area(file);
if (file->_IO_read_ptr < file->_IO_read_end)
return *(unsigned char *)file->_IO_read_ptr;
}
if (_IO_have_markers (fp))
{
if (save_for_backup (fp, fp->_IO_read_end))
return EOF;
}
else if (_IO_have_backup (fp))
INTUSE(_IO_free_backup_area) (fp);
return _IO_UFLOW (fp);
if (_IO_have_markers(file)) {
if (save_for_backup(file, file->_IO_read_end))
return EOF;
} else if (_IO_have_backup(file))
INTUSE(_IO_free_backup_area)(file);
return _IO_UNDERFLOW(file);
}
libc_hidden_def (__uflow)
libc_hidden_def(__underflow)
int
__uflow(_IO_FILE *file)
{
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
if (file->_vtable_offset == 0 && _IO_fwide(file, -1) != -1)
return EOF;
#endif
if (file->_mode == 0)
_IO_fwide(file, -11);
if (_IO_in_put_mode(file) && INTUSE(_IO_switch_to_get_mode)(file) == EOF)
return EOF;
if (file->_IO_read_ptr < file->_IO_read_end)
return *(unsigned char *)file->_IO_read_ptr++;
if (_IO_in_backup(file)) {
_IO_switch_to_main_get_area(file);
if (file->_IO_read_ptr < file->_IO_read_end)
return *(unsigned char *)file->_IO_read_ptr++;
}
if (_IO_have_markers(file)) {
if (save_for_backup(file, file->_IO_read_end))
return EOF;
} else if (_IO_have_backup(file))
INTUSE(_IO_free_backup_area)(file);
return _IO_UFLOW(file);
}
libc_hidden_def(__uflow)
void
_IO_setb (f, b, eb, a)

View File

@ -68,6 +68,7 @@ _IO_new_fclose (fp)
_IO_cleanup_region_end (0);
if (fp->_mode > 0)
{
#if 0
#if _LIBC
/* This stream has a wide orientation. This means we have to free
the conversion functions. */
@ -75,6 +76,7 @@ _IO_new_fclose (fp)
__gconv_release_step (cc->__cd_in.__cd.__steps);
__gconv_release_step (cc->__cd_out.__cd.__steps);
#endif
#endif
}
else

View File

@ -23,30 +23,21 @@
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception. */
in files containing the exception.
*/
#include "libioP.h"
#ifdef __STDC__
# include <stdlib.h>
#endif
#include <stdlib.h>
#include <fcntl.h>
#ifdef _LIBC
# include <shlib-compat.h>
#endif
#ifndef _IO_fcntl
#ifdef _LIBC
#define _IO_fcntl __fcntl
#else
#define _IO_fcntl fcntl
#endif
#endif
_IO_FILE *
_IO_new_fdopen (fd, mode)
int fd;
const char *mode;
_IO_new_fdopen (int fd, const char *mode)
{
int read_write;
int posix_mode = 0;
@ -99,7 +90,7 @@ _IO_new_fdopen (fd, mode)
break;
}
#ifdef F_GETFL
fd_flags = _IO_fcntl (fd, F_GETFL);
fd_flags = fcntl(fd, F_GETFL);
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
@ -132,7 +123,7 @@ _IO_new_fdopen (fd, mode)
if ((posix_mode & O_APPEND) && !(fd_flags & O_APPEND))
{
#ifdef F_SETFL
if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
if (fcntl(fd, F_SETFL, fd_flags | O_APPEND) == -1)
#endif
return NULL;
}

View File

@ -35,6 +35,7 @@ _IO_fputs (str, fp)
{
_IO_size_t len = strlen (str);
int result = EOF;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);

View File

@ -42,7 +42,7 @@
# include <shlib-compat.h>
#endif
#if 0
/* Prototypes of libio's codecvt functions. */
static enum __codecvt_result do_out (struct _IO_codecvt *codecvt,
__mbstate_t *statep,
@ -87,22 +87,24 @@ struct __gconv_trans_data __libio_translit attribute_hidden =
.__trans_fct = __gconv_transliterate
};
#endif
#endif
/* Return orientation of stream. If mode is nonzero try to change
the orientation first. */
#undef _IO_fwide
int
_IO_fwide (fp, mode)
_IO_FILE *fp;
int mode;
{
/* Normalize the value. */
mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1);
* the orientation first.
*/
if (mode == 0)
/* The caller simply wants to know about the current orientation. */
return fp->_mode;
#undef _IO_fwide
int
_IO_fwide(_IO_FILE *fp, int mode)
{
/* Normalize the value. */
mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1);
if (mode == 0) {
/* The caller simply wants to know about the current orientation. */
return fp->_mode;
}
#if defined SHARED && defined _LIBC \
&& SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
@ -112,20 +114,25 @@ _IO_fwide (fp, mode)
return -1;
#endif
if (fp->_mode != 0)
/* The orientation already has been determined. */
return fp->_mode;
if (fp->_mode != 0) {
/* The orientation already has been determined. */
return fp->_mode;
}
/* Set the orientation appropriately. */
if (mode > 0)
{
struct _IO_codecvt *cc = fp->_codecvt = &fp->_wide_data->_codecvt;
/* Set the orientation appropriately. */
if (mode > 0) {
// wide-orientation is currently disabled!
return -1;
}
#if 0
struct _IO_codecvt *cc = fp->_codecvt = &fp->_wide_data->_codecvt;
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base;
fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base;
/* Get the character conversion functions based on the currently
selected locale for LC_CTYPE. */
/* Get the character conversion functions based on the currently
* selected locale for LC_CTYPE.
*/
#ifdef _LIBC
{
struct gconv_fcts fcts;
@ -208,14 +215,15 @@ _IO_fwide (fp, mode)
which allows the functions without knowing the position. */
fp->_offset = _IO_SYSSEEK (fp, 0, _IO_seek_cur);
}
#endif
/* Set the mode now. */
fp->_mode = mode;
/* Set the mode now. */
fp->_mode = mode;
return mode;
return mode;
}
#if 0
static enum __codecvt_result
do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
const wchar_t *from_start, const wchar_t *from_end,
@ -496,3 +504,4 @@ do_max_length (struct _IO_codecvt *codecvt)
return MB_CUR_MAX;
#endif
}
#endif

View File

@ -23,12 +23,11 @@
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception. */
in files containing the exception.
*/
#ifdef __STDC__
#include <stdlib.h>
#endif
#include "libioP.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@ -39,11 +38,7 @@
null terminator), or -1 on error or EOF. */
_IO_ssize_t
_IO_getdelim (lineptr, n, delimiter, fp)
char **lineptr;
_IO_size_t *n;
int delimiter;
_IO_FILE *fp;
_IO_getdelim(char **lineptr, _IO_size_t *n, int delimiter, _IO_FILE *fp)
{
int result;
_IO_ssize_t cur_len = 0;

View File

@ -77,5 +77,5 @@ weak_alias (_IO_gets, gets)
#endif
#ifdef _LIBC
link_warning (gets, "the `gets' function is dangerous and should not be used.")
//link_warning (gets, "the `gets' function is dangerous and should not be used.")
#endif

View File

@ -23,31 +23,34 @@
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception. */
in files containing the exception.
*/
#include "libioP.h"
#include <string.h>
int
_IO_puts (str)
const char *str;
_IO_puts(const char *str)
{
int result = EOF;
_IO_size_t len = strlen (str);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
_IO_stdout);
_IO_flockfile (_IO_stdout);
int result = EOF;
_IO_size_t len = strlen(str);
if ((_IO_stdout->_vtable_offset != 0 || _IO_fwide (_IO_stdout, -1) == -1)
&& _IO_sputn (_IO_stdout, str, len) == len
&& _IO_putc_unlocked ('\n', _IO_stdout) != EOF)
result = len + 1;
_IO_cleanup_region_start((void (*) __P ((void *))) _IO_funlockfile, _IO_stdout);
_IO_flockfile(_IO_stdout);
_IO_funlockfile (_IO_stdout);
_IO_cleanup_region_end (0);
return result;
if ((_IO_stdout->_vtable_offset != 0 || _IO_fwide(_IO_stdout, -1) == -1)
&& _IO_sputn(_IO_stdout, str, len) == len
&& _IO_putc_unlocked('\n', _IO_stdout) != EOF)
result = len + 1;
_IO_funlockfile(_IO_stdout);
_IO_cleanup_region_end(0);
return result;
}
#ifdef weak_alias
weak_alias (_IO_puts, puts)
weak_alias(_IO_puts, puts)
#endif

View File

@ -52,7 +52,11 @@ _IO_seekoff_unlocked (fp, offset, dir, mode)
callback may not know to do the right thing about it.
This may be over-kill, but it'll do for now. TODO */
if (mode != 0 && ((_IO_fwide (fp, 0) < 0 && _IO_have_backup (fp))
#if 0
|| (_IO_fwide (fp, 0) > 0 && _IO_have_wbackup (fp))))
#else
))
#endif
{
if (dir == _IO_seek_cur && _IO_in_backup (fp))
{
@ -63,8 +67,10 @@ _IO_seekoff_unlocked (fp, offset, dir, mode)
}
if (_IO_fwide (fp, 0) < 0)
INTUSE(_IO_free_backup_area) (fp);
#if 0
else
INTUSE(_IO_free_wbackup_area) (fp);
#endif
}
return _IO_SEEKOFF (fp, offset, dir, mode);

View File

@ -23,48 +23,46 @@
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception. */
in files containing the exception.
*/
#include <libioP.h>
_IO_off64_t
_IO_seekpos_unlocked (fp, pos, mode)
_IO_FILE *fp;
_IO_off64_t pos;
int mode;
{
/* If we have a backup buffer, get rid of it, since the __seekoff
callback may not know to do the right thing about it.
This may be over-kill, but it'll do for now. TODO */
if (_IO_fwide (fp, 0) <= 0)
{
if (_IO_have_backup (fp))
INTUSE(_IO_free_backup_area) (fp);
}
else
{
if (_IO_have_wbackup (fp))
INTUSE(_IO_free_wbackup_area) (fp);
}
return _IO_SEEKPOS (fp, pos, mode);
_IO_off64_t
_IO_seekpos_unlocked(_IO_FILE *fp, _IO_off64_t pos, int mode)
{
/* If we have a backup buffer, get rid of it, since the __seekoff
* callback may not know to do the right thing about it.
* This may be over-kill, but it'll do for now. TODO
*/
if (_IO_fwide(fp, 0) <= 0) {
if (_IO_have_backup(fp))
INTUSE(_IO_free_backup_area)(fp);
} else {
#if 0
if (_IO_have_wbackup(fp))
INTUSE(_IO_free_wbackup_area)(fp);
#endif
}
return _IO_SEEKPOS(fp, pos, mode);
}
_IO_off64_t
_IO_seekpos (fp, pos, mode)
_IO_FILE *fp;
_IO_off64_t pos;
int mode;
_IO_seekpos(_IO_FILE *fp, _IO_off64_t pos, int mode)
{
_IO_off64_t retval;
_IO_off64_t retval;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
_IO_cleanup_region_start((void (*) __P ((void *)))_IO_funlockfile, fp);
_IO_flockfile(fp);
retval = _IO_seekpos_unlocked (fp, pos, mode);
retval = _IO_seekpos_unlocked(fp, pos, mode);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return retval;
_IO_funlockfile(fp);
_IO_cleanup_region_end(0);
return retval;
}

View File

@ -482,6 +482,7 @@ extern int _IO_new_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
extern int _IO_old_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
#if 0
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
# define _IO_do_flush(_f) \
((_f)->_mode <= 0 \
@ -490,11 +491,13 @@ extern int _IO_old_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
: INTUSE(_IO_wdo_write)(_f, (_f)->_wide_data->_IO_write_base, \
((_f)->_wide_data->_IO_write_ptr \
- (_f)->_wide_data->_IO_write_base)))
#else
#endif // was #else
#endif
# define _IO_do_flush(_f) \
INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
(_f)->_IO_write_ptr-(_f)->_IO_write_base)
#endif
#define _IO_old_do_flush(_f) \
_IO_old_do_write(_f, (_f)->_IO_write_base, \
(_f)->_IO_write_ptr-(_f)->_IO_write_base)

View File

@ -29,7 +29,7 @@
/* This is a compatibility file. If we don't build the libc with
versioning don't compile this file. */
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
#if 1 /*SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)*/
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
@ -53,11 +53,11 @@ extern int errno;
#ifdef _LIBC
# define open(Name, Flags, Prot) __open (Name, Flags, Prot)
/*# define open(Name, Flags, Prot) __open (Name, Flags, Prot)
# define close(FD) __close (FD)
# define lseek(FD, Offset, Whence) __lseek (FD, Offset, Whence)
# define read(FD, Buf, NBytes) __read (FD, Buf, NBytes)
# define write(FD, Buf, NBytes) __write (FD, Buf, NBytes)
# define write(FD, Buf, NBytes) __write (FD, Buf, NBytes)*/
#endif
/* An fstream can be in at most one of put mode, get mode, or putback mode.
@ -775,7 +775,7 @@ struct _IO_jump_t _IO_old_file_jumps =
JUMP_INIT(close, INTUSE(_IO_file_close)),
JUMP_INIT(stat, INTUSE(_IO_file_stat))
};
/*
compat_symbol (libc, _IO_old_do_write, _IO_do_write, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_attach, _IO_file_attach, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_close_it, _IO_file_close_it, GLIBC_2_0);
@ -789,5 +789,5 @@ compat_symbol (libc, _IO_old_file_seekoff, _IO_file_seekoff, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_underflow, _IO_file_underflow, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_write, _IO_file_write, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_xsputn, _IO_file_xsputn, GLIBC_2_0);
*/
#endif

View File

@ -23,21 +23,18 @@
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception. */
in files containing the exception.
*/
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
#define _IO_USE_OLD_IO_FILE
#ifdef __STDC__
# include <stdlib.h>
#endif
#include <stdlib.h>
#include "libioP.h"
#include <fcntl.h>
#ifndef _IO_fcntl
# define _IO_fcntl __fcntl
#endif
_IO_FILE *
_IO_old_fdopen (fd, mode)
@ -74,7 +71,7 @@ _IO_old_fdopen (fd, mode)
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
read_write &= _IO_IS_APPENDING;
#ifdef F_GETFL
fd_flags = _IO_fcntl (fd, F_GETFL);
fd_flags = fcntl(fd, F_GETFL);
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
@ -102,7 +99,7 @@ _IO_old_fdopen (fd, mode)
if ((posix_mode & O_APPEND) && !(fd_flags & O_APPEND))
{
#ifdef F_SETFL
if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
if (fcntl(fd, F_SETFL, fd_flags | O_APPEND) == -1)
#endif
return NULL;
}

View File

@ -25,8 +25,8 @@
This exception applies to code released by its copyright holders
in files containing the exception. */
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
//#include <shlib-compat.h>
//#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
/* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
for C code. Compare stdstreams.cc.
@ -56,8 +56,8 @@ DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_, _IO_NO_READS+_IO_UNBUFFERED);
#include <stdio.h>
extern const int _IO_stdin_used;
weak_extern (_IO_stdin_used);
//extern const int _IO_stdin_used;
//weak_extern (_IO_stdin_used);
#undef stdin
#undef stdout
@ -76,7 +76,8 @@ static void _IO_check_libio __P ((void)) __attribute__ ((constructor));
static void
_IO_check_libio ()
{
if (&_IO_stdin_used == NULL)
_kern_debug_output("Hey dude!\n");
//if (&_IO_stdin_used == NULL)
{
/* We are using the old one. */
_IO_stdin = stdin = (_IO_FILE *) &_IO_stdin_;
@ -93,4 +94,4 @@ _IO_check_libio ()
#endif
#endif
//#endif

View File

@ -35,7 +35,7 @@
#include "libioP.h"
#ifdef _IO_MTSAFE_IO
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
/*# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
static struct _IO_wide_data _IO_wide_data_##FD \
@ -44,13 +44,15 @@
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, &_IO_wide_data_##FD), \
&INTUSE(_IO_file_jumps)};
# else
*/
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
struct _IO_FILE_plus NAME \
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), \
&INTUSE(_IO_file_jumps)};
# endif
//# endif
#else
/*
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
static struct _IO_wide_data _IO_wide_data_##FD \
@ -59,11 +61,12 @@
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, &_IO_wide_data_##FD), \
&INTUSE(_IO_file_jumps)};
# else
*/
# define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
struct _IO_FILE_plus NAME \
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), \
&INTUSE(_IO_file_jumps)};
# endif
//# endif
#endif
DEF_STDFILE(_IO_2_1_stdin_, 0, 0, _IO_NO_WRITES);

View File

@ -0,0 +1,46 @@
/* Copyright (C) 1993,95,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link the code in this file with
files compiled with a GNU compiler to produce an executable,
that does not cause the resulting executable to be covered by
the GNU Lesser General Public License. This exception does not
however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
This exception applies to code released by its copyright holders
in files containing the exception.
*/
#include <libioP.h>
struct _IO_jump_t _IO_wfile_jumps = {
JUMP_INIT_DUMMY,
NULL
};
INTVARDEF(_IO_wfile_jumps)
struct _IO_jump_t _IO_wfile_jumps_mmap = {
JUMP_INIT_DUMMY,
NULL
};
struct _IO_jump_t _IO_wfile_jumps_maybe_mmap = {
JUMP_INIT_DUMMY,
NULL
};