diff options
Diffstat (limited to 'libio')
-rw-r--r-- | libio/fileops.c | 60 | ||||
-rw-r--r-- | libio/iofclose.c | 24 | ||||
-rw-r--r-- | libio/iofwide.c | 6 | ||||
-rw-r--r-- | libio/libioP.h | 3 |
4 files changed, 85 insertions, 8 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 * diff --git a/libio/iofclose.c b/libio/iofclose.c index 04503e7817..a10ed9266f 100644 --- a/libio/iofclose.c +++ b/libio/iofclose.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. This library is free software; you can redistribute it and/or @@ -27,6 +27,9 @@ #ifdef __STDC__ #include <stdlib.h> #endif +#if _LIBC +# include "../iconv/gconv_int.h" +#endif int _IO_new_fclose (fp) @@ -52,6 +55,25 @@ _IO_new_fclose (fp) status = fp->_flags & _IO_ERR_SEEN ? -1 : 0; _IO_FINISH (fp); _IO_funlockfile (fp); + 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->_wide_data->_codecvt; + + if (cc->__cd_in.__cd.__steps->__shlib_handle != NULL) + { + --cc->__cd_in.__cd.__steps->__counter; + __gconv_close_transform (cc->__cd_in.__cd.__steps, 1); + } + if (cc->__cd_out.__cd.__steps->__shlib_handle != NULL) + { + --cc->__cd_out.__cd.__steps->__counter; + __gconv_close_transform (cc->__cd_out.__cd.__steps, 1); + } +#endif + } _IO_cleanup_region_end (0); if (_IO_have_backup (fp)) _IO_free_backup_area (fp); diff --git a/libio/iofwide.c b/libio/iofwide.c index 853920a001..04c8bba638 100644 --- a/libio/iofwide.c +++ b/libio/iofwide.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999 Free Software Foundation, Inc. +/* Copyright (C) 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -62,7 +62,7 @@ static int do_always_noconv (struct _IO_codecvt *codecvt); /* The functions used in `codecvt' for libio are always the same. */ -static struct _IO_codecvt libio_codecvt = +struct _IO_codecvt __libio_codecvt = { .__codecvt_destr = NULL, /* Destructor, never used. */ .__codecvt_do_out = do_out, @@ -114,7 +114,7 @@ _IO_fwide (fp, mode) __wcsmbs_clone_conv (&fcts); /* The functions are always the same. */ - *cc = libio_codecvt; + *cc = __libio_codecvt; cc->__cd_in.__cd.__nsteps = 1; /* Only one step allowed. */ cc->__cd_in.__cd.__steps = fcts.towc; diff --git a/libio/libioP.h b/libio/libioP.h index f31a26b0d7..e3356f4a7e 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997, 1998, 1999 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or @@ -390,6 +390,7 @@ extern struct _IO_jump_t _IO_proc_jumps; extern struct _IO_jump_t _IO_old_proc_jumps; extern struct _IO_jump_t _IO_str_jumps; extern struct _IO_jump_t _IO_wstr_jumps; +extern struct _IO_codecvt __libio_codecvt; 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)); |