safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
freopen_s.c File Reference
#include "safe_lib.h"
+ Include dependency graph for freopen_s.c:

Functions

EXPORT errno_t freopen_s (FILE *restrict *restrict newstreamptr, const char *restrict filename, const char *restrict mode, FILE *restrict stream)
 The freopen_s function first, attempts to close the file associated with the stream, ignoring any errors. More...
 

Function Documentation

◆ freopen_s()

EXPORT errno_t freopen_s ( FILE *restrict *restrict  newstreamptr,
const char *restrict  filename,
const char *restrict  mode,
FILE *restrict  stream 
)

The freopen_s function first, attempts to close the file associated with the stream, ignoring any errors.

Then, if filename is not null, attempts to open the file specified by filename using mode as if by fopen, and associates that file with the file stream pointed to by stream. If filename is a null pointer, then the function attempts to reopen the file that is already associated with stream (it is implementation defined which mode changes are allowed in this case).

Remarks
SPECIFIED IN
Parameters
[out]newstreamptrpointer to a FILE stream that will be updated by this function call
[in]filenamefile name to associate the file stream to
[in]modeas in fopen
[in]streamthe file stream to modify
Precondition
Neither streamptr, stream nor mode shall be a null pointer.

If the file was reopened successfully, then the pointer to the FILE pointed to by newstreamptr will be set to the pointer to the object controlling the opened file. Otherwise, the pointer to the FILE pointed to by newstreamptr will be set to a null pointer.

Returns
The freopen_s function returns zero if it reopened the file. If not or there was a runtime-constraint violation, freopen_s returns a nonzero error code, and sets newstreamptr to NULL. If there is a runtime-constraint violation, freopen_s does not attempt to reopen the file. Sets the newstreamptr on success.
Return values
EOKon success
ESNULLPwhen any argument is a NULL pointer
>0 any other errno