Name

wfopen - stream open function

Library

libc.lib

Synopsis

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

Return values

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

Detailed description

The wfopen function opens the file whose name is the wide character string pointed to by path and associates a stream with it.

The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):

"r" Open text file for reading. The stream is positioned at the beginning of the file.
"r+" Open for reading and writing. The stream is positioned at the beginning of the file.
"w" Truncate to zero length or create text file for writing. The stream is positioned at the beginning of the file.
"w+" Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
"a" Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek or similar.
"a+" Open for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek or similar.

The mode string can also include the letter ‘‘b’’ either as a third character or as a character between the characters in any of the two-character strings described above. This is strictly for compatibility with -isoC and has no effect; the ‘‘b’’ is ignored.

Reads and writes may be intermixed on read/write streams in any order, and do not require an intermediate seek as in previous versions of stdio. This is not portable to other systems, however; ANSI C requires that a file positioning function intervene between output and input, unless an input operation encounters end-of-file.


Examples

/****************** this program shows opening  in write mode,write data and close **************/
/****************** again open in append mode and write data***** ******************************/
/***************************** Check file c:\wfopen.txt*****************************************/
#include <stdio.h>
int main(void)
        {
        FILE *fp;       
        wchar_t* name = L"c:\wfopen.txt";
        if ((fp = wfopen (name, L"wb")) == NULL)
                {
                printf("Error creating file");
                return -1;
                }
        printf("Opened file \n");
        fprintf(fp, "This is the first line\n");
        printf("Wrote to file\n");
        fclose (fp);
        printf("Closed file\n");
        if ((fp = wfopen (name, L"a")) == NULL)
                {
                printf("Error opening file");
                return -1;
                }
        printf("Opened file for appending\n");
        fprintf(fp, "This is the second line\n");
        fclose (fp);
        printf("closed file, check output in c:\ wfopen.txt file\n");
        wunlink(name);
        return 0;
}

         

Output

Opened file
Wrote to file
Closed file
Opened file for appending
closed file, check output in c:\ wfopen.txt file

         

Errors

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

The wfopen, functions may also fail and set errno for any of the errors specified for the routine malloc.

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


Note

1) Mode values for group and others will be ignored for file creation, execute bit and setuid on exec bit on an file don’t have any effect while file creation.Default working
directoy of a process is initalized to C: \private \UID (UID of the calling application), and any data written into this C: \private \UID directory persists between phone resets.

2) If the specified file is a symbolic link and the file it is pointing to is invalid, the symbolic link file will be automatically removed.


Limitations

A file in cannot be created with write-only permissions, hence when attempting to create a file in write-only permissions the file will be created with read-write permission. Creating a new file with O_CREAT flag, doesn’t alter the time stamp of parent directory, created entry has only two time stamps access and modification timestamps. Creation time stamp of the file is not supported, here accesstime stamp is equal to modification time stamp. open, fclose and fflush.

See also

open, fclose, fileno, fseek, fopen


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top