Next: , Previous: fgetwc, Up: Stdio


4.14 fgetws, fgetws_unlocked—get wide character string from a file or stream

Synopsis

     #include <wchar.h>
     wchar_t *fgetws(wchar_t *__restrict ws, int n,
         FILE *__restrict fp);
     
     #define _GNU_SOURCE
     #include <wchar.h>
     wchar_t *fgetws_unlocked(wchar_t *__restrict ws, int n,
         FILE *__restrict fp);
     
     #include <wchar.h>
     wchar_t *_fgetws_r(struct _reent *ptr, wchar_t *ws,
         int n, FILE *fp);
     
     #include <wchar.h>
     wchar_t *_fgetws_unlocked_r(struct _reent *ptr, wchar_t *ws,
         int n, FILE *fp);
     

Description
Reads at most n-1 wide characters from fp until a newline is found. The wide characters including to the newline are stored in ws. The buffer is terminated with a 0.

fgetws_unlocked is a non-thread-safe version of fgetws. fgetws_unlocked may only safely be used within a scope protected by flockfile() (or ftrylockfile()) and funlockfile(). This function may safely be used in a multi-threaded program if and only if they are called while the invoking thread owns the (FILE *) object, as is the case after a successful call to the flockfile() or ftrylockfile() functions. If threads are disabled, then fgetws_unlocked is equivalent to fgetws.

The _fgetws_r and _fgetws_unlocked_r functions are simply reentrant version of the above and are passed an additional reentrancy structure pointer: ptr.


Returns
fgetws returns the buffer passed to it, with the data filled in. If end of file occurs with some data already accumulated, the data is returned with no other indication. If no data are read, NULL is returned instead.

Portability
fgetws is required by C99 and POSIX.1-2001.

fgetws_unlocked is a GNU extension.