Initial revision

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3005 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2003-03-23 23:49:22 +00:00
parent 8374297262
commit 000d24f681
129 changed files with 17494 additions and 0 deletions

View File

@ -0,0 +1,116 @@
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 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
KernelMergeObject posix_gnu_libio.o :
<$(SOURCE_GRIST)>clearerr.c
<$(SOURCE_GRIST)>clearerr_u.c
<$(SOURCE_GRIST)>fcloseall.c
<$(SOURCE_GRIST)>feof.c
<$(SOURCE_GRIST)>feof_u.c
<$(SOURCE_GRIST)>ferror.c
<$(SOURCE_GRIST)>ferror_u.c
<$(SOURCE_GRIST)>fileno.c
<$(SOURCE_GRIST)>filedoalloc.c
<$(SOURCE_GRIST)>fileops.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
# <$(SOURCE_GRIST)>iofgetpos.c
<$(SOURCE_GRIST)>iofgets.c
<$(SOURCE_GRIST)>iofgets_u.c
<$(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)>iogetline.c
# <$(SOURCE_GRIST)>iogets.c
<$(SOURCE_GRIST)>iogetwline.c
<$(SOURCE_GRIST)>iopadn.c
<$(SOURCE_GRIST)>ioputs.c
<$(SOURCE_GRIST)>ioseekoff.c
<$(SOURCE_GRIST)>ioseekpos.c
<$(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)>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)>vswprintf.c
# <$(SOURCE_GRIST)>vwprintf.c
# <$(SOURCE_GRIST)>vwscanf.c
# <$(SOURCE_GRIST)>wfiledoalloc.c
# <$(SOURCE_GRIST)>wfileops.c
# <$(SOURCE_GRIST)>wgenops.c
# <$(SOURCE_GRIST)>wprintf.c
# <$(SOURCE_GRIST)>wscanf.c
# <$(SOURCE_GRIST)>wstrops.c
:
-fPIC -DPIC
;
#KernelMergeObject kernel_posix_stdio.o :
# <$(SOURCE_GRIST)>kvsprintf.c
# :
# -fPIC -DPIC
# ;
#

View File

@ -0,0 +1,146 @@
/* This file is needed by libio to define various configuration parameters.
These are always the same in the GNU C library. */
#ifndef _G_config_h
#define _G_config_h 1
#include <libc-symbols.h>
#include <bits/types.h>
#define _GLIBCPP_USE_THREADS
//#define _GLIBCPP_USE_WCHAR_T
#define _IO_MTSAFE_IO
/* Define types for libio in terms of the standard internal type names. */
#include <sys/types.h>
#define __need_size_t
#define __need_wchar_t
#define __need_wint_t
#define __need_NULL
#define __need_ptrdiff_t
#ifdef __cplusplus
# include <cstddef>
#else
# include <stddef.h>
#endif
#include <wchar.h>
#ifndef _WINT_T
/* Integral type unchanged by default argument promotions that can
hold any value corresponding to members of the extended character
set, as well as at least one value that does not correspond to any
member of the extended character set. */
# define _WINT_T
typedef unsigned int wint_t;
#endif
/* For use as part of glibc (native) or as part of libstdc++ (maybe
not glibc) */
#ifndef __c_mbstate_t_defined
# define __c_mbstate_t_defined 1
/*# ifdef _GLIBCPP_USE_WCHAR_T*/
typedef struct
{
int count;
wint_t value;
} __c_mbstate_t;
/*# endif*/
#endif
#undef __need_mbstate_t
typedef size_t _G_size_t;
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
typedef struct
{
off_t __pos;
__c_mbstate_t __state;
} _G_fpos_t;
typedef struct
{
off_t __pos;
__c_mbstate_t __state;
} _G_fpos64_t;
#else
typedef off_t _G_fpos_t;
typedef off_t _G_fpos64_t;
#endif
#define __off_t off_t
#define _G_ssize_t ssize_t
#define _G_off_t off_t
#define _G_off64_t off_t
#define _G_pid_t pid_t
#define _G_uid_t uid_t
#define _G_wchar_t wchar_t
#define _G_wint_t wint_t
#define _G_stat64 stat
#include <iconv/gconv.h>
typedef union
{
struct __gconv_info __cd;
struct
{
struct __gconv_info __cd;
struct __gconv_step_data __data;
} __combined;
} _G_iconv_t;
typedef int _G_int16_t __attribute__ ((__mode__ (__HI__)));
typedef int _G_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__)));
#define _G_HAVE_BOOL 1
/* These library features are always available in the GNU C library. */
#define _G_HAVE_ATEXIT 1
#define _G_HAVE_SYS_CDEFS 1
#define _G_HAVE_SYS_WAIT 1
#define _G_NEED_STDARG_H 1
#define _G_va_list __gnuc_va_list
#define _G_HAVE_PRINTF_FP 1
//#define _G_HAVE_MMAP 1
#define _G_HAVE_LONG_DOUBLE_IO 1
#define _G_HAVE_IO_FILE_OPEN 1
#define _G_HAVE_IO_GETLINE_INFO 1
#define _G_IO_IO_FILE_VERSION 0x20001
//#define _G_OPEN64 __open64
//#define _G_LSEEK64 __lseek64
//#define _G_FSTAT64(fd,buf) __fxstat64 (_STAT_VER, fd, buf)
/* This is defined by <bits/stat.h> if `st_blksize' exists. */
/*#define _G_HAVE_ST_BLKSIZE defined (_STATBUF_ST_BLKSIZE)*/
#define _G_BUFSIZ 8192
/* These are the vtbl details for ELF. */
#define _G_NAMES_HAVE_UNDERSCORE 0
#define _G_VTABLE_LABEL_HAS_LENGTH 1
#ifndef _G_USING_THUNKS
# define _G_USING_THUNKS 1
#endif /* _G_USING_THUNKS */
#define _G_VTABLE_LABEL_PREFIX "__vt_"
#define _G_VTABLE_LABEL_PREFIX_ID __vt_
#define _G_INTERNAL_CCS "UCS4"
#define _G_HAVE_WEAK_SYMBOL 1
#define _G_STDIO_USES_LIBIO 1
#if defined __cplusplus || defined __STDC__
# define _G_ARGS(ARGLIST) ARGLIST
#else
# define _G_ARGS(ARGLIST) ()
#endif
#endif /* _G_config.h */

View File

@ -0,0 +1,169 @@
/* Optimizing macros and inline functions for stdio functions.
Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#ifndef _STDIO_H
# error "Never include <bits/stdio.h> directly; use <stdio.h> instead."
#endif
#ifdef __cplusplus
# define __STDIO_INLINE inline
#else
# define __STDIO_INLINE extern __inline
#endif
#ifdef __USE_EXTERN_INLINES
/* Write formatted output to stdout from argument list ARG. */
__STDIO_INLINE int
vprintf (__const char *__restrict __fmt, _G_va_list __arg) __THROW
{
return vfprintf (stdout, __fmt, __arg);
}
/* Read a character from stdin. */
__STDIO_INLINE int
getchar (void) __THROW
{
return _IO_getc (stdin);
}
# if defined __USE_POSIX || defined __USE_MISC
/* This is defined in POSIX.1:1996. */
__STDIO_INLINE int
getc_unlocked (FILE *__fp) __THROW
{
return _IO_getc_unlocked (__fp);
}
/* This is defined in POSIX.1:1996. */
__STDIO_INLINE int
getchar_unlocked (void) __THROW
{
return _IO_getc_unlocked (stdin);
}
# endif /* POSIX || misc */
/* Write a character to stdout. */
__STDIO_INLINE int
putchar (int __c) __THROW
{
return _IO_putc (__c, stdout);
}
# ifdef __USE_MISC
/* Faster version when locking is not necessary. */
__STDIO_INLINE int
fputc_unlocked (int __c, FILE *__stream) __THROW
{
return _IO_putc_unlocked (__c, __stream);
}
# endif /* misc */
# if defined __USE_POSIX || defined __USE_MISC
/* This is defined in POSIX.1:1996. */
__STDIO_INLINE int
putc_unlocked (int __c, FILE *__stream) __THROW
{
return _IO_putc_unlocked (__c, __stream);
}
/* This is defined in POSIX.1:1996. */
__STDIO_INLINE int
putchar_unlocked (int __c) __THROW
{
return _IO_putc_unlocked (__c, stdout);
}
# endif /* POSIX || misc */
# ifdef __USE_GNU
/* Like `getdelim', but reads up to a newline. */
__STDIO_INLINE _IO_ssize_t
getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW
{
return __getdelim (__lineptr, __n, '\n', __stream);
}
# endif /* GNU */
# ifdef __USE_MISC
/* Faster versions when locking is not required. */
__STDIO_INLINE int
feof_unlocked (FILE *__stream) __THROW
{
return _IO_feof_unlocked (__stream);
}
/* Faster versions when locking is not required. */
__STDIO_INLINE int
ferror_unlocked (FILE *__stream) __THROW
{
return _IO_ferror_unlocked (__stream);
}
# endif /* misc */
#endif /* Use extern inlines. */
#if defined __USE_MISC && defined __GNUC__ && defined __OPTIMIZE__
/* Perform some simple optimizations. */
# define fread_unlocked(ptr, size, n, stream) \
(__extension__ ((__builtin_constant_p (size) && __builtin_constant_p (n) \
&& (size_t) ((size) * (n)) <= 8 && (size) != 0) \
? ({ char *__ptr = (char *) (ptr); \
FILE *__stream = (stream); \
size_t __cnt; \
for (__cnt = (size) * (n); __cnt > 0; --__cnt) \
{ \
int __c = _IO_getc_unlocked (__stream); \
if (__c == EOF) \
break; \
*__ptr++ = __c; \
} \
((size_t) ((size) * (n)) - __cnt) / (size); }) \
: (((__builtin_constant_p (size) && (size) == 0) \
|| (__builtin_constant_p (n) && (n) == 0)) \
/* Evaluate all parameters once. */ \
? ((void) (ptr), (void) (stream), (void) (size), \
(void) (n), 0) \
: fread_unlocked (ptr, size, n, stream))))
# define fwrite_unlocked(ptr, size, n, stream) \
(__extension__ ((__builtin_constant_p (size) && __builtin_constant_p (n) \
&& (size_t) ((size) * (n)) <= 8 && (size) != 0) \
? ({ const char *__ptr = (const char *) (ptr); \
FILE *__stream = (stream); \
size_t __cnt; \
for (__cnt = (size) * (n); __cnt > 0; --__cnt) \
if (_IO_putc_unlocked (*__ptr++, __stream) == EOF) \
break; \
((size_t) ((size) * (n)) - __cnt) / (size); }) \
: (((__builtin_constant_p (size) && (size) == 0) \
|| (__builtin_constant_p (n) && (n) == 0)) \
/* Evaluate all parameters once. */ \
? ((void) (ptr), (void) (stream), (void) (size), n) \
: fwrite_unlocked (ptr, size, n, stream))))
#endif
/* Define helper macro. */
#undef __STDIO_INLINE

View File

@ -0,0 +1,34 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#include "libioP.h"
#include "stdio.h"
void
clearerr (fp)
FILE *fp;
{
CHECK_FILE (fp, /*nothing*/);
_IO_flockfile (fp);
_IO_clearerr (fp);
_IO_funlockfile (fp);
}
#if defined weak_alias && !defined _IO_MTSAFE_IO
weak_alias (clearerr, clearerr_unlocked)
#endif

View File

@ -0,0 +1,28 @@
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#include "libioP.h"
#include "stdio.h"
void
clearerr_unlocked (fp)
FILE *fp;
{
CHECK_FILE (fp, /*nothing*/);
_IO_clearerr (fp);
}

View File

@ -0,0 +1,40 @@
/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
int
__fcloseall ()
{
/* Close all streams. */
return _IO_cleanup ();
}
#ifdef weak_alias
weak_alias (__fcloseall, fcloseall)
#endif

View File

@ -0,0 +1,50 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
int
_IO_feof (fp)
_IO_FILE* fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_flockfile (fp);
result = _IO_feof_unlocked (fp);
_IO_funlockfile (fp);
return result;
}
#ifdef weak_alias
weak_alias (_IO_feof, feof)
#ifndef _IO_MTSAFE_IO
#undef feof_unlocked
weak_alias (_IO_feof, feof_unlocked)
#endif
#endif

View File

@ -0,0 +1,39 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#undef feof_unlocked
int
feof_unlocked (fp)
_IO_FILE* fp;
{
CHECK_FILE (fp, EOF);
return _IO_feof_unlocked (fp);
}

View File

@ -0,0 +1,50 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
int
_IO_ferror (fp)
_IO_FILE* fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_flockfile (fp);
result = _IO_ferror_unlocked (fp);
_IO_funlockfile (fp);
return result;
}
#ifdef weak_alias
weak_alias (_IO_ferror, ferror)
#ifndef _IO_MTSAFE_IO
#undef ferror_unlocked
weak_alias (_IO_ferror, ferror_unlocked)
#endif
#endif

View File

@ -0,0 +1,39 @@
/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#undef ferror_unlocked
int
ferror_unlocked (fp)
_IO_FILE* fp;
{
CHECK_FILE (fp, EOF);
return _IO_ferror_unlocked (fp);
}

View File

@ -0,0 +1,124 @@
/* Copyright (C) 1993, 1997, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
/*
Copyright (C) 1990 The Regents of the University of California.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
4. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.*/
/* Modified for GNU iostream by Per Bothner 1991, 1992. */
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h"
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __STDC__
#include <stdlib.h>
#include <unistd.h>
#endif
#ifdef _LIBC
# undef isatty
# define isatty(Fd) __isatty (Fd)
# include <device-nrs.h>
#endif
/*
* Allocate a file buffer, or switch to unbuffered I/O.
* Per the ANSI C standard, ALL tty devices default to line buffered.
*
* As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
* optimisation) right after the _fstat() that finds the buffer size.
*/
int
_IO_file_doallocate (fp)
_IO_FILE *fp;
{
_IO_size_t size;
char *p;
struct _G_stat64 st;
#ifndef _LIBC
/* If _IO_cleanup_registration_needed is non-zero, we should call the
function it points to. This is to make sure _IO_cleanup gets called
on exit. We call it from _IO_file_doallocate, since that is likely
to get called by any program that does buffered I/O. */
if (__builtin_expect (_IO_cleanup_registration_needed != NULL, 0))
(*_IO_cleanup_registration_needed) ();
#endif
size = _IO_BUFSIZ;
if (fp->_fileno >= 0 && __builtin_expect (_IO_SYSSTAT (fp, &st), 0) >= 0)
{
if (S_ISCHR (st.st_mode))
{
/* Possibly a tty. */
if (
#ifdef DEV_TTY_P
DEV_TTY_P (&st) ||
#endif
isatty (fp->_fileno))
fp->_flags |= _IO_LINE_BUF;
}
#if _IO_HAVE_ST_BLKSIZE
if (st.st_blksize > 0)
size = st.st_blksize;
#endif
}
ALLOC_BUF (p, size, EOF);
INTUSE(_IO_setb) (fp, p, p + size, 1);
return 1;
}
INTDEF(_IO_file_doallocate)

View File

@ -0,0 +1,53 @@
/* Copyright (C) 1993,95,96,97,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
int
fileno (fp)
_IO_FILE* fp;
{
CHECK_FILE (fp, EOF);
if (!(fp->_flags & _IO_IS_FILEBUF) || _IO_fileno (fp) < 0)
{
__set_errno (EBADF);
return -1;
}
return _IO_fileno (fp);
}
libc_hidden_def (fileno)
#ifdef weak_alias
/* The fileno implementation for libio does not require locking because
it only accesses once a single variable and this is already atomic
(at least at thread level). Therefore we don't test _IO_MTSAFE_IO here. */
weak_alias (fileno, fileno_unlocked)
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,243 @@
/* Fmemopen implementation.
Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Hanno Mueller, kontakt@hanno.de, 2000.
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. */
/*
* fmemopen() - "my" version of a string stream
* Hanno Mueller, kontakt@hanno.de
*
*
* I needed fmemopen() for an application that I currently work on,
* but couldn't find it in libio. The following snippet of code is an
* attempt to implement what glibc's documentation describes.
*
* No, it isn't really tested yet. :-)
*
*
*
* I already see some potential problems:
*
* - I never used the "original" fmemopen(). I am sure that "my"
* fmemopen() behaves differently than the original version.
*
* - The documentation doesn't say wether a string stream allows
* seeks. I checked the old fmemopen implementation in glibc's stdio
* directory, wasn't quite able to see what is going on in that
* source, but as far as I understand there was no seek there. For
* my application, I needed fseek() and ftell(), so it's here.
*
* - "append" mode and fseek(p, SEEK_END) have two different ideas
* about the "end" of the stream.
*
* As described in the documentation, when opening the file in
* "append" mode, the position pointer will be set to the first null
* character of the string buffer (yet the buffer may already
* contain more data). For fseek(), the last byte of the buffer is
* used as the end of the stream.
*
* - It is unclear to me what the documentation tries to say when it
* explains what happens when you use fmemopen with a NULL
* buffer.
*
* Quote: "fmemopen [then] allocates an array SIZE bytes long. This
* is really only useful if you are going to write things to the
* buffer and then read them back in again."
*
* What does that mean if the original fmemopen() did not allow
* seeking? How do you read what you just wrote without seeking back
* to the beginning of the stream?
*
* - I think there should be a second version of fmemopen() that does
* not add null characters for each write. (At least in my
* application, I am not actually using strings but binary data and
* so I don't need the stream to add null characters on its own.)
*/
#include <errno.h>
#include <libio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "libioP.h"
typedef struct fmemopen_cookie_struct fmemopen_cookie_t;
struct fmemopen_cookie_struct
{
char *buffer;
int mybuffer;
size_t size;
_IO_off64_t pos;
size_t maxpos;
};
static ssize_t
fmemopen_read (void *cookie, char *b, size_t s)
{
fmemopen_cookie_t *c;
c = (fmemopen_cookie_t *) cookie;
if (c->pos + s > c->size)
{
if ((size_t) c->pos == c->size)
return 0;
s = c->size - c->pos;
}
memcpy (b, &(c->buffer[c->pos]), s);
c->pos += s;
if ((size_t) c->pos > c->maxpos)
c->maxpos = c->pos;
return s;
}
static ssize_t
fmemopen_write (void *cookie, const char *b, size_t s)
{
fmemopen_cookie_t *c;
int addnullc;
c = (fmemopen_cookie_t *) cookie;
addnullc = s == 0 || b[s - 1] != '\0';
if (c->pos + s + addnullc > c->size)
{
if ((size_t) (c->pos + addnullc) == c->size)
{
__set_errno (ENOSPC);
return -1;
}
s = c->size - c->pos - addnullc;
}
memcpy (&(c->buffer[c->pos]), b, s);
c->pos += s;
if ((size_t) c->pos > c->maxpos)
{
c->maxpos = c->pos;
if (addnullc)
c->buffer[c->maxpos] = '\0';
}
return s;
}
static int
fmemopen_seek (void *cookie, _IO_off64_t *p, int w)
{
_IO_off64_t np;
fmemopen_cookie_t *c;
c = (fmemopen_cookie_t *) cookie;
switch (w)
{
case SEEK_SET:
np = *p;
break;
case SEEK_CUR:
np = c->pos + *p;
break;
case SEEK_END:
np = c->size - *p;
break;
default:
return -1;
}
if (np < 0 || (size_t) np > c->size)
return -1;
c->pos = np;
return np;
}
static int
fmemopen_close (void *cookie)
{
fmemopen_cookie_t *c;
c = (fmemopen_cookie_t *) cookie;
if (c->mybuffer)
free (c->buffer);
free (c);
return 0;
}
FILE *
fmemopen (void *buf, size_t len, const char *mode)
{
cookie_io_functions_t iof;
fmemopen_cookie_t *c;
c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t));
if (c == NULL)
return NULL;
c->mybuffer = (buf == NULL);
if (c->mybuffer)
{
c->buffer = (char *) malloc (len);
if (c->buffer == NULL)
{
free (c);
return NULL;
}
c->buffer[0] = '\0';
}
else
c->buffer = buf;
c->size = len;
if (mode[0] == 'w')
c->buffer[0] = '\0';
c->maxpos = strlen (c->buffer);
if (mode[0] == 'a')
c->pos = c->maxpos;
else
c->pos = 0;
iof.read = fmemopen_read;
iof.write = fmemopen_write;
iof.seek = fmemopen_seek;
iof.close = fmemopen_close;
return _IO_fopencookie (c, mode, iof);
}

View File

