Name

wfdopen
- stream open function

Library

libc.lib

Synopsis

  #include <wchar.h>
  FILE * wfdopen (int fd ,const wchar_t * mode);

Return values

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

Detailed description

The wfdopen function associates a stream with the existing file descriptor, fd. The mode argument is used just as in the function wfopen.

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.


Example

#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;
}



Output:
Successfully read from the stream the following:
Hello.



Errors

[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.


Limitations

All the limitations that apply to wfopen apply to wfdopen 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