The gets_s
function reads characters from stdin until a newline is found or end-of-file occurs.
Writes only at most dmax characters into the array pointed to by str, and always writes the terminating null character.
Note that C11 allows only writing dmax-1 character. We need to work with the system fgets() passing it dmax+1. In any case, gets_s first finishes reading and discarding the characters from stdin until new-line character, end-of-file condition, or read error before calling the constraint handler. With SAFECLIB_STR_NULL_SLACK the rest of dmax is cleared with NULL bytes, without all elements following the terminating null character (if any) written by gets_s in the array of dmax characters pointed to by dest take unspeciļ¬ed values when gets_s returns.
- Parameters
-
[out] | dest | character string to be written. If the resulting concatenated string is less than dmax, the remaining slack space is nulled. |
[in] | dmax | restricted maximum length of the resulting dest, including the null. it may temp. write dmax+1, but always return max dmax. |
- Precondition
- dest shall not be a null pointer
-
dmax shall not equal zero
-
dmax shall not be greater than RSIZE_MAX_STR
- Note
- C11 uses RSIZE_MAX, not RSIZE_MAX_STR.
- Returns
- If there is a runtime-constraint violation, then if dest is not a null pointer and dmax is greater than zero and not greater than RSIZE_MAX_STR, then gets_s nulls dest.
- Return values
-
>0 | when successful operation, all the characters from src were appended to dest and the result in dest is null terminated. |
0 | + errno=ESNULLP when dest is a NULL pointer |
0 | + errno=ESZEROL when dmax = 0 |
0 | + errno=ESLEMAX when dmax > RSIZE_MAX_STR |
0 | + errno=ESUNTERM endline or eof not encountered after storing dmax-1 characters to dest. |
- See also
- scanf_s()