@ -0,0 +1,49 @@
/* Copyright (C) 1993, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
int
fputc (c, fp)
int c;
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_putc_unlocked (c, fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
#if defined weak_alias && !defined _IO_MTSAFE_IO
#undef fputc_unlocked
weak_alias (fputc, fputc_unlocked)
#endif

View File

@ -0,0 +1,40 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#undef fputc_unlocked
int
fputc_unlocked (c, fp)
int c;
_IO_FILE *fp;
{
CHECK_FILE (fp, EOF);
return _IO_putc_unlocked (c, fp);
}

View File

@ -0,0 +1,47 @@
/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
wint_t
fputwc (wc, fp)
wchar_t wc;
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_fwide (fp, 1) < 0)
result = WEOF;
else
result = _IO_putwc_unlocked (wc, fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,42 @@
/* Copyright (C) 1993, 1996, 1997, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
#undef fputwc_unlocked
wint_t
fputwc_unlocked (wc, fp)
wchar_t wc;
_IO_FILE *fp;
{
CHECK_FILE (fp, EOF);
if (_IO_fwide (fp, 1) < 0)
return WEOF;
return _IO_putwc_unlocked (wc, fp);
}

View File

@ -0,0 +1,89 @@
/* Copyright (C) 1993,95,96,97,98,2000,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#include <stdlib.h>
#include <shlib-compat.h>
#include <fd_to_filename.h>
FILE*
freopen (filename, mode, fp)
const char* filename;
const char* mode;
FILE* fp;
{
FILE *result;
int fd = -1;
CHECK_FILE (fp, NULL);
if (!(fp->_flags & _IO_IS_FILEBUF))
return NULL;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (filename == NULL && _IO_fileno (fp) >= 0)
{
fd = __dup (_IO_fileno (fp));
if (fd != -1)
filename = fd_to_filename (fd);
}
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
if (&_IO_stdin_used == NULL)
{
/* If the shared C library is used by the application binary which
was linked against the older version of libio, we just use the
older one even for internal use to avoid trouble since a pointer
to the old libio may be passed into shared C library and wind
up here. */
_IO_old_file_close_it (fp);
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_old_file_jumps;
result = _IO_old_file_fopen (fp, filename, mode);
}
else
#endif
{
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);
result = INTUSE(_IO_file_fopen) (fp, filename, mode, 1);
if (result != NULL)
result = __fopen_maybe_mmap (result);
}
if (result != NULL)
/* unbound stream orientation */
result->_mode = 0;
if (fd != -1)
{
__close (fd);
if (filename != NULL)
free ((char *) filename);
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,78 @@
/* Copyright (C) 1993,1995,1996,1997,1998,2000,2001,2002
Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#include <stdlib.h>
#include <fd_to_filename.h>
FILE *
freopen64 (filename, mode, fp)
const char* filename;
const char* mode;
FILE *fp;
{
#ifdef _G_OPEN64
FILE *result;
int fd = -1;
CHECK_FILE (fp, NULL);
if (!(fp->_flags & _IO_IS_FILEBUF))
return NULL;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (filename == NULL && _IO_fileno (fp) >= 0)
{
fd = __dup (_IO_fileno (fp));
if (fd != -1)
filename = fd_to_filename (fd);
}
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);
result = INTUSE(_IO_file_fopen) (fp, filename, mode, 0);
if (result != NULL)
result = __fopen_maybe_mmap (result);
if (result != NULL)
/* unbound stream orientation */
result->_mode = 0;
if (fd != -1)
{
__close (fd);
if (filename != NULL)
free ((char *) filename);
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
#else
__set_errno (ENOSYS);
return NULL;
#endif
}

View File

@ -0,0 +1,46 @@
/* Copyright (C) 1993,1995,1996,1997,1998,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
int
fseek (fp, offset, whence)
_IO_FILE* fp;
long int offset;
int whence;
{
int result;
CHECK_FILE (fp, -1);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_fseek (fp, offset, whence);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
libc_hidden_def (fseek)

View File

@ -0,0 +1,45 @@
/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
int
fseeko (fp, offset, whence)
_IO_FILE* fp;
off_t offset;
int whence;
{
int result;
CHECK_FILE (fp, -1);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_fseek (fp, offset, whence);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,51 @@
/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <errno.h>
#include "libioP.h"
#include "stdio.h"
int
fseeko64 (fp, offset, whence)
_IO_FILE* fp;
__off64_t offset;
int whence;
{
#ifdef _G_LSEEK64
int result;
CHECK_FILE (fp, -1);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_fseek (fp, offset, whence);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
#else
__set_errno (ENOSYS);
return -1;
#endif
}

View File

@ -0,0 +1,66 @@
/* Copyright (C) 1993, 1995-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <libioP.h>
off_t
ftello (fp)
_IO_FILE *fp;
{
_IO_off64_t pos;
CHECK_FILE (fp, -1L);
_IO_cleanup_region_start ((void (*) (void *)) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
if (_IO_in_backup (fp))
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (pos == _IO_pos_BAD)
{
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
return -1L;
}
if ((_IO_off64_t) (off_t) pos != pos)
{
#ifdef EOVERFLOW
__set_errno (EOVERFLOW);
#endif
return -1L;
}
return pos;
}

View File

@ -0,0 +1,64 @@
/* Copyright (C) 1993, 1995-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <stdio.h>
#include <stdlib.h>
#include <libioP.h>
#include <errno.h>
off64_t
ftello64 (fp)
_IO_FILE *fp;
{
#ifdef _G_LSEEK64
_IO_off64_t pos;
CHECK_FILE (fp, -1L);
_IO_cleanup_region_start ((void (*) (void *)) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
if (_IO_in_backup (fp))
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (pos == _IO_pos_BAD)
{
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
return -1L;
}
return pos;
#else
__set_errno (ENOSYS);
return -1;
#endif
}

View File

@ -0,0 +1,56 @@
/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#include <stdio.h>
#include <wchar.h>
int
fwide (fp, mode)
_IO_FILE *fp;
int mode;
{
int result;
/* 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;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_fwide (fp, mode);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,38 @@
/* Copyright (C) 1991, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
/* Write formatted output to STREAM from the format string FORMAT. */
/* VARARGS2 */
int
__fwprintf (FILE *stream, const wchar_t *format, ...)
{
va_list arg;
int done;
va_start (arg, format);
done = __vfwprintf (stream, format, arg);
va_end (arg);
return done;
}
weak_alias (__fwprintf, fwprintf)

View File

@ -0,0 +1,36 @@
/* Copyright (C) 1991, 1997, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
/* Read formatted input from STREAM according to the format string FORMAT. */
/* VARARGS2 */
int
fwscanf (FILE *stream, const wchar_t *format, ...)
{
va_list arg;
int done;
va_start (arg, format);
done = __vfwscanf (stream, format, arg);
va_end (arg);
return done;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#undef _IO_getc
int
_IO_getc (fp)
FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_getc_unlocked (fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
#undef getc
#ifdef weak_alias
weak_alias (_IO_getc, getc)
weak_alias (_IO_getc, fgetc)
#ifndef _IO_MTSAFE_IO
#undef getc_unlocked
weak_alias (_IO_getc, getc_unlocked)
weak_alias (_IO_getc, fgetc_unlocked)
#endif
#endif

View File

@ -0,0 +1,41 @@
/* Copyright (C) 1993,1995,1996,1997,1999,2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
#undef getc_unlocked
int
__getc_unlocked (FILE *fp)
{
CHECK_FILE (fp, EOF);
return _IO_getc_unlocked (fp);
}
weak_alias (__getc_unlocked, getc_unlocked)
weak_alias (__getc_unlocked, fgetc_unlocked)

View File

@ -0,0 +1,49 @@
/* Copyright (C) 1993, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#undef getchar
int
getchar ()
{
int result;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
_IO_stdin);
_IO_flockfile (_IO_stdin);
result = _IO_getc_unlocked (_IO_stdin);
_IO_funlockfile (_IO_stdin);
_IO_cleanup_region_end (0);
return result;
}
#if defined weak_alias && !defined _IO_MTSAFE_IO
#undef getchar_unlocked
weak_alias (getchar, getchar_unlocked)
#endif

View File

@ -0,0 +1,37 @@
/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#undef getchar_unlocked
int
getchar_unlocked ()
{
return _IO_getc_unlocked (_IO_stdin);
}

View File

@ -0,0 +1,53 @@
/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
#include <wchar.h>
#undef _IO_getwc
wint_t
_IO_getwc (fp)
FILE *fp;
{
wint_t result;
CHECK_FILE (fp, WEOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_getwc_unlocked (fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
#undef getwc
#ifdef weak_alias
weak_alias (_IO_getwc, getwc)
weak_alias (_IO_getwc, fgetwc)
#endif

View File

@ -0,0 +1,41 @@
/* Copyright (C) 1993,1995,1996,1997,1999,2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
#undef getwc_unlocked
wint_t
__getwc_unlocked (FILE *fp)
{
CHECK_FILE (fp, EOF);
return _IO_getwc_unlocked (fp);
}
weak_alias (__getwc_unlocked, getwc_unlocked)
weak_alias (__getwc_unlocked, fgetwc_unlocked)

View File

@ -0,0 +1,44 @@
/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
#undef getwchar
wint_t
getwchar ()
{
wint_t result;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
_IO_stdin);
_IO_flockfile (_IO_stdin);
result = _IO_getwc_unlocked (_IO_stdin);
_IO_funlockfile (_IO_stdin);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,37 @@
/* Copyright (C) 1993, 1996, 1997, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
#undef getwchar_unlocked
wint_t
getwchar_unlocked ()
{
return _IO_getwc_unlocked (_IO_stdin);
}

View File

@ -0,0 +1,98 @@
/* Copyright (C) 1993,1995,1997-2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#ifdef __STDC__
#include <stdlib.h>
#endif
#if _LIBC
# include "../iconv/gconv_int.h"
# include <shlib-compat.h>
#else
# define SHLIB_COMPAT(a, b, c) 0
# define _IO_new_fclose fclose
#endif
int
_IO_new_fclose (fp)
_IO_FILE *fp;
{
int status;
CHECK_FILE(fp, EOF);
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
/* We desperately try to help programs which are using streams in a
strange way and mix old and new functions. Detect old streams
here. */
if (fp->_vtable_offset != 0)
return _IO_old_fclose (fp);
#endif
/* First unlink the stream. */
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
status = INTUSE(_IO_file_close_it) (fp);
else
status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
_IO_FINISH (fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (fp->_mode > 0)
{
#if _LIBC
/* This stream has a wide orientation. This means we have to free
the conversion functions. */
struct _IO_codecvt *cc = fp->_codecvt;
__gconv_release_step (cc->__cd_in.__cd.__steps);
__gconv_release_step (cc->__cd_out.__cd.__steps);
#endif
}
else
{
if (_IO_have_backup (fp))
INTUSE(_IO_free_backup_area) (fp);
}
if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
{
fp->_IO_file_flags = 0;
free(fp);
}
return status;
}
#ifdef _LIBC
versioned_symbol (libc, _IO_new_fclose, _IO_fclose, GLIBC_2_1);
strong_alias (_IO_new_fclose, __new_fclose)
versioned_symbol (libc, __new_fclose, fclose, GLIBC_2_1);
#endif

View File

@ -0,0 +1,184 @@
/* Copyright (C) 1993,1994,1997-1999,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#ifdef __STDC__
# include <stdlib.h>
#endif
#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;
{
int read_write;
int posix_mode = 0;
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
struct _IO_wide_data wd;
} *new_f;
int fd_flags;
int i;
int use_mmap = 0;
switch (*mode)
{
case 'r':
read_write = _IO_NO_WRITES;
break;
case 'w':
read_write = _IO_NO_READS;
break;
case 'a':
posix_mode = O_APPEND;
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
MAYBE_SET_EINVAL;
return NULL;
}
for (i = 1; i < 5; ++i)
{
switch (*++mode)
{
case '\0':
break;
case '+':
read_write &= _IO_IS_APPENDING;
break;
case 'm':
use_mmap = 1;
continue;
case 'x':
case 'b':
default:
/* Ignore */
continue;
}
break;
}
#ifdef F_GETFL
fd_flags = _IO_fcntl (fd, F_GETFL);
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
if (fd_flags == -1)
return NULL;
if (((fd_flags & O_ACCMODE) == O_RDONLY && !(read_write & _IO_NO_WRITES))
|| ((fd_flags & O_ACCMODE) == O_WRONLY && !(read_write & _IO_NO_READS)))
{
MAYBE_SET_EINVAL;
return NULL;
}
/* The May 93 draft of P1003.4/D14.1 (redesignated as 1003.1b)
[System Application Program Interface (API) Amendment 1:
Realtime Extensions], Rationale B.8.3.3
Open a Stream on a File Descriptor says:
Although not explicitly required by POSIX.1, a good
implementation of append ("a") mode would cause the
O_APPEND flag to be set.
(Historical implementations [such as Solaris2] do a one-time
seek in fdopen.)
However, we do not turn O_APPEND off if the mode is "w" (even
though that would seem consistent) because that would be more
likely to break historical programs.
*/
if ((posix_mode & O_APPEND) && !(fd_flags & O_APPEND))
{
#ifdef F_SETFL
if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
#endif
return NULL;
}
#endif
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fp.file._lock = &new_f->lock;
#endif
/* Set up initially to use the `maybe_mmap' jump tables rather than using
__fopen_maybe_mmap to do it, because we need them in place before we
call _IO_file_attach or else it will allocate a buffer immediately. */
_IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd,
#ifdef _G_HAVE_MMAP
(use_mmap && (read_write & _IO_NO_WRITES))
? &_IO_wfile_jumps_maybe_mmap :
#endif
&INTUSE(_IO_wfile_jumps));
_IO_JUMPS (&new_f->fp) =
#ifdef _G_HAVE_MMAP
(use_mmap && (read_write & _IO_NO_WRITES)) ? &_IO_file_jumps_maybe_mmap :
#endif
&INTUSE(_IO_file_jumps);
INTUSE(_IO_file_init) (&new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
#endif
if (INTUSE(_IO_file_attach) ((_IO_FILE *) &new_f->fp, fd) == NULL)
{
INTUSE(_IO_setb) (&new_f->fp.file, NULL, NULL, 0);
INTUSE(_IO_un_link) (&new_f->fp);
free (new_f);
return NULL;
}
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
new_f->fp.file._IO_file_flags =
_IO_mask_flags (&new_f->fp.file, read_write,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
return &new_f->fp.file;
}
INTDEF2(_IO_new_fdopen, _IO_fdopen)
strong_alias (_IO_new_fdopen, __new_fdopen)
versioned_symbol (libc, _IO_new_fdopen, _IO_fdopen, GLIBC_2_1);
versioned_symbol (libc, __new_fdopen, fdopen, GLIBC_2_1);

View File

@ -0,0 +1,58 @@
/* Copyright (C) 1993,1995,1996,1997,1998,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
int
_IO_fflush (fp)
_IO_FILE *fp;
{
if (fp == NULL)
return INTUSE(_IO_flush_all) ();
else
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_SYNC (fp) ? EOF : 0;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
}
INTDEF(_IO_fflush)
#ifdef weak_alias
weak_alias (_IO_fflush, fflush)
#ifndef _IO_MTSAFE_IO
weak_alias (_IO_fflush, fflush_unlocked)
libc_hidden_weak (fflush_unlocked)
#endif
#endif

View File

@ -0,0 +1,43 @@
/* Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
int
fflush_unlocked (fp)
_IO_FILE *fp;
{
if (fp == NULL)
return INTUSE(_IO_flush_all) ();
else
{
CHECK_FILE (fp, EOF);
return _IO_SYNC (fp) ? EOF : 0;
}
}
libc_hidden_def (fflush_unlocked)

View File

@ -0,0 +1,82 @@
/* Copyright (C) 1993, 1995-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <errno.h>
#include <stdlib.h>
#include <shlib-compat.h>
int
_IO_new_fgetpos (fp, posp)
_IO_FILE *fp;
_IO_fpos_t *posp;
{
_IO_off64_t pos;
int result = 0;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
if (_IO_in_backup (fp))
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
}
if (pos == _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
result = EOF;
}
else if ((_IO_off64_t) (__typeof (posp->__pos)) pos != pos)
{
#ifdef EOVERFLOW
__set_errno (EOVERFLOW);
#endif
result = EOF;
}
else
{
posp->__pos = pos;
if (fp->_mode > 0
&& (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
/* This is a stateful encoding, safe the state. */
posp->__state = fp->_wide_data->_IO_state;
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
strong_alias (_IO_new_fgetpos, __new_fgetpos)
versioned_symbol (libc, _IO_new_fgetpos, _IO_fgetpos, GLIBC_2_2);
versioned_symbol (libc, __new_fgetpos, fgetpos, GLIBC_2_2);

View File

@ -0,0 +1,75 @@
/* Copyright (C) 1993, 1995-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <errno.h>
#include <shlib-compat.h>
int
_IO_new_fgetpos64 (fp, posp)
_IO_FILE *fp;
_IO_fpos64_t *posp;
{
#ifdef _G_LSEEK64
_IO_off64_t pos;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) (void *)) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
if (_IO_in_backup (fp))
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (pos == _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
# ifdef EIO
if (errno == 0)
__set_errno (EIO);
# endif
return EOF;
}
posp->__pos = pos;
if (fp->_mode > 0
&& (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
/* This is a stateful encoding, safe the state. */
posp->__state = fp->_wide_data->_IO_state;
return 0;
#else
__set_errno (ENOSYS);
return EOF;
#endif
}
strong_alias (_IO_new_fgetpos64, __new_fgetpos64)
versioned_symbol (libc, _IO_new_fgetpos64, _IO_fgetpos64, GLIBC_2_2);
versioned_symbol (libc, __new_fgetpos64, fgetpos64, GLIBC_2_2);

View File

@ -0,0 +1,74 @@
/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
char *
_IO_fgets (buf, n, fp)
char *buf;
int n;
_IO_FILE *fp;
{
_IO_size_t count;
char *result;
int old_error;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
/* This is very tricky since a file descriptor may be in the
non-blocking mode. The error flag doesn't mean much in this
case. We return an error only when there is a new error. */
old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
fp->_IO_file_flags &= ~_IO_ERR_SEEN;
count = INTUSE(_IO_getline) (fp, buf, n - 1, '\n', 1);
/* If we read in some bytes and errno is EAGAIN, that error will
be reported for next read. */
if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN)
&& errno != EAGAIN))
result = NULL;
else
{
buf[count] = '\0';
result = buf;
}
fp->_IO_file_flags |= old_error;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
#ifdef weak_alias
weak_alias (_IO_fgets, fgets)
# ifndef _IO_MTSAFE_IO
weak_alias (_IO_fgets, fgets_unlocked)
libc_hidden_weak (fgets_unlocked)
# endif
#endif

View File

@ -0,0 +1,62 @@
/* Copyright (C) 1993,1995,1996,1997,1998,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
char *
fgets_unlocked (buf, n, fp)
char *buf;
int n;
_IO_FILE *fp;
{
_IO_size_t count;
char *result;
int old_error;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
/* This is very tricky since a file descriptor may be in the
non-blocking mode. The error flag doesn't mean much in this
case. We return an error only when there is a new error. */
old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
fp->_IO_file_flags &= ~_IO_ERR_SEEN;
count = INTUSE(_IO_getline) (fp, buf, n - 1, '\n', 1);
/* If we read in some bytes and errno is EAGAIN, that error will
be reported for next read. */
if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN)
&& errno != EAGAIN))
result = NULL;
else
{
buf[count] = '\0';
result = buf;
}
fp->_IO_file_flags |= old_error;
return result;
}
libc_hidden_def (fgets_unlocked)

View File

@ -0,0 +1,64 @@
/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
wchar_t *
fgetws (buf, n, fp)
wchar_t *buf;
int n;
_IO_FILE *fp;
{
_IO_size_t count;
wchar_t *result;
int old_error;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
/* This is very tricky since a file descriptor may be in the
non-blocking mode. The error flag doesn't mean much in this
case. We return an error only when there is a new error. */
old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
fp->_IO_file_flags &= ~_IO_ERR_SEEN;
count = _IO_getwline (fp, buf, n - 1, L'\n', 1);
/* If we read in some bytes and errno is EAGAIN, that error will
be reported for next read. */
if (count == 0 || (_IO_ferror_unlocked (fp) && errno != EAGAIN))
result = NULL;
else
{
buf[count] = '\0';
result = buf;
}
fp->_IO_file_flags |= old_error;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,61 @@
/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
wchar_t *
fgetws_unlocked (buf, n, fp)
wchar_t *buf;
int n;
_IO_FILE *fp;
{
_IO_size_t count;
wchar_t *result;
int old_error;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
/* This is very tricky since a file descriptor may be in the
non-blocking mode. The error flag doesn't mean much in this
case. We return an error only when there is a new error. */
old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
fp->_IO_file_flags &= ~_IO_ERR_SEEN;
count = _IO_getwline (fp, buf, n - 1, L'\n', 1);
/* If we read in some bytes and errno is EAGAIN, that error will
be reported for next read. */
if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN)
&& errno != EAGAIN))
result = NULL;
else
{
buf[count] = '\0';
result = buf;
}
fp->_IO_file_flags |= old_error;
return result;
}

View File

@ -0,0 +1,113 @@
/* Copyright (C) 1993,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#ifdef __STDC__
#include <stdlib.h>
#include <stddef.h>
#endif
#ifdef _LIBC
# include <shlib-compat.h>
#else
# define _IO_new_fopen fopen
#endif
_IO_FILE *
__fopen_maybe_mmap (fp)
_IO_FILE *fp;
{
#ifdef _G_HAVE_MMAP
if ((fp->_flags2 & _IO_FLAGS2_MMAP) && (fp->_flags & _IO_NO_WRITES))
{
/* Since this is read-only, we might be able to mmap the contents
directly. We delay the decision until the first read attempt by
giving it a jump table containing functions that choose mmap or
vanilla file operations and reset the jump table accordingly. */
if (fp->_mode <= 0)
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_file_jumps_maybe_mmap;
else
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_wfile_jumps_maybe_mmap;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_maybe_mmap;
}
#endif
return fp;
}
_IO_FILE *
__fopen_internal (filename, mode, is32)
const char *filename;
const char *mode;
int is32;
{
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
struct _IO_wide_data wd;
} *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fp.file._lock = &new_f->lock;
#endif
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
_IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd, &INTUSE(_IO_wfile_jumps));
#else
_IO_no_init (&new_f->fp.file, 1, 0, NULL, NULL);
#endif
_IO_JUMPS (&new_f->fp) = &INTUSE(_IO_file_jumps);
INTUSE(_IO_file_init) (&new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
#endif
if (INTUSE(_IO_file_fopen) ((_IO_FILE *) new_f, filename, mode, is32)
!= NULL)
return __fopen_maybe_mmap (&new_f->fp.file);
INTUSE(_IO_un_link) (&new_f->fp);
free (new_f);
return NULL;
}
_IO_FILE *
_IO_new_fopen (filename, mode)
const char *filename;
const char *mode;
{
return __fopen_internal (filename, mode, 1);
}
#ifdef _LIBC
strong_alias (_IO_new_fopen, __new_fopen)
versioned_symbol (libc, _IO_new_fopen, _IO_fopen, GLIBC_2_1);
versioned_symbol (libc, __new_fopen, fopen, GLIBC_2_1);
#endif

View File

@ -0,0 +1,48 @@
/* Copyright (C) 1993, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#ifdef __STDC__
#include <stdlib.h>
#endif
_IO_FILE *
_IO_fopen64 (filename, mode)
const char *filename;
const char *mode;
{
#ifdef _G_OPEN64
return __fopen_internal (filename, mode, 0);
#else
__set_errno (ENOSYS);
return NULL;
#endif
}
#ifdef weak_alias
weak_alias (_IO_fopen64, fopen64)
#endif

View File

@ -0,0 +1,256 @@
/* Copyright (C) 1993,95,97,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#include <stdio.h>
#include <stdlib.h>
#include <shlib-compat.h>
/* Prototyped for local functions. */
static _IO_ssize_t _IO_cookie_read (register _IO_FILE* fp, void* buf,
_IO_ssize_t size);
static _IO_ssize_t _IO_cookie_write (register _IO_FILE* fp,
const void* buf, _IO_ssize_t size);
static _IO_off64_t _IO_cookie_seek (_IO_FILE *fp, _IO_off64_t offset, int dir);
static int _IO_cookie_close (_IO_FILE* fp);
static _IO_ssize_t
_IO_cookie_read (fp, buf, size)
_IO_FILE *fp;
void *buf;
_IO_ssize_t size;
{
struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
if (cfile->__io_functions.read == NULL)
return -1;
return cfile->__io_functions.read (cfile->__cookie, buf, size);
}
static _IO_ssize_t
_IO_cookie_write (fp, buf, size)
_IO_FILE *fp;
const void *buf;
_IO_ssize_t size;
{
struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
if (cfile->__io_functions.write == NULL)
return -1;
return cfile->__io_functions.write (cfile->__cookie, buf, size);
}
static _IO_off64_t
_IO_cookie_seek (fp, offset, dir)
_IO_FILE *fp;
_IO_off64_t offset;
int dir;
{
struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
return ((cfile->__io_functions.seek == NULL
|| (cfile->__io_functions.seek (cfile->__cookie, &offset, dir)
== -1)
|| offset == (_IO_off64_t) -1)
? _IO_pos_BAD : offset);
}
static int
_IO_cookie_close (fp)
_IO_FILE *fp;
{
struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
if (cfile->__io_functions.close == NULL)
return 0;
return cfile->__io_functions.close (cfile->__cookie);
}
static struct _IO_jump_t _IO_cookie_jumps = {
JUMP_INIT_DUMMY,
JUMP_INIT(finish, INTUSE(_IO_file_finish)),
JUMP_INIT(overflow, INTUSE(_IO_file_overflow)),
JUMP_INIT(underflow, INTUSE(_IO_file_underflow)),
JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, INTUSE(_IO_file_xsputn)),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
JUMP_INIT(seekoff, INTUSE(_IO_file_seekoff)),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, INTUSE(_IO_file_setbuf)),
JUMP_INIT(sync, INTUSE(_IO_file_sync)),
JUMP_INIT(doallocate, INTUSE(_IO_file_doallocate)),
JUMP_INIT(read, _IO_cookie_read),
JUMP_INIT(write, _IO_cookie_write),
JUMP_INIT(seek, _IO_cookie_seek),
JUMP_INIT(close, _IO_cookie_close),
JUMP_INIT(stat, _IO_default_stat),
JUMP_INIT(showmanyc, _IO_default_showmanyc),
JUMP_INIT(imbue, _IO_default_imbue),
};
void
_IO_cookie_init (struct _IO_cookie_file *cfile, int read_write,
void *cookie, _IO_cookie_io_functions_t io_functions)
{
INTUSE(_IO_init) (&cfile->__fp.file, 0);
_IO_JUMPS (&cfile->__fp) = &_IO_cookie_jumps;
cfile->__cookie = cookie;
cfile->__io_functions = io_functions;
INTUSE(_IO_file_init) (&cfile->__fp);
cfile->__fp.file._IO_file_flags =
_IO_mask_flags (&cfile->__fp.file, read_write,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
/* We use a negative number different from -1 for _fileno to mark that
this special stream is not associated with a real file, but still has
to be treated as such. */
cfile->__fp.file._fileno = -2;
}
_IO_FILE *
_IO_fopencookie (cookie, mode, io_functions)
void *cookie;
const char *mode;
_IO_cookie_io_functions_t io_functions;
{
int read_write;
struct locked_FILE
{
struct _IO_cookie_file cfile;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f;
switch (*mode++)
{
case 'r':
read_write = _IO_NO_WRITES;
break;
case 'w':
read_write = _IO_NO_READS;
break;
case 'a':
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
read_write &= _IO_IS_APPENDING;
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->cfile.__fp.file._lock = &new_f->lock;
#endif
_IO_cookie_init (&new_f->cfile, read_write, cookie, io_functions);
return (_IO_FILE *) &new_f->cfile.__fp;
}
versioned_symbol (libc, _IO_fopencookie, fopencookie, GLIBC_2_2);
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
static _IO_off64_t _IO_old_cookie_seek (_IO_FILE *fp, _IO_off64_t offset,
int dir);
_IO_FILE * _IO_old_fopencookie (void *cookie, const char *mode,
_IO_cookie_io_functions_t io_functions);
static _IO_off64_t
_IO_old_cookie_seek (fp, offset, dir)
_IO_FILE *fp;
_IO_off64_t offset;
int dir;
{
struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;
int (*seek) (_IO_FILE *, _IO_off_t, int);
int ret;
seek = (int (*)(_IO_FILE *, _IO_off_t, int)) cfile->__io_functions.seek;
if (seek == NULL)
return _IO_pos_BAD;
ret = seek (cfile->__cookie, offset, dir);
return (ret == -1) ? _IO_pos_BAD : ret;
}
static struct _IO_jump_t _IO_old_cookie_jumps = {
JUMP_INIT_DUMMY,
JUMP_INIT(finish, INTUSE(_IO_file_finish)),
JUMP_INIT(overflow, INTUSE(_IO_file_overflow)),
JUMP_INIT(underflow, INTUSE(_IO_file_underflow)),
JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, INTUSE(_IO_file_xsputn)),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
JUMP_INIT(seekoff, INTUSE(_IO_file_seekoff)),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, INTUSE(_IO_file_setbuf)),
JUMP_INIT(sync, INTUSE(_IO_file_sync)),
JUMP_INIT(doallocate, INTUSE(_IO_file_doallocate)),
JUMP_INIT(read, _IO_cookie_read),
JUMP_INIT(write, _IO_cookie_write),
JUMP_INIT(seek, _IO_old_cookie_seek),
JUMP_INIT(close, _IO_cookie_close),
JUMP_INIT(stat, _IO_default_stat),
JUMP_INIT(showmanyc, _IO_default_showmanyc),
JUMP_INIT(imbue, _IO_default_imbue),
};
_IO_FILE *
_IO_old_fopencookie (cookie, mode, io_functions)
void *cookie;
const char *mode;
_IO_cookie_io_functions_t io_functions;
{
_IO_FILE *ret;
ret = _IO_fopencookie (cookie, mode, io_functions);
if (ret != NULL)
_IO_JUMPS ((struct _IO_FILE_plus *) ret) = &_IO_old_cookie_jumps;
return ret;
}
compat_symbol (libc, _IO_old_fopencookie, fopencookie, GLIBC_2_0);
#endif

View File

@ -0,0 +1,57 @@
/* Copyright (C) 1993,1996,1997,1998,1999,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <string.h>
int
_IO_fputs (str, fp)
const char *str;
_IO_FILE *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);
if ((fp->_vtable_offset != 0 || _IO_fwide (fp, -1) == -1)
&& _IO_sputn (fp, str, len) == len)
result = 1;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
libc_hidden_def (_IO_fputs)
#ifdef weak_alias
weak_alias (_IO_fputs, fputs)
# ifndef _IO_MTSAFE_IO
weak_alias (_IO_fputs, fputs_unlocked)
libc_hidden_ver (_IO_fputs, fputs_unlocked)
# endif
#endif

View File

@ -0,0 +1,44 @@
/* Copyright (C) 1993,1996,1997,1998,1999,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
#include <string.h>
int
fputs_unlocked (str, fp)
const char *str;
_IO_FILE *fp;
{
_IO_size_t len = strlen (str);
int result = EOF;
CHECK_FILE (fp, EOF);
if (_IO_fwide (fp, -1) == -1 && _IO_sputn (fp, str, len) == len)
result = 1;
return result;
}
libc_hidden_def (fputs_unlocked)

View File

@ -0,0 +1,47 @@
/* Copyright (C) 1993,1996,1997,1998,1999,2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
int
fputws (str, fp)
const wchar_t *str;
_IO_FILE *fp;
{
_IO_size_t len = __wcslen (str);
int result = EOF;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_fwide (fp, 1) == 1
&& _IO_sputn (fp, (char *) str, len) == len)
result = 1;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,45 @@
/* Copyright (C) 1993, 1996-2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
#include <wchar.h>
int
fputws_unlocked (str, fp)
const wchar_t *str;
_IO_FILE *fp;
{
_IO_size_t len = __wcslen (str);
int result = EOF;
CHECK_FILE (fp, EOF);
if (_IO_fwide (fp, 1) == 1
&& _IO_sputn (fp, (char *) str, len) == len)
result = 1;
return result;
}
libc_hidden_def (fputws_unlocked)

View File

@ -0,0 +1,58 @@
/* Copyright (C) 1993,1995,1997,1998,1999,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
_IO_size_t
_IO_fread (buf, size, count, fp)
void *buf;
_IO_size_t size;
_IO_size_t count;
_IO_FILE *fp;
{
_IO_size_t bytes_requested = size * count;
_IO_size_t bytes_read;
CHECK_FILE (fp, 0);
if (bytes_requested == 0)
return 0;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
bytes_read = INTUSE(_IO_sgetn) (fp, (char *) buf, bytes_requested);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return bytes_requested == bytes_read ? count : bytes_read / size;
}
INTDEF(_IO_fread)
#ifdef weak_alias
weak_alias (_IO_fread, fread)
# ifndef _IO_MTSAFE_IO
weak_alias (_IO_fread, fread_unlocked)
libc_hidden_ver (_IO_fread, fread_unlocked)
# endif
#endif

View File

@ -0,0 +1,48 @@
/* Copyright (C) 1993, 1995, 1997, 1998, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
#undef fread_unlocked
_IO_size_t
fread_unlocked (buf, size, count, fp)
void *buf;
_IO_size_t size;
_IO_size_t count;
_IO_FILE *fp;
{
_IO_size_t bytes_requested = size * count;
_IO_size_t bytes_read;
CHECK_FILE (fp, 0);
if (bytes_requested == 0)
return 0;
bytes_read = INTUSE(_IO_sgetn) (fp, (char *) buf, bytes_requested);
return bytes_requested == bytes_read ? count : bytes_read / size;
}
libc_hidden_def (fread_unlocked)

View File

@ -0,0 +1,67 @@
/* Copyright (C) 1993, 1995, 1997-2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#include <errno.h>
#include <shlib-compat.h>
int
_IO_new_fsetpos (fp, posp)
_IO_FILE *fp;
const _IO_fpos_t *posp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_seekpos_unlocked (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
result = EOF;
}
else
{
result = 0;
if (fp->_mode > 0
&& (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
/* This is a stateful encoding, restore the state. */
fp->_wide_data->_IO_state = posp->__state;
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
strong_alias (_IO_new_fsetpos, __new_fsetpos)
versioned_symbol (libc, _IO_new_fsetpos, _IO_fsetpos, GLIBC_2_2);
versioned_symbol (libc, __new_fsetpos, fsetpos, GLIBC_2_2);

View File

@ -0,0 +1,72 @@
/* Copyright (C) 1993, 1995, 1997-2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#include <errno.h>
#include <shlib-compat.h>
int
_IO_new_fsetpos64 (fp, posp)
_IO_FILE *fp;
const _IO_fpos64_t *posp;
{
#ifdef _G_LSEEK64
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_seekpos_unlocked (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
result = EOF;
}
else
{
result = 0;
if (fp->_mode > 0
&& (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
/* This is a stateful encoding, safe the state. */
fp->_wide_data->_IO_state = posp->__state;
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
#else
__set_errno (ENOSYS);
return EOF;
#endif
}
strong_alias (_IO_new_fsetpos64, __new_fsetpos64)
versioned_symbol (libc, __new_fsetpos64, fsetpos64, GLIBC_2_2);
versioned_symbol (libc, _IO_new_fsetpos64, _IO_fsetpos64, GLIBC_2_2);

