/* We must convert the narrow format string to a wide one. Each byte can produce at most one wide character. */ wchar_t *wfmt; mbstate_t mbstate; int res; int used_malloc = 0; size_t len = strlen (fmt) + 1;
int _IO_fwide (FILE *fp, int mode) { /* Normalize the value. */ mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1);
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) if (__glibc_unlikely (&_IO_stdin_used == NULL) && _IO_legacy_file (fp)) /* This is for a stream in the glibc 2.0 format. */ return-1; #endif
/* The orientation already has been determined. */ if (fp->_mode != 0 /* Or the caller simply wants to know about the current orientation. */ || mode == 0) return fp->_mode;
/* Set the orientation appropriately. */ if (mode > 0) { struct _IO_codecvt *cc = fp->_codecvt = &fp->_wide_data->_codecvt;
/* Get the character conversion functions based on the currently selected locale for LC_CTYPE. */ { /* 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));
off64_t _IO_wfile_seekoff (FILE *fp, off64_t offset, int dir, int mode) { off64_t result; off64_t delta, new_offset; longint count;
/* Short-circuit into a separate function. We don't want to mix any functionality and we don't want to touch anything inside the FILE object. */ if (mode == 0) return do_ftell_wide (fp);
/* 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->_wide_data->_IO_read_base == fp->_wide_data->_IO_read_end) && (fp->_wide_data->_IO_write_base == fp->_wide_data->_IO_write_ptr));
/* 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 pptr. 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-mapped files. */ if (was_writing && _IO_switch_to_wget_mode (fp)) return WEOF;