aboutsummaryrefslogtreecommitdiff
path: root/libio/fileops.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-01-26 06:55:29 +0000
committerUlrich Drepper <drepper@redhat.com>2000-01-26 06:55:29 +0000
commit4e2e99997a2890df8ab5d7b86646a2b067eb8723 (patch)
tree30c16b2a54b2c166e03f136f4bd99a13db915032 /libio/fileops.c
parentc36897fb5bef95d586557f960840ee0c614adabf (diff)
downloadglibc-4e2e99997a2890df8ab5d7b86646a2b067eb8723.tar
glibc-4e2e99997a2890df8ab5d7b86646a2b067eb8723.tar.gz
glibc-4e2e99997a2890df8ab5d7b86646a2b067eb8723.tar.bz2
glibc-4e2e99997a2890df8ab5d7b86646a2b067eb8723.zip
Update.
* libio/fileops.c (_IO_new_file_open): Recognize ,ccs= in mode string and load appropriate conversions. * libio/iofwide.c (__libio_codecvt): Renamed from libio_codecvt and made global. * libio/libioP.h: Declare __libio_codecvt. * manual/stdio.texi: Document ,ccs= option for fopen. * wcsmbs/wcsmbsload.c (__wcsmbs_named_conv): New function. * wcsmbs/wcsmbsload.h (__wcsmbs_named_conv): Declare. * libio/iofclose.c: Free conversion data if stream was wide-oriented. * sysdeps/unix/sysv/linux/i386/Dist: Add sys/io.h.
Diffstat (limited to 'libio/fileops.c')
-rw-r--r--libio/fileops.c60
1 files changed, 57 insertions, 3 deletions
diff --git a/libio/fileops.c b/libio/fileops.c
index 52039a4a13..52880c52a9 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1995, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995, 1997-1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU IO Library.
Written by Per Bothner <bothner@cygnus.com>.
@@ -37,6 +37,9 @@
#ifdef __STDC__
#include <stdlib.h>
#endif
+#if _LIBC
+# include "../wcsmbs/wcsmbsload.h"
+#endif
#ifndef errno
extern int errno;
#endif
@@ -214,6 +217,11 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
int read_write;
int oprot = 0666;
int i;
+ _IO_FILE *result;
+#if _LIBC
+ const char *cs;
+#endif
+
if (_IO_file_is_open (fp))
return 0;
switch (*mode)
@@ -257,8 +265,54 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
break;
}
- return _IO_file_open (fp, filename, omode|oflags, oprot, read_write,
- is32not64);
+ result = _IO_file_open (fp, filename, omode|oflags, oprot, read_write,
+ is32not64);
+
+
+#if _LIBC
+ /* Test whether the mode string specifies the conversion. */
+ cs = strstr (mode, ",ccs=");
+ if (cs != NULL)
+ {
+ /* Yep. Load the appropriate conversions and set the orientation
+ to wide. */
+ struct gconv_fcts fcts;
+ struct _IO_codecvt *cc = &fp->_wide_data->_codecvt;
+
+ if (__wcsmbs_named_conv (&fcts, cs + 5) != 0)
+ {
+ /* Something went wrong, we cannot load the conversion modules.
+ This means we cannot proceed since the user explicitly asked
+ for these. */
+ _IO_new_fclose (result);
+ return NULL;
+ }
+
+ /* The functions are always the same. */
+ *cc = __libio_codecvt;
+
+ cc->__cd_in.__cd.__nsteps = 1; /* Only one step allowed. */
+ 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].__is_last = 1;
+ cc->__cd_in.__cd.__data[0].__statep = &result->_wide_data->_IO_state;
+
+ cc->__cd_out.__cd.__nsteps = 1; /* Only one step allowed. */
+ 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].__is_last = 1;
+ cc->__cd_out.__cd.__data[0].__statep = &result->_wide_data->_IO_state;
+
+ /* Set the mode now. */
+ result->_mode = 1;
+ }
+#endif /* GNU libc */
+
+ return result;
}
_IO_FILE *