View File

@ -0,0 +1,70 @@
/* Copyright (C) 1993, 1995-2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdlib.h>
#include <errno.h>
/* ANSI explicily requires setting errno to a positive value on failure. */
long int
_IO_ftell (fp)
_IO_FILE *fp;
{
_IO_off64_t pos;
CHECK_FILE (fp, -1L);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
if (_IO_in_backup (fp))
{
if (fp->_vtable_offset != 0 || fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
}
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (pos == _IO_pos_BAD)
{
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
return -1L;
}
if ((_IO_off64_t) (off_t) pos != pos)
{
#ifdef EOVERFLOW
__set_errno (EOVERFLOW);
#endif
return -1L;
}
return pos;
}
INTDEF(_IO_ftell)
#ifdef weak_alias
weak_alias (_IO_ftell, ftell)
#endif

View File

@ -0,0 +1,498 @@
/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#ifdef _LIBC
# include <dlfcn.h>
# include <wchar.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#ifdef _LIBC
# include <langinfo.h>
# include <locale/localeinfo.h>
# include <wcsmbs/wcsmbsload.h>
# include <iconv/gconv_int.h>
# include <shlib-compat.h>
#endif
/* Prototypes of libio's codecvt functions. */
static enum __codecvt_result do_out (struct _IO_codecvt *codecvt,
__mbstate_t *statep,
const wchar_t *from_start,
const wchar_t *from_end,
const wchar_t **from_stop, char *to_start,
char *to_end, char **to_stop);
static enum __codecvt_result do_unshift (struct _IO_codecvt *codecvt,
__mbstate_t *statep, char *to_start,
char *to_end, char **to_stop);
static enum __codecvt_result do_in (struct _IO_codecvt *codecvt,
__mbstate_t *statep,
const char *from_start,
const char *from_end,
const char **from_stop, wchar_t *to_start,
wchar_t *to_end, wchar_t **to_stop);
static int do_encoding (struct _IO_codecvt *codecvt);
static int do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
const char *from_start,
const char *from_end, _IO_size_t max);
static int do_max_length (struct _IO_codecvt *codecvt);
static int do_always_noconv (struct _IO_codecvt *codecvt);
/* The functions used in `codecvt' for libio are always the same. */
struct _IO_codecvt __libio_codecvt =
{
.__codecvt_destr = NULL, /* Destructor, never used. */
.__codecvt_do_out = do_out,
.__codecvt_do_unshift = do_unshift,
.__codecvt_do_in = do_in,
.__codecvt_do_encoding = do_encoding,
.__codecvt_do_always_noconv = do_always_noconv,
.__codecvt_do_length = do_length,
.__codecvt_do_max_length = do_max_length
};
#ifdef _LIBC
struct __gconv_trans_data __libio_translit attribute_hidden =
{
.__trans_fct = __gconv_transliterate
};
#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);
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)
if (__builtin_expect (&_IO_stdin_used == NULL, 0)
&& (fp == _IO_stdin || fp == _IO_stdout || fp == _IO_stderr))
/* This is for a stream in the glibc 2.0 format. */
return -1;
#endif
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;
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. */
#ifdef _LIBC
{
struct gconv_fcts fcts;
/* Clear the state. We start all over again. */
memset (&fp->_wide_data->_IO_state, '\0', sizeof (__mbstate_t));
memset (&fp->_wide_data->_IO_last_state, '\0', sizeof (__mbstate_t));
__wcsmbs_clone_conv (&fcts);
assert (fcts.towc_nsteps == 1);
assert (fcts.tomb_nsteps == 1);
/* The functions are always the same. */
*cc = __libio_codecvt;
cc->__cd_in.__cd.__nsteps = fcts.towc_nsteps;
cc->__cd_in.__cd.__steps = fcts.towc;
cc->__cd_in.__cd.__data[0].__invocation_counter = 0;
cc->__cd_in.__cd.__data[0].__internal_use = 1;
cc->__cd_in.__cd.__data[0].__flags = __GCONV_IS_LAST;
cc->__cd_in.__cd.__data[0].__statep = &fp->_wide_data->_IO_state;
/* XXX For now no transliteration. */
cc->__cd_in.__cd.__data[0].__trans = NULL;
cc->__cd_out.__cd.__nsteps = fcts.tomb_nsteps;
cc->__cd_out.__cd.__steps = fcts.tomb;
cc->__cd_out.__cd.__data[0].__invocation_counter = 0;
cc->__cd_out.__cd.__data[0].__internal_use = 1;
cc->__cd_out.__cd.__data[0].__flags = __GCONV_IS_LAST;
cc->__cd_out.__cd.__data[0].__statep = &fp->_wide_data->_IO_state;
/* And now the transliteration. */
cc->__cd_out.__cd.__data[0].__trans = &__libio_translit;
}
#else
# ifdef _GLIBCPP_USE_WCHAR_T
{
/* Determine internal and external character sets.
XXX For now we make our life easy: we assume a fixed internal
encoding (as most sane systems have; hi HP/UX!). If somebody
cares about systems which changing internal charsets they
should come up with a solution for the determination of the
currently used internal character set. */
const char *internal_ccs = _G_INTERNAL_CCS;
const char *external_ccs = NULL;
# ifdef HAVE_NL_LANGINFO
external_ccs = nl_langinfo (CODESET);
# endif
if (external_ccs == NULL)
external_ccs = "ISO-8859-1";
cc->__cd_in = iconv_open (internal_ccs, external_ccs);
if (cc->__cd_in != (iconv_t) -1)
cc->__cd_out = iconv_open (external_ccs, internal_ccs);
if (cc->__cd_in == (iconv_t) -1 || cc->__cd_out == (iconv_t) -1)
{
if (cc->__cd_in != (iconv_t) -1)
iconv_close (cc->__cd_in);
/* XXX */
abort ();
}
}
# else
# error "somehow determine this from LC_CTYPE"
# endif
#endif
/* From now on use the wide character callback functions. */
((struct _IO_FILE_plus *) fp)->vtable = fp->_wide_data->_wide_vtable;
/* One last twist: we get the current stream position. The wide
char streams have much more problems with not knowing the
current position and so we should disable the optimization
which allows the functions without knowing the position. */
fp->_offset = _IO_SYSSEEK (fp, 0, _IO_seek_cur);
}
/* Set the mode now. */
fp->_mode = mode;
return mode;
}
static enum __codecvt_result
do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
const wchar_t *from_start, const wchar_t *from_end,
const wchar_t **from_stop, char *to_start, char *to_end,
char **to_stop)
{
enum __codecvt_result result;
#ifdef _LIBC
struct __gconv_step *gs = codecvt->__cd_out.__cd.__steps;
int status;
size_t dummy;
const unsigned char *from_start_copy = (unsigned char *) from_start;
codecvt->__cd_out.__cd.__data[0].__outbuf = to_start;
codecvt->__cd_out.__cd.__data[0].__outbufend = to_end;
codecvt->__cd_out.__cd.__data[0].__statep = statep;
status = DL_CALL_FCT (gs->__fct,
(gs, codecvt->__cd_out.__cd.__data, &from_start_copy,
(const unsigned char *) from_end, NULL,
&dummy, 0, 0));
*from_stop = (wchar_t *) from_start_copy;
*to_stop = codecvt->__cd_out.__cd.__data[0].__outbuf;
switch (status)
{
case __GCONV_OK:
case __GCONV_EMPTY_INPUT:
result = __codecvt_ok;
break;
case __GCONV_FULL_OUTPUT:
case __GCONV_INCOMPLETE_INPUT:
result = __codecvt_partial;
break;
default:
result = __codecvt_error;
break;
}
#else
# ifdef _GLIBCPP_USE_WCHAR_T
size_t res;
const char *from_start_copy = (const char *) from_start;
size_t from_len = from_end - from_start;
char *to_start_copy = to_start;
size_t to_len = to_end - to_start;
res = iconv (codecvt->__cd_out, &from_start_copy, &from_len,
&to_start_copy, &to_len);
if (res == 0 || from_len == 0)
result = __codecvt_ok;
else if (to_len < codecvt->__codecvt_do_max_length (codecvt))
result = __codecvt_partial;
else
result = __codecvt_error;
# else
/* Decide what to do. */
result = __codecvt_error;
# endif
#endif
return result;
}
static enum __codecvt_result
do_unshift (struct _IO_codecvt *codecvt, __mbstate_t *statep,
char *to_start, char *to_end, char **to_stop)
{
enum __codecvt_result result;
#ifdef _LIBC
struct __gconv_step *gs = codecvt->__cd_out.__cd.__steps;
int status;
size_t dummy;
codecvt->__cd_out.__cd.__data[0].__outbuf = to_start;
codecvt->__cd_out.__cd.__data[0].__outbufend = to_end;
codecvt->__cd_out.__cd.__data[0].__statep = statep;
status = DL_CALL_FCT (gs->__fct,
(gs, codecvt->__cd_out.__cd.__data, NULL, NULL,
NULL, &dummy, 1, 0));
*to_stop = codecvt->__cd_out.__cd.__data[0].__outbuf;
switch (status)
{
case __GCONV_OK:
case __GCONV_EMPTY_INPUT:
result = __codecvt_ok;
break;
case __GCONV_FULL_OUTPUT:
case __GCONV_INCOMPLETE_INPUT:
result = __codecvt_partial;
break;
default:
result = __codecvt_error;
break;
}
#else
# ifdef _GLIBCPP_USE_WCHAR_T
size_t res;
char *to_start_copy = (char *) to_start;
size_t to_len = to_end - to_start;
res = iconv (codecvt->__cd_out, NULL, NULL, &to_start_copy, &to_len);
if (res == 0)
result = __codecvt_ok;
else if (to_len < codecvt->__codecvt_do_max_length (codecvt))
result = __codecvt_partial;
else
result = __codecvt_error;
# else
/* Decide what to do. */
result = __codecvt_error;
# endif
#endif
return result;
}
static enum __codecvt_result
do_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
const char *from_start, const char *from_end, const char **from_stop,
wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop)
{
enum __codecvt_result result;
#ifdef _LIBC
struct __gconv_step *gs = codecvt->__cd_in.__cd.__steps;
int status;
size_t dummy;
const unsigned char *from_start_copy = (unsigned char *) from_start;
codecvt->__cd_in.__cd.__data[0].__outbuf = (char *) to_start;
codecvt->__cd_in.__cd.__data[0].__outbufend = (char *) to_end;
codecvt->__cd_in.__cd.__data[0].__statep = statep;
status = DL_CALL_FCT (gs->__fct,
(gs, codecvt->__cd_in.__cd.__data, &from_start_copy,
from_end, NULL, &dummy, 0, 0));
*from_stop = from_start_copy;
*to_stop = (wchar_t *) codecvt->__cd_in.__cd.__data[0].__outbuf;
switch (status)
{
case __GCONV_OK:
case __GCONV_EMPTY_INPUT:
result = __codecvt_ok;
break;
case __GCONV_FULL_OUTPUT:
case __GCONV_INCOMPLETE_INPUT:
result = __codecvt_partial;
break;
default:
result = __codecvt_error;
break;
}
#else
# ifdef _GLIBCPP_USE_WCHAR_T
size_t res;
const char *from_start_copy = (const char *) from_start;
size_t from_len = from_end - from_start;
char *to_start_copy = (char *) from_start;
size_t to_len = to_end - to_start;
res = iconv (codecvt->__cd_in, &from_start_copy, &from_len,
&to_start_copy, &to_len);
if (res == 0)
result = __codecvt_ok;
else if (to_len == 0)
result = __codecvt_partial;
else if (from_len < codecvt->__codecvt_do_max_length (codecvt))
result = __codecvt_partial;
else
result = __codecvt_error;
# else
/* Decide what to do. */
result = __codecvt_error;
# endif
#endif
return result;
}
static int
do_encoding (struct _IO_codecvt *codecvt)
{
#ifdef _LIBC
/* See whether the encoding is stateful. */
if (codecvt->__cd_in.__cd.__steps[0].__stateful)
return -1;
/* Fortunately not. Now determine the input bytes for the conversion
necessary for each wide character. */
if (codecvt->__cd_in.__cd.__steps[0].__min_needed_from
!= codecvt->__cd_in.__cd.__steps[0].__max_needed_from)
/* Not a constant value. */
return 0;
return codecvt->__cd_in.__cd.__steps[0].__min_needed_from;
#else
/* Worst case scenario. */
return -1;
#endif
}
static int
do_always_noconv (struct _IO_codecvt *codecvt)
{
return 0;
}
static int
do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
const char *from_start, const char *from_end, _IO_size_t max)
{
int result;
#ifdef _LIBC
const unsigned char *cp = (const unsigned char *) from_start;
wchar_t to_buf[max];
struct __gconv_step *gs = codecvt->__cd_in.__cd.__steps;
int status;
size_t dummy;
codecvt->__cd_in.__cd.__data[0].__outbuf = (char *) to_buf;
codecvt->__cd_in.__cd.__data[0].__outbufend = (char *) &to_buf[max];
codecvt->__cd_in.__cd.__data[0].__statep = statep;
status = DL_CALL_FCT (gs->__fct,
(gs, codecvt->__cd_in.__cd.__data, &cp, from_end,
NULL, &dummy, 0, 0));
result = cp - (const unsigned char *) from_start;
#else
# ifdef _GLIBCPP_USE_WCHAR_T
const char *from_start_copy = (const char *) from_start;
size_t from_len = from_end - from_start;
wchar_t to_buf[max];
size_t res;
char *to_start = (char *) to_buf;
res = iconv (codecvt->__cd_in, &from_start_copy, &from_len,
&to_start, &max);
result = from_start_copy - (char *) from_start;
# else
/* Decide what to do. */
result = 0;
# endif
#endif
return result;
}
static int
do_max_length (struct _IO_codecvt *codecvt)
{
#ifdef _LIBC
return codecvt->__cd_in.__cd.__steps[0].__max_needed_from;
#else
return MB_CUR_MAX;
#endif
}

View File

@ -0,0 +1,63 @@
/* Copyright (C) 1993,96,97,98,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
_IO_size_t
_IO_fwrite (buf, size, count, fp)
const void *buf;
_IO_size_t size;
_IO_size_t count;
_IO_FILE *fp;
{
_IO_size_t request = size * count;
_IO_size_t written = 0;
CHECK_FILE (fp, 0);
if (request == 0)
return 0;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (fp->_vtable_offset != 0 || _IO_fwide (fp, -1) == -1)
written = _IO_sputn (fp, (const char *) buf, request);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (written == request)
return count;
else
return written / size;
}
INTDEF(_IO_fwrite)
#ifdef weak_alias
# include <stdio.h>
weak_alias (_IO_fwrite, fwrite)
libc_hidden_weak (fwrite)
# ifndef _IO_MTSAFE_IO
weak_alias (_IO_fwrite, fwrite_unlocked)
libc_hidden_weak (fwrite_unlocked)
# endif
#endif

View File

@ -0,0 +1,54 @@
/* Copyright (C) 1993, 1996-2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio.h>
#undef fwrite_unlocked
_IO_size_t
fwrite_unlocked (buf, size, count, fp)
const void *buf;
_IO_size_t size;
_IO_size_t count;
_IO_FILE *fp;
{
_IO_size_t request = size * count;
_IO_size_t written = 0;
CHECK_FILE (fp, 0);
if (request == 0)
return 0;
if (_IO_fwide (fp, -1) == -1)
{
written = _IO_sputn (fp, (const char *) buf, request);
if (written == request)
return count;
}
return written / size;
}
libc_hidden_def (fwrite_unlocked)

View File

@ -0,0 +1,131 @@
/* Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#ifdef __STDC__
#include <stdlib.h>
#endif
#include "libioP.h"
#include <string.h>
#include <errno.h>
/* Read up to (and including) a TERMINATOR from FP into *LINEPTR
(and null-terminate it). *LINEPTR is a pointer returned from malloc (or
NULL), pointing to *N characters of space. It is realloc'ed as
necessary. Returns the number of characters read (not including the
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;
{
int result;
_IO_ssize_t cur_len = 0;
_IO_ssize_t len;
if (lineptr == NULL || n == NULL)
{
MAYBE_SET_EINVAL;
return -1;
}
CHECK_FILE (fp, -1);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_ferror_unlocked (fp))
{
result = -1;
goto unlock_return;
}
if (*lineptr == NULL || *n == 0)
{
*n = 120;
*lineptr = (char *) malloc (*n);
if (*lineptr == NULL)
{
result = -1;
goto unlock_return;
}
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len <= 0)
{
if (__underflow (fp) == EOF)
{
result = -1;
goto unlock_return;
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
for (;;)
{
_IO_size_t needed;
char *t;
t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
if (t != NULL)
len = (t - fp->_IO_read_ptr) + 1;
/* Make enough space for len+1 (for final NUL) bytes. */
needed = cur_len + len + 1;
if (needed > *n)
{
char *new_lineptr;
if (needed < 2 * *n)
needed = 2 * *n; /* Be generous. */
new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
*lineptr = new_lineptr;
*n = needed;
}
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
cur_len += len;
if (t != NULL || __underflow (fp) == EOF)
break;
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
(*lineptr)[cur_len] = '\0';
result = cur_len;
unlock_return:
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
#ifdef weak_alias
weak_alias (_IO_getdelim, __getdelim)
weak_alias (_IO_getdelim, getdelim)
#endif

View File

@ -0,0 +1,122 @@
/* Copyright (C) 1993,1997,1998,2000,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <string.h>
#if defined _LIBC || !_G_HAVE_IO_GETLINE_INFO
_IO_size_t
_IO_getline (fp, buf, n, delim, extract_delim)
_IO_FILE *fp;
char *buf;
_IO_size_t n;
int delim;
int extract_delim;
{
return INTUSE(_IO_getline_info) (fp, buf, n, delim, extract_delim,
(int *) 0);
}
INTDEF(_IO_getline)
/* Algorithm based on that used by Berkeley pre-4.4 fgets implementation.
Read chars into buf (of size n), until delim is seen.
Return number of chars read (at most n).
Does not put a terminating '\0' in buf.
If extract_delim < 0, leave delimiter unread.
If extract_delim > 0, insert delim in output. */
_IO_size_t
_IO_getline_info (fp, buf, n, delim, extract_delim, eof)
_IO_FILE *fp;
char *buf;
_IO_size_t n;
int delim;
int extract_delim;
int *eof;
{
char *ptr = buf;
if (eof != NULL)
*eof = 0;
if (__builtin_expect (fp->_mode, -1) == 0)
_IO_fwide (fp, -1);
while (n != 0)
{
_IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len <= 0)
{
int c = __uflow (fp);
if (c == EOF)
{
if (eof) *eof = c;
break;
}
if (c == delim)
{
if (extract_delim > 0)
*ptr++ = c;
else if (extract_delim < 0)
INTUSE(_IO_sputbackc) (fp, c);
if (extract_delim > 0)
++len;
return ptr - buf;
}
*ptr++ = c;
n--;
}
else
{
char *t;
if ((_IO_size_t) len >= n)
len = n;
t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
if (t != NULL)
{
_IO_size_t old_len = ptr-buf;
len = t - fp->_IO_read_ptr;
if (extract_delim >= 0)
{
++t;
if (extract_delim > 0)
++len;
}
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr = t;
return old_len + len;
}
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
ptr += len;
n -= len;
}
}
return ptr - buf;
}
INTDEF(_IO_getline_info)
#endif /* Defined _LIBC || !_G_HAVE_IO_GETLINE_INFO */

View File

@ -0,0 +1,81 @@
/* Copyright (C) 1993, 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <limits.h>
char*
_IO_gets (buf)
char *buf;
{
_IO_size_t count;
int ch;
char *retval;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile,
_IO_stdin);
_IO_flockfile (_IO_stdin);
ch = _IO_getc_unlocked (_IO_stdin);
if (ch == EOF)
{
retval = NULL;
goto unlock_return;
}
if (ch == '\n')
count = 0;
else
{
/* This is very tricky since a file descriptor may be in the
non-blocking mode. The error flag doesn't mean much in this
case. We return an error only when there is a new error. */
int old_error = _IO_stdin->_IO_file_flags & _IO_ERR_SEEN;
_IO_stdin->_IO_file_flags &= ~_IO_ERR_SEEN;
buf[0] = (char) ch;
count = INTUSE(_IO_getline) (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
{
retval = NULL;
goto unlock_return;
}
else
_IO_stdin->_IO_file_flags |= old_error;
}
buf[count] = 0;
retval = buf;
unlock_return:
_IO_funlockfile (_IO_stdin);
_IO_cleanup_region_end (0);
return retval;
}
#ifdef weak_alias
weak_alias (_IO_gets, gets)
#endif
#ifdef _LIBC
link_warning (gets, "the `gets' function is dangerous and should not be used.")
#endif

View File

@ -0,0 +1,127 @@
/* Copyright (C) 1993,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <string.h>
#include <wchar.h>
#ifdef _LIBC
# define wmemcpy __wmemcpy
#endif
#if defined _LIBC || !_G_HAVE_IO_GETLINE_INFO
_IO_size_t
_IO_getwline (fp, buf, n, delim, extract_delim)
_IO_FILE *fp;
wchar_t *buf;
_IO_size_t n;
wint_t delim;
int extract_delim;
{
return _IO_getwline_info (fp, buf, n, delim, extract_delim, (wint_t *) 0);
}
/* Algorithm based on that used by Berkeley pre-4.4 fgets implementation.
Read chars into buf (of size n), until delim is seen.
Return number of chars read (at most n).
Does not put a terminating '\0' in buf.
If extract_delim < 0, leave delimiter unread.
If extract_delim > 0, insert delim in output. */
_IO_size_t
_IO_getwline_info (fp, buf, n, delim, extract_delim, eof)
_IO_FILE *fp;
wchar_t *buf;
_IO_size_t n;
wint_t delim;
int extract_delim;
wint_t *eof;
{
wchar_t *ptr = buf;
if (eof != NULL)
*eof = 0;
if (__builtin_expect (fp->_mode, 1) == 0)
_IO_fwide (fp, 1);
while (n != 0)
{
_IO_ssize_t len = (fp->_wide_data->_IO_read_end
- fp->_wide_data->_IO_read_ptr);
if (len <= 0)
{
wint_t wc = __wuflow (fp);
if (wc == WEOF)
{
if (eof)
*eof = wc;
break;
}
if (wc == delim)
{
if (extract_delim > 0)
*ptr++ = wc;
else if (extract_delim < 0)
INTUSE(_IO_sputbackc) (fp, wc);
return ptr - buf;
if (extract_delim > 0)
++len;
}
*ptr++ = wc;
n--;
}
else
{
wchar_t *t;
if ((_IO_size_t) len >= n)
len = n;
t = wmemchr ((void *) fp->_wide_data->_IO_read_ptr, delim, len);
if (t != NULL)
{
_IO_size_t old_len = ptr - buf;
len = t - fp->_wide_data->_IO_read_ptr;
if (extract_delim >= 0)
{
++t;
if (extract_delim > 0)
++len;
}
wmemcpy ((void *) ptr, (void *) fp->_wide_data->_IO_read_ptr,
len);
fp->_wide_data->_IO_read_ptr = t;
return old_len + len;
}
wmemcpy ((void *) ptr, (void *) fp->_wide_data->_IO_read_ptr, len);
fp->_wide_data->_IO_read_ptr += len;
ptr += len;
n -= len;
}
}
return ptr - buf;
}
#endif /* Defined _LIBC || !_G_HAVE_IO_GETLINE_INFO */

