This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Some Patches for glibc


Hi,

while trying to compile GNU libio outside of glibc (and without
wide-character support), I noticed that the seperation of the
wide-character functionality is missing in some places.

Basically libio.h defines the needed structures only in the case
`defined _LIBC || defined _GLIBCPP_USE_WCHAR_T'.  In some places, this
test is also used to protect wide-character code, but in some places
it is missing - that's what my patch should fix.

Furthermore some symbols in fileops.c have different names depending
on wether _LIBC is defined or not; iopopen.c needed some redefinitions
to use the correct names.

Hope the patch is alright (was done for g10 Code).

--- libio/__fbufsize.c	2001-07-06 06:54:53.000000000 +0200
+++ libio2/__fbufsize.c	2002-10-17 00:31:50.000000000 +0200
@@ -30,8 +30,10 @@
 size_t
 __fbufsize (FILE *fp)
 {
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   if (fp->_mode > 0)
     return fp->_wide_data->_IO_buf_end - fp->_wide_data->_IO_buf_base;
   else
+#endif
     return fp->_IO_buf_end - fp->_IO_buf_base;
 }
--- libio/__fpending.c	2001-07-06 06:54:53.000000000 +0200
+++ libio2/__fpending.c	2002-10-17 00:32:19.000000000 +0200
@@ -30,8 +30,10 @@
 size_t
 __fpending (FILE *fp)
 {
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   if (fp->_mode > 0)
     return fp->_wide_data->_IO_write_ptr - fp->_wide_data->_IO_write_base;
   else
+#endif
     return fp->_IO_write_ptr - fp->_IO_write_base;
 }
--- libio/__fpurge.c	2001-07-06 06:54:53.000000000 +0200
+++ libio2/__fpurge.c	2002-10-17 00:33:31.000000000 +0200
@@ -31,6 +31,7 @@
 void
 __fpurge (FILE *fp)
 {
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   if (fp->_mode > 0)
     {
       /* Wide-char stream.  */
@@ -41,6 +42,7 @@ __fpurge (FILE *fp)
       fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base;
     }
   else
+#endif
     {
       /* Byte stream.  */
       if (_IO_in_backup (fp))
--- libio/genops.c	2001-11-29 00:36:24.000000000 +0100
+++ libio2/genops.c	2002-10-17 01:32:33.000000000 +0200
@@ -590,7 +590,11 @@ _IO_no_init (fp, flags, orientation, wd,
      _IO_FILE *fp;
      int flags;
      int orientation;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
      struct _IO_wide_data *wd;
+#else
+     void *wd;
+#endif
      struct _IO_jump_t *jmp;
 {
   fp->_flags = _IO_MAGIC|flags;
--- libio/iofdopen.c	2001-07-06 06:54:55.000000000 +0200
+++ libio2/iofdopen.c	2002-10-17 01:24:34.000000000 +0200
@@ -56,7 +56,9 @@ _IO_new_fdopen (fd, mode)
 #ifdef _IO_MTSAFE_IO
     _IO_lock_t lock;
 #endif
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
     struct _IO_wide_data wd;
+#endif
   } *new_f;
   int fd_flags;
 
@@ -124,7 +126,13 @@ _IO_new_fdopen (fd, mode)
 #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, &_IO_wfile_jumps);
+#else
+  _IO_no_init (&new_f->fp.file, 0, 0, NULL, NULL);
+#endif
+
   _IO_JUMPS (&new_f->fp) = &_IO_file_jumps;
   _IO_file_init (&new_f->fp);
 #if  !_IO_UNIFIED_JUMPTABLES
--- libio/iofgetpos.c	2001-08-09 10:43:39.000000000 +0200
+++ libio2/iofgetpos.c	2002-10-17 00:37:06.000000000 +0200
@@ -59,10 +59,12 @@ _IO_new_fgetpos (fp, posp)
   else
     {
       posp->__pos = pos;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
       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;
+#endif
     }
 
   _IO_funlockfile (fp);
--- libio/iofgetpos64.c	2001-08-09 10:43:39.000000000 +0200
+++ libio2/iofgetpos64.c	2002-10-17 00:37:25.000000000 +0200
@@ -59,10 +59,12 @@ _IO_new_fgetpos64 (fp, posp)
       return EOF;
     }
   posp->__pos = pos;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   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;
+#endif
   return 0;
 #else
   __set_errno (ENOSYS);
--- libio/iofopen.c	2001-07-06 06:54:55.000000000 +0200
+++ libio2/iofopen.c	2002-10-17 01:25:13.000000000 +0200
@@ -46,7 +46,9 @@ _IO_new_fopen (filename, mode)
 #ifdef _IO_MTSAFE_IO
     _IO_lock_t lock;
 #endif
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
     struct _IO_wide_data wd;
+#endif
   } *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
 
   if (new_f == NULL)
--- libio/iofsetpos.c	2001-07-06 06:54:55.000000000 +0200
+++ libio2/iofsetpos.c	2002-10-17 00:38:26.000000000 +0200
@@ -51,10 +51,12 @@ _IO_new_fsetpos (fp, posp)
   else
     {
       result = 0;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
       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;
+#endif
     }
   _IO_funlockfile (fp);
   _IO_cleanup_region_end (0);
--- libio/iofsetpos64.c	2001-07-06 06:54:55.000000000 +0200
+++ libio2/iofsetpos64.c	2002-10-17 00:38:40.000000000 +0200
@@ -52,10 +52,12 @@ _IO_new_fsetpos64 (fp, posp)
   else
     {
       result = 0;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
       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;
+#endif
     }
   _IO_funlockfile (fp);
   _IO_cleanup_region_end (0);
--- libio/iopopen.c	2001-08-07 19:26:18.000000000 +0200
+++ libio2/iopopen.c	2002-10-17 01:26:41.000000000 +0200
@@ -95,6 +95,11 @@ extern int _IO_dup2 __P ((int fd, int fd
 #endif
 #endif
 
+#ifndef _LIBC
+/* According to fileops.c we must use _IO_file_init.  */
+# define _IO_new_file_init _IO_file_init
+#endif
+
 struct _IO_proc_file
 {
   struct _IO_FILE_plus file;
@@ -104,7 +109,9 @@ struct _IO_proc_file
 };
 typedef struct _IO_proc_file _IO_proc_file;
 
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
 static struct _IO_jump_t _IO_wproc_jumps;
+#endif
 
 static struct _IO_proc_file *proc_file_chain;
 
@@ -211,7 +218,9 @@ _IO_new_popen (command, mode)
 #ifdef _IO_MTSAFE_IO
     _IO_lock_t lock;
 #endif
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
     struct _IO_wide_data wd;
+#endif
   } *new_f;
   _IO_FILE *fp;
 
@@ -222,7 +231,11 @@ _IO_new_popen (command, mode)
   new_f->fpx.file.file._lock = &new_f->lock;
 #endif
   fp = &new_f->fpx.file.file;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   _IO_no_init (fp, 0, 0, &new_f->wd, &_IO_wproc_jumps);
+#else
+  _IO_no_init (fp, 0, 0, NULL, NULL);
+#endif
   _IO_JUMPS (&new_f->fpx.file) = &_IO_proc_jumps;
   _IO_new_file_init (&new_f->fpx.file);
 #if  !_IO_UNIFIED_JUMPTABLES
@@ -284,6 +297,19 @@ _IO_new_proc_close (fp)
 #endif
 }
 
+#ifndef _LIBC
+/* According to fileops.c, we have to do the following
+   re-definitions.  */
+# define _IO_new_file_finish _IO_file_finish
+# define _IO_new_file_overflow _IO_file_overflow
+# define _IO_new_file_underflow _IO_file_underflow
+# define _IO_new_file_xsputn _IO_file_xsputn
+# define _IO_new_file_seekoff _IO_file_seekoff
+# define _IO_new_file_setbuf _IO_file_setbuf
+# define _IO_new_file_sync _IO_file_sync
+# define _IO_new_file_write _IO_file_write
+#endif
+
 struct _IO_jump_t _IO_proc_jumps = {
   JUMP_INIT_DUMMY,
   JUMP_INIT(finish, _IO_new_file_finish),
@@ -307,6 +333,7 @@ struct _IO_jump_t _IO_proc_jumps = {
   JUMP_INIT(imbue, _IO_default_imbue)
 };
 
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
 static struct _IO_jump_t _IO_wproc_jumps = {
   JUMP_INIT_DUMMY,
   JUMP_INIT(finish, _IO_new_file_finish),
@@ -329,6 +356,7 @@ static struct _IO_jump_t _IO_wproc_jumps
   JUMP_INIT(showmanyc, _IO_default_showmanyc),
   JUMP_INIT(imbue, _IO_default_imbue)
 };
+#endif
 
 strong_alias (_IO_new_popen, __new_popen)
 versioned_symbol (libc, _IO_new_popen, _IO_popen, GLIBC_2_1);
--- libio/iosetbuffer.c	2001-07-06 06:54:57.000000000 +0200
+++ libio2/iosetbuffer.c	2002-10-17 00:45:48.000000000 +0200
@@ -40,9 +40,11 @@ _IO_setbuffer (fp, buf, size)
   if (!buf)
     size = 0;
   (void) _IO_SETBUF (fp, buf, size);
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   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);
+#endif
   _IO_funlockfile (fp);
   _IO_cleanup_region_end (0);
 }
--- libio/iosetvbuf.c	2001-07-06 06:54:57.000000000 +0200
+++ libio2/iosetvbuf.c	2002-10-17 00:46:23.000000000 +0200
@@ -94,10 +94,12 @@ _IO_setvbuf (fp, buf, mode, size)
       goto unlock_return;
     }
   result = _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   if (result == 0 && fp->_vtable_offset == 0 && fp->_mode == 0
       && _IO_CHECK_WIDE (fp))
     /* We also have to set the buffer using the wide char function.  */
     result = _IO_WSETBUF (fp, buf, size) == NULL ? EOF : 0;
+#endif
 
 unlock_return:
   _IO_funlockfile (fp);
--- libio/iovdprintf.c	2001-08-11 07:09:43.000000000 +0200
+++ libio2/iovdprintf.c	2002-10-17 01:27:28.000000000 +0200
@@ -36,13 +36,21 @@ _IO_vdprintf (d, format, arg)
      _IO_va_list arg;
 {
   struct _IO_FILE_plus tmpfil;
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   struct _IO_wide_data wd;
+#endif
   int done;
 
 #ifdef _IO_MTSAFE_IO
   tmpfil.file._lock = NULL;
 #endif
+
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
   _IO_no_init (&tmpfil.file, _IO_USER_LOCK, 0, &wd, &_IO_wfile_jumps);
+#else
+  _IO_no_init (&tmpfil.file, _IO_USER_LOCK, 0, NULL, NULL);
+#endif
+
   _IO_JUMPS (&tmpfil) = &_IO_file_jumps;
   _IO_file_init (&tmpfil);
 #if  !_IO_UNIFIED_JUMPTABLES
--- libio/libioP.h	2001-11-29 00:36:43.000000000 +0100
+++ libio2/libioP.h	2002-10-17 01:31:00.000000000 +0200
@@ -510,8 +510,13 @@ extern int _IO_new_file_close_it __P ((_
 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));
+#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
 extern void _IO_no_init __P ((_IO_FILE *, int, int, struct _IO_wide_data *,
 			      struct _IO_jump_t *));
+#else
+extern void _IO_no_init __P ((_IO_FILE *, int, int, void *,
+			      struct _IO_jump_t *));
+#endif
 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 int _IO_new_file_sync __P ((_IO_FILE *));


		moritz
-- 
moritz@duesseldorf.ccc.de - http://duesseldorf.ccc.de/~moritz/
GPG fingerprint = 3A14 3923 15BE FD57 FC06  B501 0841 2D7B 6F98 4199


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]