#include <wchar.h>
|
FILE *
wfdopen (int fd ,const wchar_t * mode); |
The mode of the stream must be compatible with the mode of the file descriptor. In other words the type specified by the stream must be allowed by the file access mode of the open file. When the stream is closed via fclose, fd is also closed.
#include <io.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <string.h> #include <wchar.h> int main(void) { long length; int fh; char buffer1="HelloWorld"; char buffer2[20]; FILE *fp; memset(buffer, \0, 20); /* Initialize buffer*/ if (-1 == (fh = wopen(L"c:\sample.dat", O_WRONLY | O_CREAT | O_TRUNC, 0666))) { perror("Unable to open sample.dat"); return EXIT_FAILURE; } if (NULL == (fp = wfdopen(fh, L"r"))) { perror("fdopen failed"); close(fh); return EXIT_FAILURE; } if (7 != fwrite(buffer1, 1, 6, fp)) { perror("fread failed"); fclose(fp); return EXIT_FAILURE; } if (7 != fread(buffer2, 1, 6, fp)) { perror("fread failed"); fclose(fp); return EXIT_FAILURE; } buffer2[7]=\0; printf("Successfully read from the stream the following:\n%s.\n", buffer2); fclose(fp); return 0; }
Successfully read from the stream the following: Hello.
[EINVAL] | |
The mode argument to wfdopen, was invalid. | |
The function wfdopen may also fail and set errno for any of the errors specified for the routine wopen.
© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user. |