View File

@ -0,0 +1,101 @@
#include <libio.h>
/* These emulate stdio functionality, but with a different name
(_IO_ungetc instead of ungetc), and using _IO_FILE instead of FILE. */
#ifdef __cplusplus
extern "C" {
#endif
extern int _IO_fclose __P((_IO_FILE*));
extern int _IO_new_fclose __P((_IO_FILE*));
extern int _IO_old_fclose __P((_IO_FILE*));
extern _IO_FILE *_IO_fdopen __P((int, const char*));
extern _IO_FILE *_IO_old_fdopen __P((int, const char*));
extern _IO_FILE *_IO_new_fdopen __P((int, const char*));
extern int _IO_fflush __P((_IO_FILE*));
extern int _IO_fgetpos __P((_IO_FILE*, _IO_fpos_t*));
extern int _IO_fgetpos64 __P((_IO_FILE*, _IO_fpos64_t*));
extern char* _IO_fgets __P((char*, int, _IO_FILE*));
extern _IO_FILE *_IO_fopen __P((const char*, const char*));
extern _IO_FILE *_IO_old_fopen __P((const char*, const char*));
extern _IO_FILE *_IO_new_fopen __P((const char*, const char*));
extern _IO_FILE *_IO_fopen64 __P((const char*, const char*));
extern _IO_FILE *__fopen_internal __P((const char*, const char*, int));
extern _IO_FILE *__fopen_maybe_mmap __P((_IO_FILE *));
extern int _IO_fprintf __P((_IO_FILE*, const char*, ...));
extern int _IO_fputs __P((const char*, _IO_FILE*));
libc_hidden_proto (_IO_fputs)
extern int _IO_fsetpos __P((_IO_FILE*, const _IO_fpos_t *));
extern int _IO_fsetpos64 __P((_IO_FILE*, const _IO_fpos64_t *));
extern long int _IO_ftell __P((_IO_FILE*));
extern _IO_size_t _IO_fread __P((void*, _IO_size_t, _IO_size_t, _IO_FILE*));
extern _IO_size_t _IO_fwrite __P((const void*,
_IO_size_t, _IO_size_t, _IO_FILE*));
extern char* _IO_gets __P((char*));
extern void _IO_perror __P((const char*));
extern int _IO_printf __P((const char*, ...));
extern int _IO_puts __P((const char*));
extern int _IO_scanf __P((const char*, ...));
extern void _IO_setbuffer __P((_IO_FILE *, char*, _IO_size_t));
extern int _IO_setvbuf __P((_IO_FILE*, char*, int, _IO_size_t));
extern int _IO_sscanf __P((const char*, const char*, ...));
extern int _IO_sprintf __P((char *, const char*, ...));
extern int _IO_ungetc __P((int, _IO_FILE*));
extern int _IO_vsscanf __P((const char *, const char *, _IO_va_list));
extern int _IO_vsprintf __P((char*, const char*, _IO_va_list));
extern int _IO_vswprintf __P((wchar_t*, _IO_size_t, const wchar_t*,
_IO_va_list));
struct obstack;
extern int _IO_obstack_vprintf __P ((struct obstack *, const char *,
_IO_va_list));
extern int _IO_obstack_printf __P ((struct obstack *, const char *, ...));
#ifndef _IO_pos_BAD
#define _IO_pos_BAD ((_IO_off64_t)(-1))
#endif
#define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
#define _IO_fseek(__fp, __offset, __whence) \
(_IO_seekoff_unlocked (__fp, __offset, __whence, _IOS_INPUT|_IOS_OUTPUT) \
== _IO_pos_BAD ? EOF : 0)
#define _IO_rewind(FILE) \
(void) _IO_seekoff_unlocked (FILE, 0, 0, _IOS_INPUT|_IOS_OUTPUT)
#define _IO_vprintf(FORMAT, ARGS) \
INTUSE(_IO_vfprintf) (_IO_stdout, FORMAT, ARGS)
#define _IO_freopen(FILENAME, MODE, FP) \
(INTUSE(_IO_file_close_it)(FP), \
INTUSE(_IO_file_fopen)(FP, FILENAME, MODE, 1))
#define _IO_old_freopen(FILENAME, MODE, FP) \
(_IO_old_file_close_it (FP), _IO_old_file_fopen(FP, FILENAME, MODE))
#define _IO_freopen64(FILENAME, MODE, FP) \
(INTUSE(_IO_file_close_it)(FP), \
INTUSE(_IO_file_fopen)(FP, FILENAME, MODE, 0))
#define _IO_fileno(FP) ((FP)->_fileno)
extern _IO_FILE* _IO_popen __P((const char*, const char*));
extern _IO_FILE* _IO_new_popen __P((const char*, const char*));
extern _IO_FILE* _IO_old_popen __P((const char*, const char*));
extern int __new_pclose __P((_IO_FILE *));
extern int __old_pclose __P((_IO_FILE *));
#define _IO_pclose _IO_fclose
#define _IO_setbuf(_FP, _BUF) INTUSE(_IO_setbuffer)(_FP, _BUF, _IO_BUFSIZ)
#define _IO_setlinebuf(_FP) INTUSE(_IO_setvbuf)(_FP, NULL, 1, 0)
_IO_FILE *__new_freopen __P ((const char *, const char *, _IO_FILE *));
_IO_FILE *__old_freopen __P ((const char *, const char *, _IO_FILE *));
/* Prototype for functions with alternative entry point. */
extern void _IO_setbuffer_internal __P((_IO_FILE *, char*, _IO_size_t));
extern _IO_size_t _IO_fread_internal __P((void*, _IO_size_t, _IO_size_t,
_IO_FILE*));
extern _IO_FILE *_IO_fdopen_internal __P((int, const char*));
extern int _IO_vsprintf_internal __P((char*, const char*, _IO_va_list));
extern int _IO_fflush_internal __P((_IO_FILE*));
extern _IO_size_t _IO_fwrite_internal __P((const void*, _IO_size_t,
_IO_size_t, _IO_FILE*));
extern long int _IO_ftell_internal __P((_IO_FILE*));
extern int _IO_fputs_internal __P((const char*, _IO_FILE*));
extern int _IO_setvbuf_internal __P((_IO_FILE*, char*, int, _IO_size_t));
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,73 @@
/* Copyright (C) 1993, 1997, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#define PADSIZE 16
static char const blanks[PADSIZE] =
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
static char const zeroes[PADSIZE] =
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
_IO_ssize_t
_IO_padn (fp, pad, count)
_IO_FILE *fp;
int pad;
_IO_ssize_t count;
{
char padbuf[PADSIZE];
const char *padptr;
int i;
_IO_size_t written = 0;
_IO_size_t w;
if (pad == ' ')
padptr = blanks;
else if (pad == '0')
padptr = zeroes;
else
{
for (i = PADSIZE; --i >= 0; )
padbuf[i] = pad;
padptr = padbuf;
}
for (i = count; i >= PADSIZE; i -= PADSIZE)
{
w = _IO_sputn (fp, padptr, PADSIZE);
written += w;
if (w != PADSIZE)
return written;
}
if (i > 0)
{
w = _IO_sputn (fp, padptr, i);
written += w;
}
return written;
}
INTDEF(_IO_padn)

View File

@ -0,0 +1,338 @@
/* Copyright (C) 1993, 1997-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Per Bothner <bothner@cygnus.com>.
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. */
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h"
#if _IO_HAVE_SYS_WAIT
#include <signal.h>
#include <unistd.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef _LIBC
# include <unistd.h>
# include <shlib-compat.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>
#ifndef _IO_fork
#ifdef _LIBC
#define _IO_fork __vfork
#else
#define _IO_fork vfork /* defined in libiberty, if needed */
#endif
extern _IO_pid_t _IO_fork __P ((void));
#endif
#endif /* _IO_HAVE_SYS_WAIT */
#ifndef _IO_pipe
#ifdef _LIBC
#define _IO_pipe __pipe
#else
#define _IO_pipe pipe
#endif
extern int _IO_pipe __P ((int des[2]));
#endif
#ifndef _IO_dup2
#ifdef _LIBC
#define _IO_dup2 __dup2
#else
#define _IO_dup2 dup2
#endif
extern int _IO_dup2 __P ((int fd, int fd2));
#endif
#ifndef _IO_waitpid
#ifdef _LIBC
#define _IO_waitpid __waitpid
#else
#define _IO_waitpid waitpid
#endif
#endif
#ifndef _IO_execl
#define _IO_execl execl
#endif
#ifndef _IO__exit
#define _IO__exit _exit
#endif
#ifndef _IO_close
#ifdef _LIBC
#define _IO_close __close
#else
#define _IO_close close
#endif
#endif
struct _IO_proc_file
{
struct _IO_FILE_plus file;
/* Following fields must match those in class procbuf (procbuf.h) */
_IO_pid_t pid;
struct _IO_proc_file *next;
};
typedef struct _IO_proc_file _IO_proc_file;
static struct _IO_jump_t _IO_proc_jumps;
static struct _IO_jump_t _IO_wproc_jumps;
static struct _IO_proc_file *proc_file_chain;
#ifdef _IO_MTSAFE_IO
static _IO_lock_t proc_file_chain_lock = _IO_lock_initializer;
static void
unlock (void *not_used)
{
_IO_lock_unlock (proc_file_chain_lock);
}
#endif
_IO_FILE *
_IO_new_proc_open (fp, command, mode)
_IO_FILE *fp;
const char *command;
const char *mode;
{
#if _IO_HAVE_SYS_WAIT
volatile int read_or_write;
volatile int parent_end, child_end;
int pipe_fds[2];
_IO_pid_t child_pid;
if (_IO_file_is_open (fp))
return NULL;
if (_IO_pipe (pipe_fds) < 0)
return NULL;
if (mode[0] == 'r' && mode[1] == '\0')
{
parent_end = pipe_fds[0];
child_end = pipe_fds[1];
read_or_write = _IO_NO_WRITES;
}
else if (mode[0] == 'w' && mode[1] == '\0')
{
parent_end = pipe_fds[1];
child_end = pipe_fds[0];
read_or_write = _IO_NO_READS;
}
else
{
_IO_close (pipe_fds[0]);
_IO_close (pipe_fds[1]);
__set_errno (EINVAL);
return NULL;
}
((_IO_proc_file *) fp)->pid = child_pid = _IO_fork ();
if (child_pid == 0)
{
int child_std_end = mode[0] == 'r' ? 1 : 0;
struct _IO_proc_file *p;
_IO_close (parent_end);
if (child_end != child_std_end)
{
_IO_dup2 (child_end, child_std_end);
_IO_close (child_end);
}
/* POSIX.2: "popen() shall ensure that any streams from previous
popen() calls that remain open in the parent process are closed
in the new child process." */
for (p = proc_file_chain; p; p = p->next)
_IO_close (_IO_fileno ((_IO_FILE *) p));
_IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
_IO__exit (127);
}
_IO_close (child_end);
if (child_pid < 0)
{
_IO_close (parent_end);
return NULL;
}
_IO_fileno (fp) = parent_end;
/* Link into proc_file_chain. */
#ifdef _IO_MTSAFE_IO
_IO_cleanup_region_start_noarg (unlock);
_IO_lock_lock (proc_file_chain_lock);
#endif
((_IO_proc_file *) fp)->next = proc_file_chain;
proc_file_chain = (_IO_proc_file *) fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_unlock (proc_file_chain_lock);
_IO_cleanup_region_end (0);
#endif
_IO_mask_flags (fp, read_or_write, _IO_NO_READS|_IO_NO_WRITES);
return fp;
#else /* !_IO_HAVE_SYS_WAIT */
return NULL;
#endif
}
_IO_FILE *
_IO_new_popen (command, mode)
const char *command;
const char *mode;
{
struct locked_FILE
{
struct _IO_proc_file fpx;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
struct _IO_wide_data wd;
} *new_f;
_IO_FILE *fp;
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fpx.file.file._lock = &new_f->lock;
#endif
fp = &new_f->fpx.file.file;
_IO_no_init (fp, 0, 0, &new_f->wd, &_IO_wproc_jumps);
_IO_JUMPS (&new_f->fpx.file) = &_IO_proc_jumps;
_IO_new_file_init (&new_f->fpx.file);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fpx.file.vtable = NULL;
#endif
if (_IO_new_proc_open (fp, command, mode) != NULL)
return (_IO_FILE *) &new_f->fpx.file;
INTUSE(_IO_un_link) (&new_f->fpx.file);
free (new_f);
return NULL;
}
int
_IO_new_proc_close (fp)
_IO_FILE *fp;
{
/* This is not name-space clean. FIXME! */
#if _IO_HAVE_SYS_WAIT
int wstatus;
_IO_proc_file **ptr = &proc_file_chain;
_IO_pid_t wait_pid;
int status = -1;
/* Unlink from proc_file_chain. */
#ifdef _IO_MTSAFE_IO
_IO_cleanup_region_start_noarg (unlock);
_IO_lock_lock (proc_file_chain_lock);
#endif
for ( ; *ptr != NULL; ptr = &(*ptr)->next)
{
if (*ptr == (_IO_proc_file *) fp)
{
*ptr = (*ptr)->next;
status = 0;
break;
}
}
#ifdef _IO_MTSAFE_IO
_IO_lock_unlock (proc_file_chain_lock);
_IO_cleanup_region_end (0);
#endif
if (status < 0 || _IO_close (_IO_fileno(fp)) < 0)
return -1;
/* POSIX.2 Rationale: "Some historical implementations either block
or ignore the signals SIGINT, SIGQUIT, and SIGHUP while waiting
for the child process to terminate. Since this behavior is not
described in POSIX.2, such implementations are not conforming." */
do
{
wait_pid = _IO_waitpid (((_IO_proc_file *) fp)->pid, &wstatus, 0);
}
while (wait_pid == -1 && errno == EINTR);
if (wait_pid == -1)
return -1;
return wstatus;
#else /* !_IO_HAVE_SYS_WAIT */
return -1;
#endif
}
static struct _IO_jump_t _IO_proc_jumps = {
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_new_file_finish),
JUMP_INIT(overflow, _IO_new_file_overflow),
JUMP_INIT(underflow, _IO_new_file_underflow),
JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, _IO_new_file_xsputn),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
JUMP_INIT(seekoff, _IO_new_file_seekoff),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, _IO_new_file_setbuf),
JUMP_INIT(sync, _IO_new_file_sync),
JUMP_INIT(doallocate, INTUSE(_IO_file_doallocate)),
JUMP_INIT(read, INTUSE(_IO_file_read)),
JUMP_INIT(write, _IO_new_file_write),
JUMP_INIT(seek, INTUSE(_IO_file_seek)),
JUMP_INIT(close, _IO_new_proc_close),
JUMP_INIT(stat, INTUSE(_IO_file_stat)),
JUMP_INIT(showmanyc, _IO_default_showmanyc),
JUMP_INIT(imbue, _IO_default_imbue)
};
static struct _IO_jump_t _IO_wproc_jumps = {
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_new_file_finish),
JUMP_INIT(overflow, _IO_new_file_overflow),
JUMP_INIT(underflow, _IO_new_file_underflow),
JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, _IO_new_file_xsputn),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
JUMP_INIT(seekoff, _IO_new_file_seekoff),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, _IO_new_file_setbuf),
JUMP_INIT(sync, _IO_new_file_sync),
JUMP_INIT(doallocate, INTUSE(_IO_file_doallocate)),
JUMP_INIT(read, INTUSE(_IO_file_read)),
JUMP_INIT(write, _IO_new_file_write),
JUMP_INIT(seek, INTUSE(_IO_file_seek)),
JUMP_INIT(close, _IO_new_proc_close),
JUMP_INIT(stat, INTUSE(_IO_file_stat)),
JUMP_INIT(showmanyc, _IO_default_showmanyc),
JUMP_INIT(imbue, _IO_default_imbue)
};
strong_alias (_IO_new_popen, __new_popen)
versioned_symbol (libc, _IO_new_popen, _IO_popen, GLIBC_2_1);
versioned_symbol (libc, __new_popen, popen, GLIBC_2_1);
versioned_symbol (libc, _IO_new_proc_open, _IO_proc_open, GLIBC_2_1);
versioned_symbol (libc, _IO_new_proc_close, _IO_proc_close, GLIBC_2_1);

View File

@ -0,0 +1,53 @@
/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <string.h>
int
_IO_puts (str)
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);
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)
#endif

View File

@ -0,0 +1,91 @@
/* Copyright (C) 1993,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#include <stdlib.h>
#include <errno.h>
#ifndef errno
extern int errno;
#endif
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
_IO_off64_t
_IO_seekoff_unlocked (fp, offset, dir, mode)
_IO_FILE *fp;
_IO_off64_t offset;
int dir;
int mode;
{
if (dir != _IO_seek_cur && dir != _IO_seek_set && dir != _IO_seek_end)
{
__set_errno (EINVAL);
return EOF;
}
/* 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 (mode != 0 && ((_IO_fwide (fp, 0) < 0 && _IO_have_backup (fp))
|| (_IO_fwide (fp, 0) > 0 && _IO_have_wbackup (fp))))
{
if (dir == _IO_seek_cur && _IO_in_backup (fp))
{
if (fp->_vtable_offset != 0 || fp->_mode <= 0)
offset -= fp->_IO_read_end - fp->_IO_read_ptr;
else
abort ();
}
if (_IO_fwide (fp, 0) < 0)
INTUSE(_IO_free_backup_area) (fp);
else
INTUSE(_IO_free_wbackup_area) (fp);
}
return _IO_SEEKOFF (fp, offset, dir, mode);
}
_IO_off64_t
_IO_seekoff (fp, offset, dir, mode)
_IO_FILE *fp;
_IO_off64_t offset;
int dir;
int mode;
{
_IO_off64_t retval;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
retval = _IO_seekoff_unlocked (fp, offset, dir, mode);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return retval;
}

View File

@ -0,0 +1,70 @@
/* Copyright (C) 1993, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
_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 (fp, pos, mode)
_IO_FILE *fp;
_IO_off64_t pos;
int mode;
{
_IO_off64_t retval;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
retval = _IO_seekpos_unlocked (fp, pos, mode);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return retval;
}

View File

@ -0,0 +1,53 @@
/* Copyright (C) 1993,95,96,97,98,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
void
_IO_setbuffer (fp, buf, size)
_IO_FILE *fp;
char *buf;
_IO_size_t size;
{
CHECK_FILE (fp, );
_IO_cleanup_region_start ((void (*) (void *)) _IO_funlockfile, fp);
_IO_flockfile (fp);
fp->_flags &= ~_IO_LINE_BUF;
if (!buf)
size = 0;
(void) _IO_SETBUF (fp, buf, size);
if (fp->_vtable_offset == 0 && fp->_mode == 0 && _IO_CHECK_WIDE (fp))
/* We also have to set the buffer using the wide char function. */
(void) _IO_WSETBUF (fp, buf, size);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
}
INTDEF(_IO_setbuffer)
#ifdef weak_alias
weak_alias (_IO_setbuffer, setbuffer)
#endif

View File

@ -0,0 +1,107 @@
/* Copyright (C) 1993,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#define _IOFBF 0 /* Fully buffered. */
#define _IOLBF 1 /* Line buffered. */
#define _IONBF 2 /* No buffering. */
int
_IO_setvbuf (fp, buf, mode, size)
_IO_FILE *fp;
char *buf;
int mode;
_IO_size_t size;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) (void *)) _IO_funlockfile, fp);
_IO_flockfile (fp);
switch (mode)
{
case _IOFBF:
fp->_IO_file_flags &= ~_IO_LINE_BUF|_IO_UNBUFFERED;
if (buf == NULL)
{
if (fp->_IO_buf_base == NULL)
{
/* There is no flag to distinguish between "fully buffered
mode has been explicitly set" as opposed to "line
buffering has not been explicitly set". In both
cases, _IO_LINE_BUF is off. If this is a tty, and
_IO_filedoalloc later gets called, it cannot know if
it should set the _IO_LINE_BUF flag (because that is
the default), or not (because we have explicitly asked
for fully buffered mode). So we make sure a buffer
gets allocated now, and explicitly turn off line
buffering.
A possibly cleaner alternative would be to add an
extra flag, but then flags are a finite resource. */
if (_IO_DOALLOCATE (fp) < 0)
{
result = EOF;
goto unlock_return;
}
fp->_IO_file_flags &= ~_IO_LINE_BUF;
}
result = 0;
goto unlock_return;
}
break;
case _IOLBF:
fp->_IO_file_flags &= ~_IO_UNBUFFERED;
fp->_IO_file_flags |= _IO_LINE_BUF;
if (buf == NULL)
{
result = 0;
goto unlock_return;
}
break;
case _IONBF:
fp->_IO_file_flags &= ~_IO_LINE_BUF;
fp->_IO_file_flags |= _IO_UNBUFFERED;
buf = NULL;
size = 0;
break;
default:
result = EOF;
goto unlock_return;
}
result = _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
unlock_return:
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
INTDEF(_IO_setvbuf)
#ifdef weak_alias
weak_alias (_IO_setvbuf, setvbuf)
#endif

View File

