Name

wfreopen
- stream open function

Library

libc.lib

Synopsis

  #include <wchar.h>
  FILE * wfreopen (const wchar_t * path, const wchar_t * mode,   FILE *stream);

Return values

Upon successful completion wfreopen, returns a FILE pointer. Otherwise, NULL is returned and the global variable errno is set to indicate the error.

Detailed description

The wfreopen function opens the file whose name is the string pointed to by path and associates the stream pointed to by stream with it. The original stream (if it exists) is closed. The mode argument is used just as in the wfopen function.

If the path argument is NULL, wfreopen attempts to re-open the file associated with stream with a new mode. The new mode must be compatible with the mode that the stream was originally opened with:

The primary use of the wfreopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout).


Examples

/* wfreopen example: redirecting stdout */
#include <stdio.h>
#include <wchar.h>
int main ()
{
  wfreopen (L"c:\myfile.txt",L"w",stdout);
  printf ("This sentence is redirected to a file.");
  fclose (stdout);
  return 0;
}


Output:
Contents of myfile.txt:This sentence is redirected to a file.
The output here is redirected from stdout to file myfile.txt



Errors

[EINVAL]
  The mode argument to wfreopen, was invalid.

The wfreopen function may also fail and set errno for any of the errors specified for the routine wopen.


Limitations

All the limitations that apply to wfopen apply to wfreopen also.

See also

wopen, wfclose, wfopen


Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top