@ -0,0 +1,49 @@
/* Copyright (C) 1993,1996,1997,1998,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
int
_IO_ungetc (c, fp)
int c;
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
if (c == EOF)
return EOF;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = INTUSE(_IO_sputbackc) (fp, (unsigned char) c);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
#ifdef weak_alias
weak_alias (_IO_ungetc, ungetc)
#endif

View File

@ -0,0 +1,48 @@
/* Copyright (C) 1993, 1996-1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <wchar.h>
wint_t
ungetwc (c, fp)
wint_t c;
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, WEOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
_IO_fwide (fp, 1);
if (c == WEOF)
result = WEOF;
else
result = INTUSE(_IO_sputbackwc) (fp, c);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,69 @@
/* Copyright (C) 1995, 1997-2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <stdio_ext.h>
int
_IO_vdprintf (d, format, arg)
int d;
const char *format;
_IO_va_list arg;
{
struct _IO_FILE_plus tmpfil;
struct _IO_wide_data wd;
int done;
#ifdef _IO_MTSAFE_IO
tmpfil.file._lock = NULL;
#endif
_IO_no_init (&tmpfil.file, _IO_USER_LOCK, 0, &wd, &INTUSE(_IO_wfile_jumps));
_IO_JUMPS (&tmpfil) = &INTUSE(_IO_file_jumps);
INTUSE(_IO_file_init) (&tmpfil);
#if !_IO_UNIFIED_JUMPTABLES
tmpfil.vtable = NULL;
#endif
if (INTUSE(_IO_file_attach) (&tmpfil.file, d) == NULL)
{
INTUSE(_IO_un_link) (&tmpfil);
return EOF;
}
tmpfil.file._IO_file_flags =
(_IO_mask_flags (&tmpfil.file, _IO_NO_READS,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING)
| _IO_DELETE_DONT_CLOSE);
done = INTUSE(_IO_vfprintf) (&tmpfil.file, format, arg);
_IO_FINISH (&tmpfil.file);
return done;
}
#ifdef weak_alias
weak_alias (_IO_vdprintf, vdprintf)
#endif

View File

@ -0,0 +1,54 @@
/* Copyright (C) 1993, 1997-2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "strfile.h"
int
_IO_vsprintf (string, format, args)
char *string;
const char *format;
_IO_va_list args;
{
_IO_strfile sf;
int ret;
#ifdef _IO_MTSAFE_IO
sf._sbf._f._lock = NULL;
#endif
_IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
_IO_JUMPS ((struct _IO_FILE_plus *) &sf._sbf) = &_IO_str_jumps;
INTUSE(_IO_str_init_static) (&sf, string, -1, string);
ret = INTUSE(_IO_vfprintf) ((_IO_FILE *) &sf._sbf, format, args);
_IO_putc_unlocked ('\0', (_IO_FILE *) &sf._sbf);
return ret;
}
INTDEF(_IO_vsprintf)
#ifdef weak_alias
weak_alias (_IO_vsprintf, vsprintf)
#endif

View File

@ -0,0 +1,52 @@
/* Copyright (C) 1993, 1997-2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "strfile.h"
int
_IO_vsscanf (string, format, args)
const char *string;
const char *format;
_IO_va_list args;
{
int ret;
_IO_strfile sf;
#ifdef _IO_MTSAFE_IO
sf._sbf._f._lock = NULL;
#endif
_IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
_IO_JUMPS ((struct _IO_FILE_plus *) &sf._sbf) = &_IO_str_jumps;
INTUSE(_IO_str_init_static) (&sf, (char*)string, 0, NULL);
ret = INTUSE(_IO_vfscanf) ((_IO_FILE *) &sf._sbf, format, args, NULL);
return ret;
}
#ifdef weak_alias
weak_alias (_IO_vsscanf, __vsscanf)
weak_alias (_IO_vsscanf, vsscanf)
#endif

View File

@ -0,0 +1,50 @@
/* Copyright (C) 1993, 1997-2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "strfile.h"
#include <wchar.h>
int
vswscanf (string, format, args)
const wchar_t *string;
const wchar_t *format;
_IO_va_list args;
{
int ret;
_IO_strfile sf;
struct _IO_wide_data wd;
#ifdef _IO_MTSAFE_IO
sf._sbf._f._lock = NULL;
#endif
_IO_no_init (&sf._sbf._f, _IO_USER_LOCK, 0, &wd, &_IO_wstr_jumps);
_IO_fwide (&sf._sbf._f, 1);
_IO_wstr_init_static (&sf._sbf._f, (wchar_t *)string, 0, NULL);
ret = _IO_vfwscanf ((_IO_FILE *) &sf._sbf, format, args, NULL);
return ret;
}
libc_hidden_def (vswscanf)

View File

@ -0,0 +1,78 @@
/* Copyright (C) 1993, 1997, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#define PADSIZE 16
static wchar_t const blanks[PADSIZE] =
{
L' ', L' ', L' ', L' ', L' ', L' ', L' ', L' ',
L' ', L' ', L' ', L' ', L' ', L' ', L' ', L' '
};
static wchar_t const zeroes[PADSIZE] =
{
L'0', L'0', L'0', L'0', L'0', L'0', L'0', L'0',
L'0', L'0', L'0', L'0', L'0', L'0', L'0', L'0'
};
_IO_ssize_t
_IO_wpadn (fp, pad, count)
_IO_FILE *fp;
wint_t pad;
_IO_ssize_t count;
{
wchar_t padbuf[PADSIZE];
const wchar_t *padptr;
int i;
_IO_size_t written = 0;
_IO_size_t w;
if (pad == L' ')
padptr = blanks;
else if (pad == L'0')
padptr = zeroes;
else
{
for (i = PADSIZE; --i >= 0; )
padbuf[i] = pad;
padptr = padbuf;
}
for (i = count; i >= PADSIZE; i -= PADSIZE)
{
w = _IO_sputn (fp, (char *) padptr, PADSIZE);
written += w;
if (w != PADSIZE)
return written;
}
if (i > 0)
{
w = _IO_sputn (fp, (char *) padptr, i);
written += w;
}
return written;
}

View File

@ -0,0 +1,522 @@
/* Copyright (C) 1991-1995, 1997-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Per Bothner <bothner@cygnus.com>.
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. */
#ifndef _IO_STDIO_H
#define _IO_STDIO_H
#include <_G_config.h>
/* ALL of these should be defined in _G_config.h */
#define _IO_pos_t _G_fpos_t /* obsolete */
#define _IO_fpos_t _G_fpos_t
#define _IO_fpos64_t _G_fpos64_t
#define _IO_size_t _G_size_t
#define _IO_ssize_t _G_ssize_t
#define _IO_off_t _G_off_t
#define _IO_off64_t _G_off64_t
#define _IO_pid_t _G_pid_t
#define _IO_uid_t _G_uid_t
#define _IO_iconv_t _G_iconv_t
#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
#define _IO_BUFSIZ _G_BUFSIZ
#define _IO_va_list _G_va_list
#define _IO_wint_t _G_wint_t
#ifdef _G_NEED_STDARG_H
/* This define avoids name pollution if we're using GNU stdarg.h */
# define __need___va_list
# include <stdarg.h>
# ifdef __GNUC_VA_LIST
# undef _IO_va_list
# define _IO_va_list __gnuc_va_list
# endif /* __GNUC_VA_LIST */
#endif
#ifndef __P
# if _G_HAVE_SYS_CDEFS
# include <sys/cdefs.h>
# else
# ifdef __STDC__
# define __P(p) p
# define __PMT(p) p
# else
# define __P(p) ()
# define __PMT(p) ()
# endif
# endif
#endif /*!__P*/
/* For backward compatibility */
#ifndef _PARAMS
# define _PARAMS(protos) __P(protos)
#endif /*!_PARAMS*/
#ifndef __STDC__
# ifndef const
# define const
# endif
#endif
#define _IO_UNIFIED_JUMPTABLES 1
#ifndef _G_HAVE_PRINTF_FP
# define _IO_USE_DTOA 1
#endif
#ifndef EOF
# define EOF (-1)
#endif
#ifndef NULL
# if defined __GNUG__ && \
(__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
# define NULL (__null)
# else
# if !defined(__cplusplus)
# define NULL ((void*)0)
# else
# define NULL (0)
# endif
# endif
#endif
#define _IOS_INPUT 1
#define _IOS_OUTPUT 2
#define _IOS_ATEND 4
#define _IOS_APPEND 8
#define _IOS_TRUNC 16
#define _IOS_NOCREATE 32
#define _IOS_NOREPLACE 64
#define _IOS_BIN 128
/* Magic numbers and bits for the _flags field.
The magic numbers use the high-order bits of _flags;
the remaining bits are available for variable flags.
Note: The magic numbers must all be negative if stdio
emulation is desired. */
#define _IO_MAGIC 0xFBAD0000 /* Magic number */
#define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
#define _IO_MAGIC_MASK 0xFFFF0000
#define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
#define _IO_UNBUFFERED 2
#define _IO_NO_READS 4 /* Reading not allowed */
#define _IO_NO_WRITES 8 /* Writing not allowd */
#define _IO_EOF_SEEN 0x10
#define _IO_ERR_SEEN 0x20
#define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
#define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
#define _IO_IN_BACKUP 0x100
#define _IO_LINE_BUF 0x200
#define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
#define _IO_CURRENTLY_PUTTING 0x800
#define _IO_IS_APPENDING 0x1000
#define _IO_IS_FILEBUF 0x2000
#define _IO_BAD_SEEN 0x4000
#define _IO_USER_LOCK 0x8000
#define _IO_FLAGS2_MMAP 1
/* These are "formatting flags" matching the iostream fmtflags enum values. */
#define _IO_SKIPWS 01
#define _IO_LEFT 02
#define _IO_RIGHT 04
#define _IO_INTERNAL 010
#define _IO_DEC 020
#define _IO_OCT 040
#define _IO_HEX 0100
#define _IO_SHOWBASE 0200
#define _IO_SHOWPOINT 0400
#define _IO_UPPERCASE 01000
#define _IO_SHOWPOS 02000
#define _IO_SCIENTIFIC 04000
#define _IO_FIXED 010000
#define _IO_UNITBUF 020000
#define _IO_STDIO 040000
#define _IO_DONT_CLOSE 0100000
#define _IO_BOOLALPHA 0200000
struct _IO_jump_t; struct _IO_FILE;
/* Handle lock. */
#ifdef _IO_MTSAFE_IO
# if defined __GLIBC__ && __GLIBC__ >= 2
# include <bits/stdio-lock.h>
# else
/*# include <comthread.h>*/
# endif
#else
typedef void _IO_lock_t;
#endif
/* A streammarker remembers a position in a buffer. */
struct _IO_marker {
struct _IO_marker *_next;
struct _IO_FILE *_sbuf;
/* If _pos >= 0
it points to _buf->Gbase()+_pos. FIXME comment */
/* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
int _pos;
#if 0
void set_streampos(streampos sp) { _spos = sp; }
void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
public:
streammarker(streambuf *sb);
~streammarker();
int saving() { return _spos == -2; }
int delta(streammarker&);
int delta();
#endif
};
/* This is the structure from the libstdc++ codecvt class. */
enum __codecvt_result
{
__codecvt_ok,
__codecvt_partial,
__codecvt_error,
__codecvt_noconv
};
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
/* The order of the elements in the following struct must match the order
of the virtual functions in the libstdc++ codecvt class. */
struct _IO_codecvt
{
void (*__codecvt_destr) (struct _IO_codecvt *);
enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
__mbstate_t *,
const wchar_t *,
const wchar_t *,
const wchar_t **, char *,
char *, char **);
enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
__mbstate_t *, char *,
char *, char **);
enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
__mbstate_t *,
const char *, const char *,
const char **, wchar_t *,
wchar_t *, wchar_t **);
int (*__codecvt_do_encoding) (struct _IO_codecvt *);
int (*__codecvt_do_always_noconv) (struct _IO_codecvt *);
int (*__codecvt_do_length) (struct _IO_codecvt *, __mbstate_t *,
const char *, const char *, _IO_size_t);
int (*__codecvt_do_max_length) (struct _IO_codecvt *);
_IO_iconv_t __cd_in;
_IO_iconv_t __cd_out;
};
/* Extra data for wide character streams. */
struct _IO_wide_data
{
wchar_t *_IO_read_ptr; /* Current read pointer */
wchar_t *_IO_read_end; /* End of get area. */
wchar_t *_IO_read_base; /* Start of putback+get area. */
wchar_t *_IO_write_base; /* Start of put area. */
wchar_t *_IO_write_ptr; /* Current put pointer. */
wchar_t *_IO_write_end; /* End of put area. */
wchar_t *_IO_buf_base; /* Start of reserve area. */
wchar_t *_IO_buf_end; /* End of reserve area. */
/* The following fields are used to support backing up and undo. */
wchar_t *_IO_save_base; /* Pointer to start of non-current get area. */
wchar_t *_IO_backup_base; /* Pointer to first valid character of
backup area */
wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */
__mbstate_t _IO_state;
__mbstate_t _IO_last_state;
struct _IO_codecvt _codecvt;
wchar_t _shortbuf[1];
struct _IO_jump_t *_wide_vtable;
};
#endif
struct _IO_FILE {
int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
#define _IO_file_flags _flags
/* The following pointers correspond to the C++ streambuf protocol. */
/* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
char* _IO_read_ptr; /* Current read pointer */
char* _IO_read_end; /* End of get area. */
char* _IO_read_base; /* Start of putback+get area. */
char* _IO_write_base; /* Start of put area. */
char* _IO_write_ptr; /* Current put pointer. */
char* _IO_write_end; /* End of put area. */
char* _IO_buf_base; /* Start of reserve area. */
char* _IO_buf_end; /* End of reserve area. */
/* The following fields are used to support backing up and undo. */
char *_IO_save_base; /* Pointer to start of non-current get area. */
char *_IO_backup_base; /* Pointer to first valid character of backup area */
char *_IO_save_end; /* Pointer to end of non-current get area. */
struct _IO_marker *_markers;
struct _IO_FILE *_chain;
int _fileno;
#if 0
int _blksize;
#else
int _flags2;
#endif
_IO_off_t _old_offset; /* This used to be _offset but it's too small. */
#define __HAVE_COLUMN /* temporary */
/* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column;
signed char _vtable_offset;
char _shortbuf[1];
/* char* _save_gptr; char* _save_egptr; */
_IO_lock_t *_lock;
#ifdef _IO_USE_OLD_IO_FILE
};
struct _IO_FILE_complete
{
struct _IO_FILE _file;
#endif
#if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
_IO_off64_t _offset;
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
/* Wide character stream stuff. */
struct _IO_codecvt *_codecvt;
struct _IO_wide_data *_wide_data;
# else
void *__pad1;
void *__pad2;
# endif
int _mode;
/* Make sure we don't get into trouble again. */
char _unused2[15 * sizeof (int) - 2 * sizeof (void *)];
#endif
};
#ifndef __cplusplus
typedef struct _IO_FILE _IO_FILE;
#endif
struct _IO_FILE_plus;
extern struct _IO_FILE_plus _IO_2_1_stdin_;
extern struct _IO_FILE_plus _IO_2_1_stdout_;
extern struct _IO_FILE_plus _IO_2_1_stderr_;
#ifndef _LIBC
#define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
#define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
#define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
#else
extern _IO_FILE *_IO_stdin attribute_hidden;
extern _IO_FILE *_IO_stdout attribute_hidden;
extern _IO_FILE *_IO_stderr attribute_hidden;
#endif
/* Functions to do I/O and file management for a stream. */
/* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
Return number of bytes read. */
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
/* Write N bytes pointed to by BUF to COOKIE. Write all N bytes
unless there is an error. Return number of bytes written, or -1 if
there is an error without writing anything. If the file has been
opened for append (__mode.__append set), then set the file pointer
to the end of the file and then do the write; if not, just write at
the current file pointer. */
typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,
size_t __n);
/* Move COOKIE's file position to *POS bytes from the
beginning of the file (if W is SEEK_SET),
the current position (if W is SEEK_CUR),
or the end of the file (if W is SEEK_END).
Set *POS to the new file position.
Returns zero if successful, nonzero if not. */
typedef int __io_seek_fn (void *__cookie, _IO_off64_t *__pos, int __w);
/* Close COOKIE. */
typedef int __io_close_fn (void *__cookie);
#ifdef _GNU_SOURCE
/* User-visible names for the above. */
typedef __io_read_fn cookie_read_function_t;
typedef __io_write_fn cookie_write_function_t;
typedef __io_seek_fn cookie_seek_function_t;
typedef __io_close_fn cookie_close_function_t;
/* The structure with the cookie function pointers. */
typedef struct
{
__io_read_fn *read; /* Read bytes. */
__io_write_fn *write; /* Write bytes. */
__io_seek_fn *seek; /* Seek/tell file position. */
__io_close_fn *close; /* Close file. */
} _IO_cookie_io_functions_t;
typedef _IO_cookie_io_functions_t cookie_io_functions_t;
struct _IO_cookie_file;
/* Initialize one of those. */
extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,
void *__cookie, _IO_cookie_io_functions_t __fns);
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int __underflow (_IO_FILE *) __THROW;
extern int __uflow (_IO_FILE *) __THROW;
extern int __overflow (_IO_FILE *, int) __THROW;
extern _IO_wint_t __wunderflow (_IO_FILE *) __THROW;
extern _IO_wint_t __wuflow (_IO_FILE *) __THROW;
extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t) __THROW;
#define _IO_getc_unlocked(_fp) \
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \
: *(unsigned char *) (_fp)->_IO_read_ptr++)
#define _IO_peekc_unlocked(_fp) \
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
&& __underflow (_fp) == EOF ? EOF \
: *(unsigned char *) (_fp)->_IO_read_ptr)
#define _IO_putc_unlocked(_ch, _fp) \
(((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
? __overflow (_fp, (unsigned char) (_ch)) \
: (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
#define _IO_getwc_unlocked(_fp) \
((_fp)->_wide_data->_IO_read_ptr >= (_fp)->_wide_data->_IO_read_end \
? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
#define _IO_putwc_unlocked(_wch, _fp) \
((_fp)->_wide_data->_IO_write_ptr >= (_fp)->_wide_data->_IO_write_end \
? __woverflow (_fp, _wch) \
: (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
extern int _IO_getc (_IO_FILE *__fp) __THROW;
extern int _IO_putc (int __c, _IO_FILE *__fp) __THROW;
extern int _IO_feof (_IO_FILE *__fp) __THROW;
extern int _IO_ferror (_IO_FILE *__fp) __THROW;
extern int _IO_peekc_locked (_IO_FILE *__fp) __THROW;
/* This one is for Emacs. */
#define _IO_PENDING_OUTPUT_COUNT(_fp) \
((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
extern void _IO_flockfile (_IO_FILE *) __THROW;
extern void _IO_funlockfile (_IO_FILE *) __THROW;
extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
#ifdef _IO_MTSAFE_IO
# define _IO_peekc(_fp) _IO_peekc_locked (_fp)
# define _IO_flockfile(_fp) \
if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp)
# define _IO_funlockfile(_fp) \
if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (_fp)
#else
# define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
# define _IO_flockfile(_fp) /**/
# define _IO_funlockfile(_fp) /**/
# define _IO_ftrylockfile(_fp) /**/
# define _IO_cleanup_region_start(_fct, _fp) /**/
# define _IO_cleanup_region_end(_Doit) /**/
#endif /* !_IO_MTSAFE_IO */
extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
_IO_va_list, int *__restrict) __THROW;
extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
_IO_va_list) __THROW;
extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t) __THROW;
extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t) __THROW;
extern _IO_off64_t _IO_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
extern _IO_off64_t _IO_seekpos (_IO_FILE *, _IO_off64_t, int) __THROW;
extern void _IO_free_backup_area (_IO_FILE *) __THROW;
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
extern _IO_wint_t _IO_getwc (_IO_FILE *__fp) __THROW;
extern _IO_wint_t _IO_putwc (wchar_t __wc, _IO_FILE *__fp) __THROW;
extern int _IO_fwide (_IO_FILE *__fp, int __mode) __THROW;
# if __GNUC__ >= 2
/* While compiling glibc we have to handle compatibility with very old
versions. */
# if defined _LIBC && defined SHARED
# include <shlib-compat.h>
# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
# define _IO_fwide_maybe_incompatible \
(__builtin_expect (&_IO_stdin_used == NULL, 0))
extern const int _IO_stdin_used;
weak_extern (_IO_stdin_used);
# endif
# endif
# ifndef _IO_fwide_maybe_incompatible
# define _IO_fwide_maybe_incompatible (0)
# endif
/* A special optimized version of the function above. It optimizes the
case of initializing an unoriented byte stream. */
# define _IO_fwide(__fp, __mode) \
({ int __result = (__mode); \
if (__result < 0 && ! _IO_fwide_maybe_incompatible) \
{ \
if ((__fp)->_mode == 0) \
/* We know that all we have to do is to set the flag. */ \
(__fp)->_mode = -1; \
__result = (__fp)->_mode; \
} \
else if (__builtin_constant_p (__mode) && (__mode) == 0) \
__result = (__fp)->_mode; \
else \
__result = _IO_fwide (__fp, __result); \
__result; })
# endif
extern int _IO_vfwscanf (_IO_FILE * __restrict, const wchar_t * __restrict,
_IO_va_list, int *__restrict) __THROW;
extern int _IO_vfwprintf (_IO_FILE *__restrict, const wchar_t *__restrict,
_IO_va_list) __THROW;
extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t) __THROW;
extern void _IO_free_wbackup_area (_IO_FILE *) __THROW;
#endif
#ifdef __cplusplus
}
#endif
#endif /* _IO_STDIO_H */

View File

@ -0,0 +1,973 @@
/* Copyright (C) 1993, 1997-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#ifndef _LIBIO_P_H_
#define _LIBIO_P_H_
#include <errno.h>
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <bits/libc-lock.h>
#else
/*# include <comthread.h>*/
#endif
#include "iolibio.h"
/* Control of exported symbols. Used in glibc. By default we don't
do anything. */
#ifndef INTUSE
# define INTUSE(name) name
#endif
#ifndef INTDEF
# define INTDEF(name)
#endif
#ifndef INTDEF2
# define INTDEF2(name)
#endif
#ifndef libc_hidden_proto
# define libc_hidden_proto(name)
#endif
#ifndef libc_hidden_def
# define libc_hidden_def(name)
#endif
#ifndef libc_hidden_weak
# define libc_hidden_weak(name)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define _IO_seek_set 0
#define _IO_seek_cur 1
#define _IO_seek_end 2
/* THE JUMPTABLE FUNCTIONS.
* The _IO_FILE type is used to implement the FILE type in GNU libc,
* as well as the streambuf class in GNU iostreams for C++.
* These are all the same, just used differently.
* An _IO_FILE (or FILE) object is allows followed by a pointer to
* a jump table (of pointers to functions). The pointer is accessed
* with the _IO_JUMPS macro. The jump table has a eccentric format,
* so as to be compatible with the layout of a C++ virtual function table.
* (as implemented by g++). When a pointer to a streambuf object is
* coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
* happens to point to the virtual function table of the streambuf.
* Thus the _IO_JUMPS function table used for C stdio/libio does
* double duty as the virtual function table for C++ streambuf.
*
* The entries in the _IO_JUMPS function table (and hence also the
* virtual functions of a streambuf) are described below.
* The first parameter of each function entry is the _IO_FILE/streambuf
* object being acted on (i.e. the 'this' parameter).
*/
#ifdef _LIBC
# include <shlib-compat.h>
# if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
/* Setting this macro disables the use of the _vtable_offset
bias in _IO_JUMPS_FUNCS, below. That is only needed if we
want to support old binaries (see oldfileops.c). */
# define _G_IO_NO_BACKWARD_COMPAT 1
# endif
#endif
#if (!defined _IO_USE_OLD_IO_FILE \
&& (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
# define _IO_JUMPS_OFFSET 1
#endif
#define _IO_JUMPS(THIS) (THIS)->vtable
#define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
#define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
#if _IO_JUMPS_OFFSET
# define _IO_JUMPS_FUNC(THIS) \
(*(struct _IO_jump_t **) ((void *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \
+ (THIS)->_vtable_offset))
#else
# define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
#endif
#define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
#ifdef _G_USING_THUNKS
# define JUMP_FIELD(TYPE, NAME) TYPE NAME
# define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
# define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
# define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
# define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
# define JUMP_INIT(NAME, VALUE) VALUE
# define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
# define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
# define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
# define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
# define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
#else
/* These macros will change when we re-implement vtables to use "thunks"! */
# define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
# define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
# define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
# define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
# define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
# define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
# define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
# define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
# define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
#endif
/* The 'finish' function does any final cleaning up of an _IO_FILE object.
It does not delete (free) it, but does everything else to finalize it.
It matches the streambuf::~streambuf virtual destructor. */
typedef void (*_IO_finish_t) __PMT ((_IO_FILE *, int)); /* finalize */
#define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
#define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
/* The 'overflow' hook flushes the buffer.
The second argument is a character, or EOF.
It matches the streambuf::overflow virtual function. */
typedef int (*_IO_overflow_t) __PMT ((_IO_FILE *, int));
#define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
#define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
/* The 'underflow' hook tries to fills the get buffer.
It returns the next character (as an unsigned char) or EOF. The next
character remains in the get buffer, and the get position is not changed.
It matches the streambuf::underflow virtual function. */
typedef int (*_IO_underflow_t) __PMT ((_IO_FILE *));
#define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
#define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
/* The 'uflow' hook returns the next character in the input stream
(cast to unsigned char), and increments the read position;
EOF is returned on failure.
It matches the streambuf::uflow virtual function, which is not in the
cfront implementation, but was added to C++ by the ANSI/ISO committee. */
#define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
#define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
/* The 'pbackfail' hook handles backing up.
It matches the streambuf::pbackfail virtual function. */
typedef int (*_IO_pbackfail_t) __PMT ((_IO_FILE *, int));
#define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
#define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
/* The 'xsputn' hook writes upto N characters from buffer DATA.
Returns the number of character actually written.
It matches the streambuf::xsputn virtual function. */
typedef _IO_size_t (*_IO_xsputn_t) __PMT ((_IO_FILE *FP, const void *DATA,
_IO_size_t N));
#define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
#define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
/* The 'xsgetn' hook reads upto N characters into buffer DATA.
Returns the number of character actually read.
It matches the streambuf::xsgetn virtual function. */
typedef _IO_size_t (*_IO_xsgetn_t) __PMT ((_IO_FILE *FP, void *DATA,
_IO_size_t N));
#define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
#define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
/* The 'seekoff' hook moves the stream position to a new position
relative to the start of the file (if DIR==0), the current position
(MODE==1), or the end of the file (MODE==2).
It matches the streambuf::seekoff virtual function.
It is also used for the ANSI fseek function. */
typedef _IO_off64_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off64_t OFF,
int DIR, int MODE));
#define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
#define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
/* The 'seekpos' hook also moves the stream position,
but to an absolute position given by a fpos64_t (seekpos).
It matches the streambuf::seekpos virtual function.
It is also used for the ANSI fgetpos and fsetpos functions. */
/* The _IO_seek_cur and _IO_seek_end options are not allowed. */
typedef _IO_off64_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
#define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
#define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
/* The 'setbuf' hook gives a buffer to the file.
It matches the streambuf::setbuf virtual function. */
typedef _IO_FILE* (*_IO_setbuf_t) __PMT ((_IO_FILE *, char *, _IO_ssize_t));
#define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
#define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
/* The 'sync' hook attempts to synchronize the internal data structures
of the file with the external state.
It matches the streambuf::sync virtual function. */
typedef int (*_IO_sync_t) __PMT ((_IO_FILE *));
#define _IO_SYNC(FP) JUMP0 (__sync, FP)
#define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
/* The 'doallocate' hook is used to tell the file to allocate a buffer.
It matches the streambuf::doallocate virtual function, which is not
in the ANSI/ISO C++ standard, but is part traditional implementations. */
typedef int (*_IO_doallocate_t) __PMT ((_IO_FILE *));
#define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
#define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
/* The following four hooks (sysread, syswrite, sysclose, sysseek, and
sysstat) are low-level hooks specific to this implementation.
There is no correspondence in the ANSI/ISO C++ standard library.
The hooks basically correspond to the Unix system functions
(read, write, close, lseek, and stat) except that a _IO_FILE*
parameter is used instead of a integer file descriptor; the default
implementation used for normal files just calls those functions.
The advantage of overriding these functions instead of the higher-level
ones (underflow, overflow etc) is that you can leave all the buffering
higher-level functions. */
/* The 'sysread' hook is used to read data from the external file into
an existing buffer. It generalizes the Unix read(2) function.
It matches the streambuf::sys_read virtual function, which is
specific to this implementation. */
typedef _IO_ssize_t (*_IO_read_t) __PMT ((_IO_FILE *, void *, _IO_ssize_t));
#define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
#define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
/* The 'syswrite' hook is used to write data from an existing buffer
to an external file. It generalizes the Unix write(2) function.
It matches the streambuf::sys_write virtual function, which is
specific to this implementation. */
typedef _IO_ssize_t (*_IO_write_t) __PMT ((_IO_FILE *, const void *,
_IO_ssize_t));
#define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
#define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
/* The 'sysseek' hook is used to re-position an external file.
It generalizes the Unix lseek(2) function.
It matches the streambuf::sys_seek virtual function, which is
specific to this implementation. */
typedef _IO_off64_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
#define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
#define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
/* The 'sysclose' hook is used to finalize (close, finish up) an
external file. It generalizes the Unix close(2) function.
It matches the streambuf::sys_close virtual function, which is
specific to this implementation. */
typedef int (*_IO_close_t) __PMT ((_IO_FILE *)); /* finalize */
#define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
#define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
/* The 'sysstat' hook is used to get information about an external file
into a struct stat buffer. It generalizes the Unix fstat(2) call.
It matches the streambuf::sys_stat virtual function, which is
specific to this implementation. */
typedef int (*_IO_stat_t) __PMT ((_IO_FILE *, void *));
#define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
#define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
/* The 'showmany' hook can be used to get an image how much input is
available. In many cases the answer will be 0 which means unknown
but some cases one can provide real information. */
typedef int (*_IO_showmanyc_t) __PMT ((_IO_FILE *));
#define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
#define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
/* The 'imbue' hook is used to get information about the currently
installed locales. */
typedef void (*_IO_imbue_t) __PMT ((_IO_FILE *, void *));
#define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
#define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
#define _IO_CHAR_TYPE char /* unsigned char ? */
#define _IO_INT_TYPE int
struct _IO_jump_t
{
JUMP_FIELD(_G_size_t, __dummy);
#ifdef _G_USING_THUNKS
JUMP_FIELD(_G_size_t, __dummy2);
#endif
JUMP_FIELD(_IO_finish_t, __finish);
JUMP_FIELD(_IO_overflow_t, __overflow);
JUMP_FIELD(_IO_underflow_t, __underflow);
JUMP_FIELD(_IO_underflow_t, __uflow);
JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
/* showmany */
JUMP_FIELD(_IO_xsputn_t, __xsputn);
JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
JUMP_FIELD(_IO_seekoff_t, __seekoff);
JUMP_FIELD(_IO_seekpos_t, __seekpos);
JUMP_FIELD(_IO_setbuf_t, __setbuf);
JUMP_FIELD(_IO_sync_t, __sync);
JUMP_FIELD(_IO_doallocate_t, __doallocate);
JUMP_FIELD(_IO_read_t, __read);
JUMP_FIELD(_IO_write_t, __write);
JUMP_FIELD(_IO_seek_t, __seek);
JUMP_FIELD(_IO_close_t, __close);
JUMP_FIELD(_IO_stat_t, __stat);
JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
JUMP_FIELD(_IO_imbue_t, __imbue);
#if 0
get_column;
set_column;
#endif
};
/* We always allocate an extra word following an _IO_FILE.
This contains a pointer to the function jump table used.
This is for compatibility with C++ streambuf; the word can
be used to smash to a pointer to a virtual function table. */
struct _IO_FILE_plus
{
_IO_FILE file;
const struct _IO_jump_t *vtable;
};
/* Special file type for fopencookie function. */
struct _IO_cookie_file
{
struct _IO_FILE_plus __fp;
void *__cookie;
_IO_cookie_io_functions_t __io_functions;
};
_IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
_IO_cookie_io_functions_t io_functions);
/* Iterator type for walking global linked list of _IO_FILE objects. */
typedef struct _IO_FILE *_IO_ITER;
/* Generic functions */
extern void _IO_switch_to_main_get_area __P ((_IO_FILE *));
extern void _IO_switch_to_backup_area __P ((_IO_FILE *));
extern int _IO_switch_to_get_mode __P ((_IO_FILE *));
extern void _IO_init __P ((_IO_FILE *, int));
extern int _IO_sputbackc __P ((_IO_FILE *, int));
extern int _IO_sungetc __P ((_IO_FILE *));
extern void _IO_un_link __P ((struct _IO_FILE_plus *));
extern void _IO_link_in __P ((struct _IO_FILE_plus *));
extern void _IO_doallocbuf __P ((_IO_FILE *));
extern void _IO_unsave_markers __P ((_IO_FILE *));
extern void _IO_setb __P ((_IO_FILE *, char *, char *, int));
extern unsigned _IO_adjust_column __P ((unsigned, const char *, int));
#define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
extern void _IO_switch_to_main_wget_area __P ((_IO_FILE *));
extern void _IO_switch_to_wbackup_area __P ((_IO_FILE *));
extern int _IO_switch_to_wget_mode __P ((_IO_FILE *));
extern void _IO_wsetb __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
extern wint_t _IO_sputbackwc __P ((_IO_FILE *, wint_t));
extern wint_t _IO_sungetwc __P ((_IO_FILE *));
extern void _IO_wdoallocbuf __P ((_IO_FILE *));
extern void _IO_unsave_wmarkers __P ((_IO_FILE *));
extern unsigned _IO_adjust_wcolumn __P ((unsigned, const wchar_t *, int));
/* Marker-related function. */
extern void _IO_init_marker __P ((struct _IO_marker *, _IO_FILE *));
extern void _IO_init_wmarker __P ((struct _IO_marker *, _IO_FILE *));
extern void _IO_remove_marker __P ((struct _IO_marker *));
extern int _IO_marker_difference __P ((struct _IO_marker *,
struct _IO_marker *));
extern int _IO_marker_delta __P ((struct _IO_marker *));
extern int _IO_wmarker_delta __P ((struct _IO_marker *));
extern int _IO_seekmark __P ((_IO_FILE *, struct _IO_marker *, int));
extern int _IO_seekwmark __P ((_IO_FILE *, struct _IO_marker *, int));
/* Functions for iterating global list and dealing with
its lock */
extern _IO_ITER _IO_iter_begin __P ((void));
libc_hidden_proto (_IO_iter_begin)
extern _IO_ITER _IO_iter_end __P ((void));
libc_hidden_proto (_IO_iter_end)
extern _IO_ITER _IO_iter_next __P ((_IO_ITER));
libc_hidden_proto (_IO_iter_next)
extern _IO_FILE *_IO_iter_file __P ((_IO_ITER));
libc_hidden_proto (_IO_iter_file)
extern void _IO_list_lock __P ((void));
libc_hidden_proto (_IO_list_lock)
extern void _IO_list_unlock __P ((void));
libc_hidden_proto (_IO_list_unlock)
extern void _IO_list_resetlock __P ((void));
libc_hidden_proto (_IO_list_resetlock)
/* Default jumptable functions. */
extern int _IO_default_underflow __P ((_IO_FILE *));
extern int _IO_default_uflow __P ((_IO_FILE *));
extern wint_t _IO_wdefault_uflow __P ((_IO_FILE *));
extern int _IO_default_doallocate __P ((_IO_FILE *));
extern int _IO_wdefault_doallocate __P ((_IO_FILE *));
extern void _IO_default_finish __P ((_IO_FILE *, int));
extern void _IO_wdefault_finish __P ((_IO_FILE *, int));
extern int _IO_default_pbackfail __P ((_IO_FILE *, int));
extern wint_t _IO_wdefault_pbackfail __P ((_IO_FILE *, wint_t));
extern _IO_FILE* _IO_default_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
extern _IO_size_t _IO_default_xsputn __P ((_IO_FILE *, const void *,
_IO_size_t));
extern _IO_size_t _IO_wdefault_xsputn __P ((_IO_FILE *, const void *,
_IO_size_t));
extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
extern _IO_size_t _IO_wdefault_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
extern _IO_off64_t _IO_default_seekoff __P ((_IO_FILE *,
_IO_off64_t, int, int));
extern _IO_off64_t _IO_default_seekpos __P ((_IO_FILE *, _IO_off64_t, int));
extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
_IO_ssize_t));
extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
extern int _IO_default_stat __P ((_IO_FILE *, void *));
extern _IO_off64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
extern int _IO_default_sync __P ((_IO_FILE *));
#define _IO_default_close ((_IO_close_t) _IO_default_sync)
extern int _IO_default_showmanyc __P ((_IO_FILE *));
extern void _IO_default_imbue __P ((_IO_FILE *, void *));
extern struct _IO_jump_t _IO_file_jumps;
extern struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
extern struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
extern struct _IO_jump_t _IO_wfile_jumps attribute_hidden;
extern struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
extern struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
extern struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
extern struct _IO_jump_t _IO_streambuf_jumps;
extern struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
extern struct _IO_jump_t _IO_str_jumps attribute_hidden;
extern struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
extern struct _IO_codecvt __libio_codecvt attribute_hidden;
extern int _IO_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
extern int _IO_new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
extern int _IO_old_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
extern int _IO_wdo_write __P ((_IO_FILE *, const wchar_t *, _IO_size_t));
extern int _IO_flush_all_lockp __P ((int));
extern int _IO_flush_all __P ((void));
extern int _IO_cleanup __P ((void));
extern void _IO_flush_all_linebuffered __P ((void));
extern int _IO_new_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
extern int _IO_old_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
extern int _IO_new_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
extern int _IO_old_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
extern int _IO_new_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
extern int _IO_old_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
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 defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
# define _IO_do_flush(_f) \
((_f)->_mode <= 0 \
? INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
(_f)->_IO_write_ptr-(_f)->_IO_write_base) \
: INTUSE(_IO_wdo_write)(_f, (_f)->_wide_data->_IO_write_base, \
((_f)->_wide_data->_IO_write_ptr \
- (_f)->_wide_data->_IO_write_base)))
#else
# 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)
#define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
#define _IO_mask_flags(fp, f, mask) \
((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
#define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
(fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
#define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
(fp)->_wide_data->_IO_read_ptr = (g), \
(fp)->_wide_data->_IO_read_end = (eg))
#define _IO_setp(__fp, __p, __ep) \
((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
= __p, (__fp)->_IO_write_end = (__ep))
#define _IO_wsetp(__fp, __p, __ep) \
((__fp)->_wide_data->_IO_write_base \
= (__fp)->_wide_data->_IO_write_ptr = __p, \
(__fp)->_wide_data->_IO_write_end = (__ep))
#define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
#define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
#define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
#define _IO_have_markers(fp) ((fp)->_markers != NULL)
#define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
#define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
- (fp)->_wide_data->_IO_buf_base)
/* Jumptable functions for files. */
extern int _IO_file_doallocate __P ((_IO_FILE *));
extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
extern _IO_off64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
extern _IO_off64_t _IO_file_seekoff_mmap __P ((_IO_FILE *, _IO_off64_t, int,
int));
extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
extern _IO_size_t _IO_file_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
extern int _IO_file_stat __P ((_IO_FILE *, void *));
extern int _IO_file_close __P ((_IO_FILE *));
extern int _IO_file_close_mmap __P ((_IO_FILE *));
extern int _IO_file_underflow __P ((_IO_FILE *));
extern int _IO_file_underflow_mmap __P ((_IO_FILE *));
extern int _IO_file_underflow_maybe_mmap __P ((_IO_FILE *));
extern int _IO_file_overflow __P ((_IO_FILE *, int));
#define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
extern void _IO_file_init __P ((struct _IO_FILE_plus *));
extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int));
extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
int, int));
libc_hidden_proto (_IO_file_open)
extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
int));
extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *,
_IO_ssize_t));
extern _IO_ssize_t _IO_file_read __P ((_IO_FILE *, void *, _IO_ssize_t));
extern int _IO_file_sync __P ((_IO_FILE *));
extern int _IO_file_close_it __P ((_IO_FILE *));
extern _IO_off64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
extern void _IO_file_finish __P ((_IO_FILE *, int));
extern _IO_FILE* _IO_new_file_attach __P ((_IO_FILE *, int));
extern int _IO_new_file_close_it __P ((_IO_FILE *));
extern void _IO_new_file_finish __P ((_IO_FILE *, int));
extern _IO_FILE* _IO_new_file_fopen __P ((_IO_FILE *, const char *, const char *,
int));
extern void _IO_no_init __P ((_IO_FILE *, int, int, struct _IO_wide_data *,
struct _IO_jump_t *));
extern void _IO_new_file_init __P ((struct _IO_FILE_plus *));
extern _IO_FILE* _IO_new_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
extern _IO_FILE* _IO_file_setbuf_mmap __P ((_IO_FILE *, char *, _IO_ssize_t));
extern int _IO_new_file_sync __P ((_IO_FILE *));
extern int _IO_new_file_underflow __P ((_IO_FILE *));
extern int _IO_new_file_overflow __P ((_IO_FILE *, int));
extern _IO_off64_t _IO_new_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
extern _IO_ssize_t _IO_new_file_write __P ((_IO_FILE *, const void *,
_IO_ssize_t));
extern _IO_size_t _IO_new_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
extern _IO_FILE* _IO_old_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
extern _IO_off64_t _IO_old_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int,
int));
extern _IO_size_t _IO_old_file_xsputn __P ((_IO_FILE *, const void *,
_IO_size_t));
extern int _IO_old_file_underflow __P ((_IO_FILE *));
extern int _IO_old_file_overflow __P ((_IO_FILE *, int));
extern void _IO_old_file_init __P ((struct _IO_FILE_plus *));
extern _IO_FILE* _IO_old_file_attach __P ((_IO_FILE *, int));
extern _IO_FILE* _IO_old_file_fopen __P ((_IO_FILE *, const char *,
const char *));
extern _IO_ssize_t _IO_old_file_write __P ((_IO_FILE *, const void *,
_IO_ssize_t));
extern int _IO_old_file_sync __P ((_IO_FILE *));
extern int _IO_old_file_close_it __P ((_IO_FILE *));
extern void _IO_old_file_finish __P ((_IO_FILE *, int));
extern int _IO_wfile_doallocate __P ((_IO_FILE *));
extern _IO_size_t _IO_wfile_xsputn __P ((_IO_FILE *, const void *,
_IO_size_t));
extern _IO_FILE* _IO_wfile_setbuf __P ((_IO_FILE *, wchar_t *, _IO_ssize_t));
extern wint_t _IO_wfile_sync __P ((_IO_FILE *));
extern wint_t _IO_wfile_underflow __P ((_IO_FILE *));
extern wint_t _IO_wfile_overflow __P ((_IO_FILE *, wint_t));
extern _IO_off64_t _IO_wfile_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
/* Jumptable functions for proc_files. */
extern _IO_FILE* _IO_proc_open __P ((_IO_FILE *, const char *, const char *));
extern _IO_FILE* _IO_new_proc_open __P ((_IO_FILE *, const char *, const char *));
extern _IO_FILE* _IO_old_proc_open __P ((_IO_FILE *, const char *, const char *));
extern int _IO_proc_close __P ((_IO_FILE *));
extern int _IO_new_proc_close __P ((_IO_FILE *));
extern int _IO_old_proc_close __P ((_IO_FILE *));
/* Jumptable functions for strfiles. */
extern int _IO_str_underflow __P ((_IO_FILE *));
extern int _IO_str_overflow __P ((_IO_FILE *, int));
extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
extern _IO_off64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
extern void _IO_str_finish __P ((_IO_FILE *, int));
/* Other strfile functions */
struct _IO_strfile_;
extern void _IO_str_init_static __P ((struct _IO_strfile_ *, char *, int, char *));
extern void _IO_str_init_readonly __P ((struct _IO_strfile_ *, const char *, int));
extern _IO_ssize_t _IO_str_count __P ((_IO_FILE *));
/* And the wide character versions. */
extern void _IO_wstr_init_static __P ((_IO_FILE *, wchar_t *, int, wchar_t *));
extern void _IO_wstr_init_readonly __P ((_IO_FILE *, const char *, int));
extern _IO_ssize_t _IO_wstr_count __P ((_IO_FILE *));
extern _IO_wint_t _IO_wstr_overflow __P ((_IO_FILE *, _IO_wint_t));
extern _IO_wint_t _IO_wstr_underflow __P ((_IO_FILE *));
extern _IO_off64_t _IO_wstr_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
extern _IO_wint_t _IO_wstr_pbackfail __P ((_IO_FILE *, _IO_wint_t));
extern void _IO_wstr_finish __P ((_IO_FILE *, int));
extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
_IO_va_list args));
extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
__const char *format, _IO_va_list args));
extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
int, int, int *));
extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
extern _IO_size_t _IO_getwline __P ((_IO_FILE *,wchar_t *, _IO_size_t, wint_t,
int));
extern _IO_size_t _IO_getwline_info __P ((_IO_FILE *,wchar_t *, _IO_size_t,
wint_t, int, wint_t *));
extern double _IO_strtod __P ((const char *, char **));
extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
int *__decpt, int *__sign, char **__rve));
extern int _IO_outfloat __P ((double __value, _IO_FILE *__sb, int __type,
int __width, int __precision, int __flags,
int __sign_mode, int __fill));
extern struct _IO_FILE_plus *_IO_list_all;
extern void (*_IO_cleanup_registration_needed) __PMT ((void));
/* Prototype for functions with alternative entry point. */
extern int _IO_flush_all_internal __P ((void));
extern unsigned _IO_adjust_column_internal __P ((unsigned, const char *, int));
extern int _IO_default_uflow_internal __P ((_IO_FILE *));
extern void _IO_default_finish_internal __P ((_IO_FILE *, int));
extern int _IO_default_pbackfail_internal __P ((_IO_FILE *, int));
extern _IO_size_t _IO_default_xsputn_internal __P ((_IO_FILE *, const void *,
_IO_size_t));
extern _IO_size_t _IO_default_xsgetn_internal __P ((_IO_FILE *, void *,
_IO_size_t));
extern int _IO_default_doallocate_internal __P ((_IO_FILE *));
extern void _IO_wdefault_finish_internal __P ((_IO_FILE *, int));
extern wint_t _IO_wdefault_pbackfail_internal __P ((_IO_FILE *, wint_t));
extern _IO_size_t _IO_wdefault_xsputn_internal __P ((_IO_FILE *, const void *,
_IO_size_t));
extern _IO_size_t _IO_wdefault_xsgetn_internal __P ((_IO_FILE *, void *,
_IO_size_t));
extern int _IO_wdefault_doallocate_internal __P ((_IO_FILE *));
extern wint_t _IO_wdefault_uflow_internal __P ((_IO_FILE *));
extern int _IO_file_doallocate_internal __P ((_IO_FILE *));
extern _IO_FILE* _IO_file_setbuf_internal __P ((_IO_FILE *, char *,
_IO_ssize_t));
extern _IO_off64_t _IO_file_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
int, int));
extern _IO_size_t _IO_file_xsputn_internal __P ((_IO_FILE *, const void *,
_IO_size_t));
extern _IO_size_t _IO_file_xsgetn_internal __P ((_IO_FILE *, void *,
_IO_size_t));
extern int _IO_file_stat_internal __P ((_IO_FILE *, void *));
extern int _IO_file_close_internal __P ((_IO_FILE *));
extern int _IO_file_close_it_internal __P ((_IO_FILE *));
extern int _IO_file_underflow_internal __P ((_IO_FILE *));
extern int _IO_file_overflow_internal __P ((_IO_FILE *, int));
extern void _IO_file_init_internal __P ((struct _IO_FILE_plus *));
extern _IO_FILE* _IO_file_attach_internal __P ((_IO_FILE *, int));
extern _IO_FILE* _IO_file_fopen_internal __P ((_IO_FILE *, const char *,
const char *, int));
extern _IO_ssize_t _IO_file_read_internal __P ((_IO_FILE *, void *,
_IO_ssize_t));
extern int _IO_file_sync_internal __P ((_IO_FILE *));
extern _IO_off64_t _IO_file_seek_internal __P ((_IO_FILE *, _IO_off64_t, int));
extern void _IO_file_finish_internal __P ((_IO_FILE *, int));
extern _IO_size_t _IO_wfile_xsputn_internal __P ((_IO_FILE *, const void *,
_IO_size_t));
extern _IO_off64_t _IO_wfile_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
int, int));
extern wint_t _IO_wfile_sync_internal __P ((_IO_FILE *));
extern int _IO_str_underflow_internal __P ((_IO_FILE *));
extern int _IO_str_overflow_internal __P ((_IO_FILE *, int));
extern int _IO_str_pbackfail_internal __P ((_IO_FILE *, int));
extern _IO_off64_t _IO_str_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
int, int));
extern void _IO_str_init_static_internal __P ((struct _IO_strfile_ *, char *,
int, char *));
extern struct _IO_jump_t _IO_file_jumps_internal attribute_hidden;
extern struct _IO_jump_t _IO_wfile_jumps_internal attribute_hidden;
extern struct _IO_FILE_plus *_IO_list_all_internal attribute_hidden;
extern void _IO_link_in_internal __P ((struct _IO_FILE_plus *));
extern int _IO_sputbackc_internal __P ((_IO_FILE *, int));
extern void _IO_wdoallocbuf_internal __P ((_IO_FILE *));
extern _IO_size_t _IO_sgetn_internal (_IO_FILE *, void *, _IO_size_t);
extern void _IO_flush_all_linebuffered_internal __P ((void));
extern int _IO_switch_to_wget_mode_internal __P ((_IO_FILE *));
extern void _IO_unsave_markers_internal __P ((_IO_FILE *));
extern void _IO_switch_to_main_wget_area_internal __P ((_IO_FILE *));
extern int _IO_wdo_write_internal __P ((_IO_FILE *, const wchar_t *,
_IO_size_t));
extern int _IO_do_write_internal __P ((_IO_FILE *, const char *, _IO_size_t));
extern _IO_ssize_t _IO_padn_internal (_IO_FILE *, int, _IO_ssize_t);
extern _IO_size_t _IO_getline_info_internal __P ((_IO_FILE *,char *,
_IO_size_t, int, int,
int *));
extern _IO_size_t _IO_getline_internal __P ((_IO_FILE *, char *, _IO_size_t,
int, int));
extern void _IO_free_wbackup_area_internal (_IO_FILE *);
extern void _IO_free_backup_area_internal (_IO_FILE *);
extern void _IO_switch_to_wbackup_area_internal __P ((_IO_FILE *));
extern void _IO_setb_internal __P ((_IO_FILE *, char *, char *, int));
extern wint_t _IO_sputbackwc_internal __P ((_IO_FILE *, wint_t));
extern int _IO_switch_to_get_mode_internal __P ((_IO_FILE *));
extern int _IO_vfscanf_internal (_IO_FILE * __restrict,
const char * __restrict,
_IO_va_list, int *__restrict);
extern int _IO_vfprintf_internal (_IO_FILE *__restrict, const char *__restrict,
_IO_va_list);
extern void _IO_doallocbuf_internal __P ((_IO_FILE *));
extern void _IO_wsetb_internal __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
attribute_hidden;
extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
attribute_hidden;
extern int _IO_putc_internal (int __c, _IO_FILE *__fp);
extern void _IO_init_internal __P ((_IO_FILE *, int));
extern void _IO_un_link_internal __P ((struct _IO_FILE_plus *));
#ifndef EOF
# define EOF (-1)
#endif
#ifndef NULL
# if defined __GNUG__ && \
(__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
# define NULL (__null)
# else
# if !defined(__cplusplus)
# define NULL ((void*)0)
# else
# define NULL (0)
# endif
# endif
#endif
#if _G_HAVE_MMAP
# include <unistd.h>
# include <fcntl.h>
# include <sys/mman.h>
# include <sys/param.h>
# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
# define MAP_ANONYMOUS MAP_ANON
# endif
# if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
# undef _G_HAVE_MMAP
# define _G_HAVE_MMAP 0
# endif
#endif /* _G_HAVE_MMAP */
#if _G_HAVE_MMAP
# ifdef _LIBC
/* When using this code in the GNU libc we must not pollute the name space. */
# define mmap __mmap
# define munmap __munmap
# define ftruncate __ftruncate
# endif
# define ROUND_TO_PAGE(_S) \
(((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
# define FREE_BUF(_B, _S) \
munmap ((_B), ROUND_TO_PAGE (_S))
# define ALLOC_BUF(_B, _S, _R) \
do { \
(_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
PROT_READ | PROT_WRITE, \
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
if ((_B) == (char *) MAP_FAILED) \
return (_R); \
} while (0)
# define ALLOC_WBUF(_B, _S, _R) \
do { \
(_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
PROT_READ | PROT_WRITE, \
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
if ((_B) == (wchar_t *) MAP_FAILED) \
return (_R); \
} while (0)
#else /* _G_HAVE_MMAP */
# define FREE_BUF(_B, _S) \
free(_B)
# define ALLOC_BUF(_B, _S, _R) \
do { \
(_B) = (char*)malloc(_S); \
if ((_B) == NULL) \
return (_R); \
} while (0)
# define ALLOC_WBUF(_B, _S, _R) \
do { \
(_B) = (wchar_t *)malloc(_S); \
if ((_B) == NULL) \
return (_R); \
} while (0)
#endif /* _G_HAVE_MMAP */
#ifndef OS_FSTAT
# define OS_FSTAT fstat
#endif
struct stat;
extern _IO_ssize_t _IO_read __P ((int, void *, _IO_size_t));
extern _IO_ssize_t _IO_write __P ((int, const void *, _IO_size_t));
extern _IO_off64_t _IO_lseek __P ((int, _IO_off64_t, int));
extern int _IO_close __P ((int));
extern int _IO_fstat __P ((int, struct stat *));
extern int _IO_vscanf __P ((const char *, _IO_va_list));
/* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
#ifndef _IO_pos_BAD
# define _IO_pos_BAD ((_IO_off64_t) -1)
#endif
/* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
#ifndef _IO_pos_adjust
# define _IO_pos_adjust(pos, delta) ((pos) += (delta))
#endif
/* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
#ifndef _IO_pos_0
# define _IO_pos_0 ((_IO_off64_t) 0)
#endif
#ifdef __cplusplus
}
#endif
#ifdef _IO_MTSAFE_IO
/* check following! */
# ifdef _IO_USE_OLD_IO_FILE
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
# else
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
NULL, WDP, 0 }
# else
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
0 }
# endif
# endif
#else
# ifdef _IO_USE_OLD_IO_FILE
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
0, _IO_pos_BAD }
# else
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
NULL, WDP, 0 }
# else
# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
0 }
# endif
# endif
#endif
/* VTABLE_LABEL defines NAME as of the CLASS class.
CNLENGTH is strlen(#CLASS). */
#ifdef __GNUC__
# if _G_VTABLE_LABEL_HAS_LENGTH
# define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
# else
# define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
# endif
#endif /* __GNUC__ */
#if !defined(builtinbuf_vtable) && defined(__cplusplus)
# ifdef __GNUC__
VTABLE_LABEL(builtinbuf_vtable, builtinbuf, 10)
# else
# if _G_VTABLE_LABEL_HAS_LENGTH
# define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
# else
# define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
# endif
# endif
#endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
#if defined(__STDC__) || defined(__cplusplus)
# define _IO_va_start(args, last) va_start(args, last)
#else
# define _IO_va_start(args, last) va_start(args)
#endif
extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
#if 1
# define COERCE_FILE(FILE) /* Nothing */
#else
/* This is part of the kludge for binary compatibility with old stdio. */
# define COERCE_FILE(FILE) \
(((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
&& (FILE) = *(FILE**)&((int*)fp)[1])
#endif
#ifdef EINVAL
# define MAYBE_SET_EINVAL __set_errno (EINVAL)
#else
# define MAYBE_SET_EINVAL /* nothing */
#endif
#ifdef IO_DEBUG
# define CHECK_FILE(FILE, RET) \
if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
else { COERCE_FILE(FILE); \
if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
{ MAYBE_SET_EINVAL; return RET; }}
#else
# define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
#endif
#endif /* _LIBIO_P_H_ */

View File

@ -0,0 +1,226 @@
/* Copyright (C) 1995,1996,1997,1999,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#include "libioP.h"
#include "strfile.h"
#include <stdio.h>
#include <stdlib.h>
struct _IO_FILE_memstream
{
_IO_strfile _sf;
char **bufloc;
_IO_size_t *sizeloc;
};
static int _IO_mem_sync __P ((_IO_FILE* fp));
static void _IO_mem_finish __P ((_IO_FILE* fp, int));
static int _IO_wmem_sync __P ((_IO_FILE* fp));
static void _IO_wmem_finish __P ((_IO_FILE* fp, int));
static struct _IO_jump_t _IO_mem_jumps =
{
JUMP_INIT_DUMMY,
JUMP_INIT (finish, _IO_mem_finish),
JUMP_INIT (overflow, INTUSE(_IO_str_overflow)),
JUMP_INIT (underflow, INTUSE(_IO_str_underflow)),
JUMP_INIT (uflow, INTUSE(_IO_default_uflow)),
JUMP_INIT (pbackfail, INTUSE(_IO_str_pbackfail)),
JUMP_INIT (xsputn, INTUSE(_IO_default_xsputn)),
JUMP_INIT (xsgetn, INTUSE(_IO_default_xsgetn)),
JUMP_INIT (seekoff, INTUSE(_IO_str_seekoff)),
JUMP_INIT (seekpos, _IO_default_seekpos),
JUMP_INIT (setbuf, _IO_default_setbuf),
JUMP_INIT (sync, _IO_mem_sync),
JUMP_INIT (doallocate, INTUSE(_IO_default_doallocate)),
JUMP_INIT (read, _IO_default_read),
JUMP_INIT (write, _IO_default_write),
JUMP_INIT (seek, _IO_default_seek),
JUMP_INIT (close, _IO_default_close),
JUMP_INIT (stat, _IO_default_stat),
JUMP_INIT(showmanyc, _IO_default_showmanyc),
JUMP_INIT(imbue, _IO_default_imbue)
};
static struct _IO_jump_t _IO_wmem_jumps =
{
JUMP_INIT_DUMMY,
JUMP_INIT (finish, (_IO_finish_t) _IO_wmem_finish),
JUMP_INIT (overflow, (_IO_overflow_t) _IO_wstr_overflow),
JUMP_INIT (underflow, (_IO_underflow_t) _IO_wstr_underflow),
JUMP_INIT (uflow, (_IO_underflow_t) INTUSE(_IO_wdefault_uflow)),
JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail),
JUMP_INIT (xsputn, (_IO_xsputn_t) INTUSE(_IO_wdefault_xsputn)),
JUMP_INIT (xsgetn, (_IO_xsgetn_t) INTUSE(_IO_wdefault_xsgetn)),
JUMP_INIT (seekoff, _IO_wstr_seekoff),
JUMP_INIT (seekpos, _IO_default_seekpos),
JUMP_INIT (setbuf, _IO_default_setbuf),
JUMP_INIT (sync, (_IO_sync_t) _IO_wmem_sync),
JUMP_INIT (doallocate, INTUSE(_IO_wdefault_doallocate)),
JUMP_INIT (read, _IO_default_read),
JUMP_INIT (write, _IO_default_write),
JUMP_INIT (seek, _IO_default_seek),
JUMP_INIT (close, _IO_default_close),
JUMP_INIT (stat, _IO_default_stat),
JUMP_INIT(showmanyc, _IO_default_showmanyc),
JUMP_INIT(imbue, _IO_default_imbue)
};
/* Open a stream that writes into a malloc'd buffer that is expanded as
necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
and the number of characters written on fflush or fclose. */
_IO_FILE *
open_memstream (bufloc, sizeloc)
char **bufloc;
_IO_size_t *sizeloc;
{
struct locked_FILE
{
struct _IO_FILE_memstream fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
struct _IO_wide_data wd;
} *new_f;
char *buf;
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fp._sf._sbf._f._lock = &new_f->lock;
#endif
buf = malloc (_IO_BUFSIZ);
if (buf == NULL)
return NULL;
_IO_no_init (&new_f->fp._sf._sbf._f, 0, 0, &new_f->wd, &_IO_wmem_jumps);
_IO_JUMPS ((struct _IO_FILE_plus *) &new_f->fp._sf._sbf) = &_IO_mem_jumps;
INTUSE(_IO_str_init_static) (&new_f->fp._sf, buf, _IO_BUFSIZ, buf);
new_f->fp._sf._sbf._f._flags &= ~_IO_USER_BUF;
new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc;
new_f->fp._sf._s._free_buffer = (_IO_free_type) free;
new_f->fp.bufloc = bufloc;
new_f->fp.sizeloc = sizeloc;
return (_IO_FILE *) &new_f->fp._sf._sbf;
}
libc_hidden_def (open_memstream)
static int
_IO_mem_sync (fp)
_IO_FILE* fp;
{
struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp;
int res;
res = _IO_default_sync (fp);
if (res < 0)
return res;
if (fp->_IO_write_ptr == fp->_IO_write_end)
{
INTUSE(_IO_str_overflow) (fp, '\0');
--fp->_IO_write_ptr;
}
else
*fp->_IO_write_ptr = '\0';
*mp->bufloc = fp->_IO_write_base;
*mp->sizeloc = fp->_IO_write_ptr - fp->_IO_write_base;
return 0;
}
static void
_IO_mem_finish (fp, dummy)
_IO_FILE* fp;
int dummy;
{
struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp;
*mp->bufloc = (char *) realloc (fp->_IO_write_base,
fp->_IO_write_ptr - fp->_IO_write_base + 1);
if (*mp->bufloc != NULL)
{
(*mp->bufloc)[fp->_IO_write_ptr - fp->_IO_write_base] = '\0';
*mp->sizeloc = fp->_IO_write_ptr - fp->_IO_write_base;
}
fp->_IO_buf_base = NULL;
INTUSE(_IO_default_finish) (fp, 0);
}
static int
_IO_wmem_sync (fp)
_IO_FILE* fp;
{
struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp;
int res;
res = _IO_default_sync (fp);
if (res < 0)
return res;
if (fp->_wide_data->_IO_write_ptr == fp->_wide_data->_IO_write_end)
{
_IO_wstr_overflow (fp, L'\0');
--fp->_wide_data->_IO_write_ptr;
}
else
*fp->_wide_data->_IO_write_ptr = '\0';
*mp->bufloc = (char *) fp->_wide_data->_IO_write_base;
*mp->sizeloc = (fp->_wide_data->_IO_write_ptr
- fp->_wide_data->_IO_write_base);
return 0;
}
static void
_IO_wmem_finish (fp, dummy)
_IO_FILE* fp;
int dummy;
{
struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp;
*mp->bufloc = (char *) realloc (fp->_wide_data->_IO_write_base,
(fp->_wide_data->_IO_write_ptr
- fp->_wide_data->_IO_write_base + 1)
* sizeof (wchar_t));
if (*mp->bufloc != NULL)
{
((wchar_t *) (*mp->bufloc))[fp->_wide_data->_IO_write_ptr
- fp->_wide_data->_IO_write_base] = '\0';
*mp->sizeloc = (fp->_wide_data->_IO_write_ptr
- fp->_wide_data->_IO_write_base);
}
fp->_wide_data->_IO_buf_base = NULL;
INTUSE(_IO_default_finish) (fp, 0);
}

View File

@ -0,0 +1,191 @@
/* Print output of stream to given obstack.
Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
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. */
#include "libioP.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <obstack.h>
#include <stdarg.h>
#include <stdio_ext.h>
struct _IO_obstack_file
{
struct _IO_FILE_plus file;
struct obstack *obstack;
};
static int
_IO_obstack_overflow (_IO_FILE *fp, int c)
{
struct obstack *obstack = ((struct _IO_obstack_file *) fp)->obstack;
int size;
/* Make room for another character. This might as well allocate a
new chunk a memory and moves the old contents over. */
assert (c != EOF);
obstack_1grow (obstack, c);
/* Setup the buffer pointers again. */
fp->_IO_write_base = obstack_base (obstack);
fp->_IO_write_ptr = obstack_next_free (obstack);
size = obstack_room (obstack);
fp->_IO_write_end = fp->_IO_write_ptr + size;
/* Now allocate the rest of the current chunk. */
obstack_blank_fast (obstack, size);
return c;
}
static _IO_size_t
_IO_obstack_xsputn (_IO_FILE *fp, const void *data, _IO_size_t n)
{
struct obstack *obstack = ((struct _IO_obstack_file *) fp)->obstack;
if (fp->_IO_write_ptr + n > fp->_IO_write_end)
{
int size;
/* We need some more memory. First shrink the buffer to the
space we really currently need. */
obstack_blank_fast (obstack, fp->_IO_write_ptr - fp->_IO_write_end);
/* Now grow for N bytes, and put the data there. */
obstack_grow (obstack, data, n);
/* Setup the buffer pointers again. */
fp->_IO_write_base = obstack_base (obstack);
fp->_IO_write_ptr = obstack_next_free (obstack);
size = obstack_room (obstack);
fp->_IO_write_end = fp->_IO_write_ptr + size;
/* Now allocate the rest of the current chunk. */
obstack_blank_fast (obstack, size);
}
else
fp->_IO_write_ptr = __mempcpy (fp->_IO_write_ptr, data, n);
return n;
}
/* the jump table. */
static struct _IO_jump_t _IO_obstack_jumps =
{
JUMP_INIT_DUMMY,
JUMP_INIT(finish, NULL),
JUMP_INIT(overflow, _IO_obstack_overflow),
JUMP_INIT(underflow, NULL),
JUMP_INIT(uflow, NULL),
JUMP_INIT(pbackfail, NULL),
JUMP_INIT(xsputn, _IO_obstack_xsputn),
JUMP_INIT(xsgetn, NULL),
JUMP_INIT(seekoff, NULL),
JUMP_INIT(seekpos, NULL),
JUMP_INIT(setbuf, NULL),
JUMP_INIT(sync, NULL),
JUMP_INIT(doallocate, NULL),
JUMP_INIT(read, NULL),
JUMP_INIT(write, NULL),
JUMP_INIT(seek, NULL),
JUMP_INIT(close, NULL),
JUMP_INIT(stat, NULL),
JUMP_INIT(showmanyc, NULL),
JUMP_INIT(imbue, NULL)
};
int
_IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args)
{
struct obstack_FILE
{
struct _IO_obstack_file ofile;
} new_f;
int result;
int size;
int room;
#ifdef _IO_MTSAFE_IO
new_f.ofile.file.file._lock = NULL;
#endif
_IO_no_init (&new_f.ofile.file.file, _IO_USER_LOCK, -1, NULL, NULL);
_IO_JUMPS (&new_f.ofile.file) = &_IO_obstack_jumps;
room = obstack_room (obstack);
size = obstack_object_size (obstack) + room;
if (size == 0)
{
/* We have to handle the allocation a bit different since the
`_IO_str_init_static' function would handle a size of zero
different from what we expect. */
/* Get more memory. */
obstack_make_room (obstack, 64);
/* Recompute how much room we have. */
room = obstack_room (obstack);
size = room;
assert (size != 0);
}
INTUSE(_IO_str_init_static) ((struct _IO_strfile_ *) &new_f.ofile,
obstack_base (obstack),
size, obstack_next_free (obstack));
/* Now allocate the rest of the current chunk. */
assert (size == (new_f.ofile.file.file._IO_write_end
- new_f.ofile.file.file._IO_write_base));
assert (new_f.ofile.file.file._IO_write_ptr
== (new_f.ofile.file.file._IO_write_base
+ obstack_object_size (obstack)));
obstack_blank_fast (obstack, room);
new_f.ofile.obstack = obstack;
result = INTUSE(_IO_vfprintf) (&new_f.ofile.file.file, format, args);
/* Shrink the buffer to the space we really currently need. */
obstack_blank_fast (obstack, (new_f.ofile.file.file._IO_write_ptr
- new_f.ofile.file.file._IO_write_end));
return result;
}
#ifdef weak_alias
weak_alias (_IO_obstack_vprintf, obstack_vprintf)
#endif
int
_IO_obstack_printf (struct obstack *obstack, const char *format, ...)
{
int result;
va_list ap;
va_start (ap, format);
result = _IO_obstack_vprintf (obstack, format, ap);
va_end (ap);
return result;
}
#ifdef weak_alias
weak_alias (_IO_obstack_printf, obstack_printf)
#endif

View File

@ -0,0 +1,793 @@
/* Copyright (C) 1993,95,97,98,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Per Bothner <bothner@cygnus.com>.
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. */
/* 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)
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#define _IO_USE_OLD_IO_FILE
#include "libioP.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifndef errno
extern int errno;
#endif
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
#ifdef _LIBC
# 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)
#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.
In a filebuf, there is only one current position, instead of two
separate get and put pointers. In get mode, the current position
is that of gptr(); in put mode that of pptr().
The position in the buffer that corresponds to the position
in external file system is normally _IO_read_end, except in putback
mode, when it is _IO_save_end.
If the field _fb._offset is >= 0, it gives the offset in
the file as a whole corresponding to eGptr(). (?)
PUT MODE:
If a filebuf is in put mode, then all of _IO_read_ptr, _IO_read_end,
and _IO_read_base are equal to each other. These are usually equal
to _IO_buf_base, though not necessarily if we have switched from
get mode to put mode. (The reason is to maintain the invariant
that _IO_read_end corresponds to the external file position.)
_IO_write_base is non-NULL and usually equal to _IO_base_base.
We also have _IO_write_end == _IO_buf_end, but only in fully buffered mode.
The un-flushed character are those between _IO_write_base and _IO_write_ptr.
GET MODE:
If a filebuf is in get or putback mode, eback() != egptr().
In get mode, the unread characters are between gptr() and egptr().
The OS file position corresponds to that of egptr().
PUTBACK MODE:
Putback mode is used to remember "excess" characters that have
been sputbackc'd in a separate putback buffer.
In putback mode, the get buffer points to the special putback buffer.
The unread characters are the characters between gptr() and egptr()
in the putback buffer, as well as the area between save_gptr()
and save_egptr(), which point into the original reserve buffer.
(The pointers save_gptr() and save_egptr() are the values
of gptr() and egptr() at the time putback mode was entered.)
The OS position corresponds to that of save_egptr().
LINE BUFFERED OUTPUT:
During line buffered output, _IO_write_base==base() && epptr()==base().
However, ptr() may be anywhere between base() and ebuf().
This forces a call to filebuf::overflow(int C) on every put.
If there is more space in the buffer, and C is not a '\n',
then C is inserted, and pptr() incremented.
UNBUFFERED STREAMS:
If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer.
*/
#define CLOSED_FILEBUF_FLAGS \
(_IO_IS_FILEBUF+_IO_NO_READS+_IO_NO_WRITES+_IO_TIED_PUT_GET)
void
_IO_old_file_init (fp)
struct _IO_FILE_plus *fp;
{
/* POSIX.1 allows another file handle to be used to change the position
of our file descriptor. Hence we actually don't know the actual
position before we do the first fseek (and until a following fflush). */
fp->file._old_offset = _IO_pos_BAD;
fp->file._IO_file_flags |= CLOSED_FILEBUF_FLAGS;
INTUSE(_IO_link_in) (fp);
fp->file._vtable_offset = ((int) sizeof (struct _IO_FILE)
- (int) sizeof (struct _IO_FILE_complete));
fp->file._fileno = -1;
}
int
_IO_old_file_close_it (fp)
_IO_FILE *fp;
{
int write_status, close_status;
if (!_IO_file_is_open (fp))
return EOF;
write_status = _IO_old_do_flush (fp);
INTUSE(_IO_unsave_markers) (fp);
close_status = _IO_SYSCLOSE (fp);
/* Free buffer. */
INTUSE(_IO_setb) (fp, NULL, NULL, 0);
_IO_setg (fp, NULL, NULL, NULL);
_IO_setp (fp, NULL, NULL);
INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);
fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
fp->_fileno = -1;
fp->_old_offset = _IO_pos_BAD;
return close_status ? close_status : write_status;
}
void
_IO_old_file_finish (fp, dummy)
_IO_FILE *fp;
int dummy;
{
if (_IO_file_is_open (fp))
{
_IO_old_do_flush (fp);
if (!(fp->_flags & _IO_DELETE_DONT_CLOSE))
_IO_SYSCLOSE (fp);
}
INTUSE(_IO_default_finish) (fp, 0);
}
_IO_FILE *
_IO_old_file_fopen (fp, filename, mode)
_IO_FILE *fp;
const char *filename;
const char *mode;
{
int oflags = 0, omode;
int read_write, fdesc;
int oprot = 0666;
if (_IO_file_is_open (fp))
return 0;
switch (*mode++)
{
case 'r':
omode = O_RDONLY;
read_write = _IO_NO_WRITES;
break;
case 'w':
omode = O_WRONLY;
oflags = O_CREAT|O_TRUNC;
read_write = _IO_NO_READS;
break;
case 'a':
omode = O_WRONLY;
oflags = O_CREAT|O_APPEND;
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
__set_errno (EINVAL);
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
{
omode = O_RDWR;
read_write &= _IO_IS_APPENDING;
}
fdesc = open (filename, omode|oflags, oprot);
if (fdesc < 0)
return NULL;
fp->_fileno = fdesc;
_IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
if (read_write & _IO_IS_APPENDING)
if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD && errno != ESPIPE)
return NULL;
INTUSE(_IO_link_in) ((struct _IO_FILE_plus *) fp);
return fp;
}
_IO_FILE *
_IO_old_file_attach (fp, fd)
_IO_FILE *fp;
int fd;
{
if (_IO_file_is_open (fp))
return NULL;
fp->_fileno = fd;
fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES);
fp->_flags |= _IO_DELETE_DONT_CLOSE;
/* Get the current position of the file. */
/* We have to do that since that may be junk. */
fp->_old_offset = _IO_pos_BAD;
if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD && errno != ESPIPE)
return NULL;
return fp;
}
_IO_FILE *
_IO_old_file_setbuf (fp, p, len)
_IO_FILE *fp;
char *p;
_IO_ssize_t len;
{
if (_IO_default_setbuf (fp, p, len) == NULL)
return NULL;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
= fp->_IO_buf_base;
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
return fp;
}
static int old_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
/* Write TO_DO bytes from DATA to FP.
Then mark FP as having empty buffers. */
int
_IO_old_do_write (fp, data, to_do)
_IO_FILE *fp;
const char *data;
_IO_size_t to_do;
{
return (to_do == 0 || (_IO_size_t) old_do_write (fp, data, to_do) == to_do)
? 0 : EOF;
}
static
int
old_do_write (fp, data, to_do)
_IO_FILE *fp;
const char *data;
_IO_size_t to_do;
{
_IO_size_t count;
if (fp->_flags & _IO_IS_APPENDING)
/* On a system without a proper O_APPEND implementation,
you would need to sys_seek(0, SEEK_END) here, but is
is not needed nor desirable for Unix- or Posix-like systems.
Instead, just indicate that offset (before and after) is
unpredictable. */
fp->_old_offset = _IO_pos_BAD;
else if (fp->_IO_read_end != fp->_IO_write_base)
{
_IO_off_t new_pos
= _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1);
if (new_pos == _IO_pos_BAD)
return 0;
fp->_old_offset = new_pos;
}
count = _IO_SYSWRITE (fp, data, to_do);
if (fp->_cur_column && count)
fp->_cur_column = INTUSE(_IO_adjust_column) (fp->_cur_column - 1, data,
count) + 1;
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
? fp->_IO_buf_base : fp->_IO_buf_end);
return count;
}
int
_IO_old_file_underflow (fp)
_IO_FILE *fp;
{
_IO_ssize_t count;
#if 0
/* SysV does not make this test; take it out for compatibility */
if (fp->_flags & _IO_EOF_SEEN)
return (EOF);
#endif
if (fp->_flags & _IO_NO_READS)
{
fp->_flags |= _IO_ERR_SEEN;
__set_errno (EBADF);
return EOF;
}
if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char *) fp->_IO_read_ptr;
if (fp->_IO_buf_base == NULL)
{
/* Maybe we already have a push back pointer. */
if (fp->_IO_save_base != NULL)
{
free (fp->_IO_save_base);
fp->_flags &= ~_IO_IN_BACKUP;
}
INTUSE(_IO_doallocbuf) (fp);
}
/* Flush all line buffered files before reading. */
/* FIXME This can/should be moved to genops ?? */
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
INTUSE(_IO_flush_all_linebuffered) ();
INTUSE(_IO_switch_to_get_mode) (fp);
/* This is very tricky. We have to adjust those
pointers before we call _IO_SYSREAD () since
we may longjump () out while waiting for
input. Those pointers may be screwed up. H.J. */
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
fp->_IO_read_end = fp->_IO_buf_base;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
= fp->_IO_buf_base;
count = _IO_SYSREAD (fp, fp->_IO_buf_base,
fp->_IO_buf_end - fp->_IO_buf_base);
if (count <= 0)
{
if (count == 0)
fp->_flags |= _IO_EOF_SEEN;
else
fp->_flags |= _IO_ERR_SEEN, count = 0;
}
fp->_IO_read_end += count;
if (count == 0)
return EOF;
if (fp->_old_offset != _IO_pos_BAD)
_IO_pos_adjust (fp->_old_offset, count);
return *(unsigned char *) fp->_IO_read_ptr;
}
int
_IO_old_file_overflow (f, ch)
_IO_FILE *f;
int ch;
{
if (f->_flags & _IO_NO_WRITES) /* SET ERROR */
{
f->_flags |= _IO_ERR_SEEN;
__set_errno (EBADF);
return EOF;
}
/* If currently reading or no buffer allocated. */
if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0)
{
/* Allocate a buffer if needed. */
if (f->_IO_write_base == 0)
{
INTUSE(_IO_doallocbuf) (f);
_IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base);
}
/* Otherwise must be currently reading.
If _IO_read_ptr (and hence also _IO_read_end) is at the buffer end,
logically slide the buffer forwards one block (by setting the
read pointers to all point at the beginning of the block). This
makes room for subsequent output.
Otherwise, set the read pointers to _IO_read_end (leaving that
alone, so it can continue to correspond to the external position). */
if (f->_IO_read_ptr == f->_IO_buf_end)
f->_IO_read_end = f->_IO_read_ptr = f->_IO_buf_base;
f->_IO_write_ptr = f->_IO_read_ptr;
f->_IO_write_base = f->_IO_write_ptr;
f->_IO_write_end = f->_IO_buf_end;
f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
f->_IO_write_end = f->_IO_write_ptr;
f->_flags |= _IO_CURRENTLY_PUTTING;
}
if (ch == EOF)
return _IO_old_do_flush (f);
if (f->_IO_write_ptr == f->_IO_buf_end ) /* Buffer is really full */
if (_IO_old_do_flush (f) == EOF)
return EOF;
*f->_IO_write_ptr++ = ch;
if ((f->_flags & _IO_UNBUFFERED)
|| ((f->_flags & _IO_LINE_BUF) && ch == '\n'))
if (_IO_old_do_flush (f) == EOF)
return EOF;
return (unsigned char) ch;
}
int
_IO_old_file_sync (fp)
_IO_FILE *fp;
{
_IO_ssize_t delta;
int retval = 0;
/* char* ptr = cur_ptr(); */
if (fp->_IO_write_ptr > fp->_IO_write_base)
if (_IO_old_do_flush(fp)) return EOF;
delta = fp->_IO_read_ptr - fp->_IO_read_end;
if (delta != 0)
{
#ifdef TODO
if (_IO_in_backup (fp))
delta -= eGptr () - Gbase ();
#endif
_IO_off_t new_pos = _IO_SYSSEEK (fp, delta, 1);
if (new_pos != (_IO_off_t) EOF)
fp->_IO_read_end = fp->_IO_read_ptr;
#ifdef ESPIPE
else if (errno == ESPIPE)
; /* Ignore error from unseekable devices. */
#endif
else
retval = EOF;
}
if (retval != EOF)
fp->_old_offset = _IO_pos_BAD;
/* FIXME: Cleanup - can this be shared? */
/* setg(base(), ptr, ptr); */
return retval;
}
_IO_off64_t
_IO_old_file_seekoff (fp, offset, dir, mode)
_IO_FILE *fp;
_IO_off64_t offset;
int dir;
int mode;
{
_IO_off_t result;
_IO_off64_t delta, new_offset;
long count;
/* POSIX.1 8.2.3.7 says that after a call the fflush() the file
offset of the underlying file must be exact. */
int must_be_exact = (fp->_IO_read_base == fp->_IO_read_end
&& fp->_IO_write_base == fp->_IO_write_ptr);
if (mode == 0)
dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
/* Flush unwritten characters.
(This may do an unneeded write if we seek within the buffer.
But to be able to switch to reading, we would need to set
egptr to ptr. That can't be done in the current design,
which assumes file_ptr() is eGptr. Anyway, since we probably
end up flushing when we close(), it doesn't make much difference.)
FIXME: simulate mem-papped files. */
if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode (fp))
if (INTUSE(_IO_switch_to_get_mode) (fp))
return EOF;
if (fp->_IO_buf_base == NULL)
{
/* It could be that we already have a pushback buffer. */
if (fp->_IO_read_base != NULL)
{
free (fp->_IO_read_base);
fp->_flags &= ~_IO_IN_BACKUP;
}
INTUSE(_IO_doallocbuf) (fp);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
}
switch (dir)
{
case _IO_seek_cur:
/* Adjust for read-ahead (bytes is buffer). */
offset -= fp->_IO_read_end - fp->_IO_read_ptr;
if (fp->_old_offset == _IO_pos_BAD)
goto dumb;
/* Make offset absolute, assuming current pointer is file_ptr(). */
offset += fp->_old_offset;
dir = _IO_seek_set;
break;
case _IO_seek_set:
break;
case _IO_seek_end:
{
struct _G_stat64 st;
if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
{
offset += st.st_size;
dir = _IO_seek_set;
}
else
goto dumb;
}
}
/* At this point, dir==_IO_seek_set. */
/* If we are only interested in the current position we've found it now. */
if (mode == 0)
return offset;
/* If destination is within current buffer, optimize: */
if (fp->_old_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
&& !_IO_in_backup (fp))
{
/* Offset relative to start of main get area. */
_IO_off_t rel_offset = (offset - fp->_old_offset
+ (fp->_IO_read_end - fp->_IO_read_base));
if (rel_offset >= 0)
{
#if 0
if (_IO_in_backup (fp))
_IO_switch_to_main_get_area (fp);
#endif
if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
{
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
fp->_IO_read_end);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
{
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
goto resync;
}
}
#ifdef TODO
/* If we have streammarkers, seek forward by reading ahead. */
if (_IO_have_markers (fp))
{
int to_skip = rel_offset
- (fp->_IO_read_ptr - fp->_IO_read_base);
if (ignore (to_skip) != to_skip)
goto dumb;
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
goto resync;
}
#endif
}
#ifdef TODO
if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())
{
if (!_IO_in_backup (fp))
_IO_switch_to_backup_area (fp);
gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
goto resync;
}
#endif
}
#ifdef TODO
INTUSE(_IO_unsave_markers) (fp);
#endif
if (fp->_flags & _IO_NO_READS)
goto dumb;
/* Try to seek to a block boundary, to improve kernel page management. */
new_offset = offset & ~(fp->_IO_buf_end - fp->_IO_buf_base - 1);
delta = offset - new_offset;
if (delta > fp->_IO_buf_end - fp->_IO_buf_base)
{
new_offset = offset;
delta = 0;
}
result = _IO_SYSSEEK (fp, new_offset, 0);
if (result < 0)
return EOF;
if (delta == 0)
count = 0;
else
{
count = _IO_SYSREAD (fp, fp->_IO_buf_base,
(must_be_exact
? delta : fp->_IO_buf_end - fp->_IO_buf_base));
if (count < delta)
{
/* We weren't allowed to read, but try to seek the remainder. */
offset = count == EOF ? delta : delta-count;
dir = _IO_seek_cur;
goto dumb;
}
}
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,
fp->_IO_buf_base + count);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_old_offset = result + count;
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
return offset;
dumb:
INTUSE(_IO_unsave_markers) (fp);
result = _IO_SYSSEEK (fp, offset, dir);
if (result != EOF)
{
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
fp->_old_offset = result;
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
}
return result;
resync:
/* We need to do it since it is possible that the file offset in
the kernel may be changed behind our back. It may happen when
we fopen a file and then do a fork. One process may access the
the file and the kernel file offset will be changed. */
if (fp->_old_offset >= 0)
_IO_SYSSEEK (fp, fp->_old_offset, 0);
return offset;
}
_IO_ssize_t
_IO_old_file_write (f, data, n)
_IO_FILE *f;
const void *data;
_IO_ssize_t n;
{
_IO_ssize_t to_do = n;
while (to_do > 0)
{
_IO_ssize_t count = write (f->_fileno, data, to_do);
if (count == EOF)
{
f->_flags |= _IO_ERR_SEEN;
break;
}
to_do -= count;
data = (void *) ((char *) data + count);
}
n -= to_do;
if (f->_old_offset >= 0)
f->_old_offset += n;
return n;
}
_IO_size_t
_IO_old_file_xsputn (f, data, n)
_IO_FILE *f;
const void *data;
_IO_size_t n;
{
register const char *s = (char *) data;
_IO_size_t to_do = n;
int must_flush = 0;
_IO_size_t count;
if (n <= 0)
return 0;
/* This is an optimized implementation.
If the amount to be written straddles a block boundary
(or the filebuf is unbuffered), use sys_write directly. */
/* First figure out how much space is available in the buffer. */
count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */
if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING))
{
count = f->_IO_buf_end - f->_IO_write_ptr;
if (count >= n)
{
register const char *p;
for (p = s + n; p > s; )
{
if (*--p == '\n')
{
count = p - s + 1;
must_flush = 1;
break;
}
}
}
}
/* Then fill the buffer. */
if (count > 0)
{
if (count > to_do)
count = to_do;
if (count > 20)
{
#ifdef _LIBC
f->_IO_write_ptr = __mempcpy (f->_IO_write_ptr, s, count);
#else
memcpy (f->_IO_write_ptr, s, count);
f->_IO_write_ptr += count;
#endif
s += count;
}
else
{
register char *p = f->_IO_write_ptr;
register int i = (int) count;
while (--i >= 0)
*p++ = *s++;
f->_IO_write_ptr = p;
}
to_do -= count;
}
if (to_do + must_flush > 0)
{
_IO_size_t block_size, do_write;
/* Next flush the (full) buffer. */
if (__overflow (f, EOF) == EOF)
return n - to_do;
/* Try to maintain alignment: write a whole number of blocks.
dont_write is what gets left over. */
block_size = f->_IO_buf_end - f->_IO_buf_base;
do_write = to_do - (block_size >= 128 ? to_do % block_size : 0);
if (do_write)
{
count = old_do_write (f, s, do_write);
to_do -= count;
if (count < do_write)
return n - to_do;
}
/* Now write out the remainder. Normally, this will fit in the
buffer, but it's somewhat messier for line-buffered files,
so we let _IO_default_xsputn handle the general case. */
if (to_do)
to_do -= INTUSE(_IO_default_xsputn) (f, s+do_write, to_do);
}
return n - to_do;
}
struct _IO_jump_t _IO_old_file_jumps =
{
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_old_file_finish),
JUMP_INIT(overflow, _IO_old_file_overflow),
JUMP_INIT(underflow, _IO_old_file_underflow),
JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, _IO_old_file_xsputn),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
JUMP_INIT(seekoff, _IO_old_file_seekoff),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, _IO_old_file_setbuf),
JUMP_INIT(sync, _IO_old_file_sync),
JUMP_INIT(doallocate, INTUSE(_IO_file_doallocate)),
JUMP_INIT(read, INTUSE(_IO_file_read)),
JUMP_INIT(write, _IO_old_file_write),
JUMP_INIT(seek, INTUSE(_IO_file_seek)),
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);
compat_symbol (libc, _IO_old_file_finish, _IO_file_finish, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_fopen, _IO_file_fopen, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_init, _IO_file_init, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_setbuf, _IO_file_setbuf, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_sync, _IO_file_sync, GLIBC_2_0);
compat_symbol (libc, _IO_old_file_overflow, _IO_file_overflow, GLIBC_2_0);
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

@ -0,0 +1,79 @@
/* Copyright (C) 1993, 1995, 1997-2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
#define _IO_USE_OLD_IO_FILE
#include "libioP.h"
#ifdef __STDC__
#include <stdlib.h>
#endif
int
_IO_old_fclose (fp)
_IO_FILE *fp;
{
int status;
CHECK_FILE(fp, EOF);
/* We desperately try to help programs which are using streams in a
strange way and mix old and new functions. Detect new streams
here. */
if (fp->_vtable_offset == 0)
return _IO_new_fclose (fp);
/* First unlink the stream. */
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);
_IO_cleanup_region_start ((void (*) (void *)) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
status = _IO_old_file_close_it (fp);
else
status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
_IO_FINISH (fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (_IO_have_backup (fp))
INTUSE(_IO_free_backup_area) (fp);
if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
{
fp->_IO_file_flags = 0;
free(fp);
}
return status;
}
strong_alias (_IO_old_fclose, __old_fclose)
compat_symbol (libc, _IO_old_fclose, _IO_fclose, GLIBC_2_0);
compat_symbol (libc, __old_fclose, fclose, GLIBC_2_0);
#endif

View File

@ -0,0 +1,142 @@
/* Copyright (C) 1993,94,97,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <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 "libioP.h"
#include <fcntl.h>
#ifndef _IO_fcntl
# define _IO_fcntl __fcntl
#endif
_IO_FILE *
_IO_old_fdopen (fd, mode)
int fd;
const char *mode;
{
int read_write;
int posix_mode = 0;
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f;
int fd_flags;
switch (*mode++)
{
case 'r':
read_write = _IO_NO_WRITES;
break;
case 'w':
read_write = _IO_NO_READS;
break;
case 'a':
posix_mode = O_APPEND;
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
MAYBE_SET_EINVAL;
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
read_write &= _IO_IS_APPENDING;
#ifdef F_GETFL
fd_flags = _IO_fcntl (fd, F_GETFL);
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
if (fd_flags == -1
|| ((fd_flags & O_ACCMODE) == O_RDONLY && !(read_write & _IO_NO_WRITES))
|| ((fd_flags & O_ACCMODE) == O_WRONLY && !(read_write & _IO_NO_READS)))
return NULL;
/* The May 93 draft of P1003.4/D14.1 (redesignated as 1003.1b)
[System Application Program Interface (API) Amendment 1:
Realtime Extensions], Rationale B.8.3.3
Open a Stream on a File Descriptor says:
Although not explicitly required by POSIX.1, a good
implementation of append ("a") mode would cause the
O_APPEND flag to be set.
(Historical implementations [such as Solaris2] do a one-time
seek in fdopen.)
However, we do not turn O_APPEND off if the mode is "w" (even
though that would seem consistent) because that would be more
likely to break historical programs.
*/
if ((posix_mode & O_APPEND) && !(fd_flags & O_APPEND))
{
#ifdef F_SETFL
if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
#endif
return NULL;
}
#endif
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fp.file._lock = &new_f->lock;
#endif
INTUSE(_IO_init) (&new_f->fp.file, 0);
_IO_JUMPS (&new_f->fp) = &_IO_old_file_jumps;
_IO_old_file_init (&new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
#endif
if (_IO_old_file_attach (&new_f->fp.file, fd) == NULL)
{
INTUSE(_IO_un_link) (&new_f->fp);
free (new_f);
return NULL;
}
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
new_f->fp.file._IO_file_flags =
_IO_mask_flags (&new_f->fp.file, read_write,
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
return (_IO_FILE *) &new_f->fp;
}
strong_alias (_IO_old_fdopen, __old_fdopen)
compat_symbol (libc, _IO_old_fdopen, _IO_fdopen, GLIBC_2_0);
compat_symbol (libc, __old_fdopen, fdopen, GLIBC_2_0);
#endif

View File

@ -0,0 +1,68 @@
/* Copyright (C) 1993,95,96,97,98,99,2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <errno.h>
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
int
_IO_old_fgetpos (fp, posp)
_IO_FILE *fp;
_IO_fpos_t *posp;
{
_IO_off_t pos;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
if (_IO_in_backup (fp))
pos -= fp->_IO_save_end - fp->_IO_save_base;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (pos == _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
return EOF;
}
posp->__pos = pos;
return 0;
}
#ifdef weak_alias
compat_symbol (libc, _IO_old_fgetpos, _IO_fgetpos, GLIBC_2_0);
strong_alias (_IO_old_fgetpos, __old_fgetpos)
compat_symbol (libc, __old_fgetpos, fgetpos, GLIBC_2_0);
#endif
#endif

View File

@ -0,0 +1,73 @@
/* Copyright (C) 1993,95,96,97,98,99,2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include <errno.h>
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
int
_IO_old_fgetpos64 (fp, posp)
_IO_FILE *fp;
_IO_fpos64_t *posp;
{
#ifdef _G_LSEEK64
_IO_off64_t pos;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
if (_IO_in_backup (fp))
pos -= fp->_IO_save_end - fp->_IO_save_base;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
if (pos == _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
return EOF;
}
posp->__pos = pos;
return 0;
#else
__set_errno (ENOSYS);
return EOF;
#endif
}
#ifdef weak_alias
compat_symbol (libc, _IO_old_fgetpos64, _IO_fgetpos64, GLIBC_2_1);
strong_alias (_IO_old_fgetpos64, __old_fgetpos64)
compat_symbol (libc, __old_fgetpos64, fgetpos64, GLIBC_2_1);
#endif
#endif

View File

@ -0,0 +1,72 @@
/* Copyright (C) 1993, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
#define _IO_USE_OLD_IO_FILE
#include "libioP.h"
#ifdef __STDC__
#include <stdlib.h>
#endif
_IO_FILE *
_IO_old_fopen (filename, mode)
const char *filename;
const char *mode;
{
struct locked_FILE
{
struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fp.file._lock = &new_f->lock;
#endif
INTUSE(_IO_init) (&new_f->fp.file, 0);
_IO_JUMPS (&new_f->fp) = &_IO_old_file_jumps;
_IO_old_file_init (&new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
#endif
if (_IO_old_file_fopen ((_IO_FILE *) &new_f->fp, filename, mode) != NULL)
return (_IO_FILE *) &new_f->fp;
INTUSE(_IO_un_link) (&new_f->fp);
free (new_f);
return NULL;
}
strong_alias (_IO_old_fopen, __old_fopen)
compat_symbol (libc, _IO_old_fopen, _IO_fopen, GLIBC_2_0);
compat_symbol (libc, __old_fopen, fopen, GLIBC_2_0);
#endif

View File

@ -0,0 +1,66 @@
/* Copyright (C) 1993,95,97,98,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#include <errno.h>
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
int
_IO_old_fsetpos (fp, posp)
_IO_FILE *fp;
const _IO_fpos_t *posp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_seekpos_unlocked (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
result = EOF;
}
else
result = 0;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
#ifdef weak_alias
compat_symbol (libc, _IO_old_fsetpos, _IO_fsetpos, GLIBC_2_0);
strong_alias (_IO_old_fsetpos, __old_fsetpos)
compat_symbol (libc, __old_fsetpos, fsetpos, GLIBC_2_0);
#endif
#endif

View File

@ -0,0 +1,72 @@
/* Copyright (C) 1993,95,97,98,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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>
#include <errno.h>
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
int
_IO_old_fsetpos64 (fp, posp)
_IO_FILE *fp;
const _IO_fpos64_t *posp;
{
#ifdef _G_LSEEK64
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
if (_IO_seekpos_unlocked (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT)
== _IO_pos_BAD)
{
/* ANSI explicitly requires setting errno to a positive value on
failure. */
#ifdef EIO
if (errno == 0)
__set_errno (EIO);
#endif
result = EOF;
}
else
result = 0;
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
#else
__set_errno (ENOSYS);
return EOF;
#endif
}
#ifdef weak_alias
compat_symbol (libc, _IO_old_fsetpos64, _IO_fsetpos64, GLIBC_2_1);
strong_alias (_IO_old_fsetpos64, __old_fsetpos64)
compat_symbol (libc, __old_fsetpos64, fsetpos64, GLIBC_2_1);
#endif
#endif

View File

@ -0,0 +1,316 @@
/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Per Bothner <bothner@cygnus.com>.
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. */
#define _IO_USE_OLD_IO_FILE
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h"
#if _IO_HAVE_SYS_WAIT
#include <signal.h>
#include <unistd.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef _LIBC
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>
#ifndef _IO_fork
#ifdef _LIBC
#define _IO_fork __vfork
#else
#define _IO_fork vfork /* defined in libiberty, if needed */
#endif
extern _IO_pid_t _IO_fork __P ((void));
#endif
#endif /* _IO_HAVE_SYS_WAIT */
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
#ifndef _IO_pipe
#ifdef _LIBC
#define _IO_pipe __pipe
#else
#define _IO_pipe pipe
#endif
extern int _IO_pipe __P ((int des[2]));
#endif
#ifndef _IO_dup2
#ifdef _LIBC
#define _IO_dup2 __dup2
#else
#define _IO_dup2 dup2
#endif
extern int _IO_dup2 __P ((int fd, int fd2));
#endif
#ifndef _IO_waitpid
#ifdef _LIBC
#define _IO_waitpid __waitpid
#else
#define _IO_waitpid waitpid
#endif
#endif
#ifndef _IO_execl
#define _IO_execl execl
#endif
#ifndef _IO__exit
#define _IO__exit _exit
#endif
#ifndef _IO_close
#ifdef _LIBC
#define _IO_close __close
#else
#define _IO_close close
#endif
#endif
struct _IO_proc_file
{
struct _IO_FILE_plus file;
/* Following fields must match those in class procbuf (procbuf.h) */
_IO_pid_t pid;
struct _IO_proc_file *next;
};
typedef struct _IO_proc_file _IO_proc_file;
static struct _IO_proc_file *old_proc_file_chain;
#ifdef _IO_MTSAFE_IO
static _IO_lock_t proc_file_chain_lock = _IO_lock_initializer;
static void
unlock (void *not_used)
{
_IO_lock_unlock (proc_file_chain_lock);
}
#endif
_IO_FILE *
_IO_old_proc_open (fp, command, mode)
_IO_FILE *fp;
const char *command;
const char *mode;
{
#if _IO_HAVE_SYS_WAIT
volatile int read_or_write;
volatile int parent_end, child_end;
int pipe_fds[2];
_IO_pid_t child_pid;
if (_IO_file_is_open (fp))
return NULL;
if (_IO_pipe (pipe_fds) < 0)
return NULL;
if (mode[0] == 'r' && mode[1] == '\0')
{
parent_end = pipe_fds[0];
child_end = pipe_fds[1];
read_or_write = _IO_NO_WRITES;
}
else if (mode[0] == 'w' && mode[1] == '\0')
{
parent_end = pipe_fds[1];
child_end = pipe_fds[0];
read_or_write = _IO_NO_READS;
}
else
{
_IO_close (pipe_fds[0]);
_IO_close (pipe_fds[1]);
__set_errno (EINVAL);
return NULL;
}
((_IO_proc_file *) fp)->pid = child_pid = _IO_fork ();
if (child_pid == 0)
{
int child_std_end = mode[0] == 'r' ? 1 : 0;
struct _IO_proc_file *p;
_IO_close (parent_end);
if (child_end != child_std_end)
{
_IO_dup2 (child_end, child_std_end);
_IO_close (child_end);
}
/* POSIX.2: "popen() shall ensure that any streams from previous
popen() calls that remain open in the parent process are closed
in the new child process." */
for (p = old_proc_file_chain; p; p = p->next)
_IO_close (_IO_fileno ((_IO_FILE *) p));
_IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
_IO__exit (127);
}
_IO_close (child_end);
if (child_pid < 0)
{
_IO_close (parent_end);
return NULL;
}
_IO_fileno (fp) = parent_end;
/* Link into old_proc_file_chain. */
#ifdef _IO_MTSAFE_IO
_IO_cleanup_region_start_noarg (unlock);
_IO_lock_lock (proc_file_chain_lock);
#endif
((_IO_proc_file *) fp)->next = old_proc_file_chain;
old_proc_file_chain = (_IO_proc_file *) fp;
#ifdef _IO_MTSAFE_IO
_IO_lock_unlock (proc_file_chain_lock);
_IO_cleanup_region_end (0);
#endif
_IO_mask_flags (fp, read_or_write, _IO_NO_READS|_IO_NO_WRITES);
return fp;
#else /* !_IO_HAVE_SYS_WAIT */
return NULL;
#endif
}
_IO_FILE *
_IO_old_popen (command, mode)
const char *command;
const char *mode;
{
struct locked_FILE
{
struct _IO_proc_file fpx;
#ifdef _IO_MTSAFE_IO
_IO_lock_t lock;
#endif
} *new_f;
_IO_FILE *fp;
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
if (new_f == NULL)
return NULL;
#ifdef _IO_MTSAFE_IO
new_f->fpx.file.file._lock = &new_f->lock;
#endif
fp = &new_f->fpx.file.file;
INTUSE(_IO_init) (fp, 0);
_IO_JUMPS (&new_f->fpx.file) = &_IO_old_proc_jumps;
_IO_old_file_init (&new_f->fpx.file);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fpx.file.vtable = NULL;
#endif
if (_IO_old_proc_open (fp, command, mode) != NULL)
return fp;
INTUSE(_IO_un_link) (&new_f->fpx.file);
free (new_f);
return NULL;
}
int
_IO_old_proc_close (fp)
_IO_FILE *fp;
{
/* This is not name-space clean. FIXME! */
#if _IO_HAVE_SYS_WAIT
int wstatus;
_IO_proc_file **ptr = &old_proc_file_chain;
_IO_pid_t wait_pid;
int status = -1;
/* Unlink from old_proc_file_chain. */
#ifdef _IO_MTSAFE_IO
_IO_cleanup_region_start_noarg (unlock);
_IO_lock_lock (proc_file_chain_lock);
#endif
for ( ; *ptr != NULL; ptr = &(*ptr)->next)
{
if (*ptr == (_IO_proc_file *) fp)
{
*ptr = (*ptr)->next;
status = 0;
break;
}
}
#ifdef _IO_MTSAFE_IO
_IO_lock_unlock (proc_file_chain_lock);
_IO_cleanup_region_end (0);
#endif
if (status < 0 || _IO_close (_IO_fileno(fp)) < 0)
return -1;
/* POSIX.2 Rationale: "Some historical implementations either block
or ignore the signals SIGINT, SIGQUIT, and SIGHUP while waiting
for the child process to terminate. Since this behavior is not
described in POSIX.2, such implementations are not conforming." */
do
{
wait_pid = _IO_waitpid (((_IO_proc_file *) fp)->pid, &wstatus, 0);
}
while (wait_pid == -1 && errno == EINTR);
if (wait_pid == -1)
return -1;
return wstatus;
#else /* !_IO_HAVE_SYS_WAIT */
return -1;
#endif
}
struct _IO_jump_t _IO_old_proc_jumps = {
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_old_file_finish),
JUMP_INIT(overflow, _IO_old_file_overflow),
JUMP_INIT(underflow, _IO_old_file_underflow),
JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
JUMP_INIT(pbackfail, INTUSE(_IO_default_pbackfail)),
JUMP_INIT(xsputn, _IO_old_file_xsputn),
JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
JUMP_INIT(seekoff, _IO_old_file_seekoff),
JUMP_INIT(seekpos, _IO_default_seekpos),
JUMP_INIT(setbuf, _IO_old_file_setbuf),
JUMP_INIT(sync, _IO_old_file_sync),
JUMP_INIT(doallocate, INTUSE(_IO_file_doallocate)),
JUMP_INIT(read, INTUSE(_IO_file_read)),
JUMP_INIT(write, _IO_old_file_write),
JUMP_INIT(seek, INTUSE(_IO_file_seek)),
JUMP_INIT(close, _IO_old_proc_close),
JUMP_INIT(stat, INTUSE(_IO_file_stat)),
JUMP_INIT(showmanyc, _IO_default_showmanyc),
JUMP_INIT(imbue, _IO_default_imbue)
};
strong_alias (_IO_old_popen, __old_popen)
compat_symbol (libc, _IO_old_popen, _IO_popen, GLIBC_2_0);
compat_symbol (libc, __old_popen, popen, GLIBC_2_0);
compat_symbol (libc, _IO_old_proc_open, _IO_proc_open, GLIBC_2_0);
compat_symbol (libc, _IO_old_proc_close, _IO_proc_close, GLIBC_2_0);
#endif

View File

@ -0,0 +1,50 @@
/* Copyright (C) 1998,2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
#define _IO_USE_OLD_IO_FILE
#include "libioP.h"
#include "stdio.h"
#include <errno.h>
int
__old_pclose (fp)
FILE *fp;
{
#if 0
/* Does not actually test that stream was created by popen(). Instead,
it depends on the filebuf::sys_close() virtual to Do The Right Thing. */
if (fp is not a proc_file)
return -1;
#endif
return _IO_old_fclose (fp);
}
compat_symbol (libc, __old_pclose, pclose, GLIBC_2_0);
#endif

View File

@ -0,0 +1,96 @@
/* Copyright (C) 1993,94,96,97,99,2000,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 <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.
(The difference is that here the vtable field is set to 0,
so the objects defined are not valid C++ objects. On the other
hand, we don't need a C++ compiler to build this file.) */
#define _IO_USE_OLD_IO_FILE
#include "libioP.h"
#ifdef _IO_MTSAFE_IO
#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), &_IO_old_file_jumps};
#else
#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
struct _IO_FILE_plus NAME \
= {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
#endif
DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_, _IO_NO_READS);
DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_, _IO_NO_READS+_IO_UNBUFFERED);
#if defined __GNUC__ && __GNUC__ >= 2
#include <stdio.h>
extern const int _IO_stdin_used;
weak_extern (_IO_stdin_used);
#undef stdin
#undef stdout
#undef stderr
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
static void _IO_check_libio __P ((void)) __attribute__ ((constructor));
/* This function determines which shared C library the application
was linked against. We then set up the stdin/stdout/stderr and
_IO_list_all accordingly. */
static void
_IO_check_libio ()
{
if (&_IO_stdin_used == NULL)
{
/* We are using the old one. */
_IO_stdin = stdin = (_IO_FILE *) &_IO_stdin_;
_IO_stdout = stdout = (_IO_FILE *) &_IO_stdout_;
_IO_stderr = stderr = (_IO_FILE *) &_IO_stderr_;
INTUSE(_IO_list_all) = &_IO_stderr_;
_IO_stdin->_vtable_offset = _IO_stdout->_vtable_offset =
_IO_stderr->_vtable_offset = stdin->_vtable_offset =
stdout->_vtable_offset = stderr->_vtable_offset =
((int) sizeof (struct _IO_FILE)
- (int) sizeof (struct _IO_FILE_complete));
}
}
#endif
#endif

View File

@ -0,0 +1,55 @@
/* Copyright (C) 1991, 1993, 1996-1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
#define _IO_USE_OLD_IO_FILE
#include <stdio.h>
#include <unistd.h>
#include <iolibio.h>
/* This returns a new stream opened on a temporary file (generated
by tmpnam). The file is opened with mode "w+b" (binary read/write).
If we couldn't generate a unique filename or the file couldn't
be opened, NULL is returned. */
FILE *
__old_tmpfile (void)
{
char buf[FILENAME_MAX];
int fd;
FILE *f;
if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
return NULL;
fd = __gen_tempname (buf, __GT_FILE);
if (fd < 0)
return NULL;
/* Note that this relies on the Unix semantics that
a file is not really removed until it is closed. */
(void) remove (buf);
if ((f = _IO_old_fdopen (fd, "w+b")) == NULL)
__close (fd);
return f;
}
compat_symbol (libc, __old_tmpfile, tmpfile, GLIBC_2_0);
#endif

View File

@ -0,0 +1,46 @@
/* Copyright (C) 1993, 1995, 1996-1998, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#include <errno.h>
#include <shlib-compat.h>
int
__new_pclose (fp)
FILE *fp;
{
#if 0
/* Does not actually test that stream was created by popen(). Instead,
it depends on the filebuf::sys_close() virtual to Do The Right Thing. */
if (fp is not a proc_file)
return -1;
#endif
return _IO_new_fclose (fp);
}
versioned_symbol (libc, __new_pclose, pclose, GLIBC_2_1);

View File

@ -0,0 +1,45 @@
/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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"
#include "stdio.h"
#undef _IO_peekc
int
_IO_peekc_locked (fp)
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_peekc_unlocked (fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}

View File

@ -0,0 +1,49 @@
/* Copyright (C) 1991,1995,1996,1997,1998,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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. */
#include "libioP.h"
#include "stdio.h"
#undef _IO_putc
int
_IO_putc (c, fp)
int c;
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
result = _IO_putc_unlocked (c, fp);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
}
INTDEF(_IO_putc)
#undef putc
#ifdef weak_alias
weak_alias (_IO_putc, putc)
#ifndef _IO_MTSAFE_IO
#undef putc_unlocked
weak_alias (_IO_putc, putc_unlocked)
#endif
#endif

Some files were not shown because too many files have changed in this diff Show More