**tl;dr**

Is it a constraint violation if the next new-line character is the `n`th character in `stdin`?

---

Implementing [gets\_s()](https://en.cppreference.com/w/c/io/gets), I was wondering about what I consider to be a contradiction in the standard's wording.

The standard's definition (Annex K) reads (emphasis mine):

> 
> `char *gets_s(char *s, rsize_t n);`
> 
> 
> Runtime-constraints
> 
> 
> [...] **A new-line character**, end-of-file, or read error **shall occur within reading
> n-1 characters** from `stdin`.
> 
> 
> 

> 
> [...]
> 
> 
> The `gets_s` function reads at most one less than the number of characters specified by `n`
> from the stream pointed to by `stdin`, into the array pointed to by `s`. No additional
> characters are read after a new-line character (which is discarded) or after end-of-file.
> **The discarded new-line character does not count towards number of characters read.**
> 
> 
> 

Let us assume that a new-line character appears as the `n`th character of the input. The clearest example would be with `n == 1` and the next character in the `stdin` stream being that new-line.

Am I expected to...

* ...consider this a constraint violation (no newline within `n - 1 == 0` chracters read from `stdin`)? This would mean a call to the constraint violation handler, and returning `NULL`.
* ...reading the newline, discarding it (and not counting it towards the number of characters read), and returning `s`?

Either case would see `s[0] = '\0'`, and (everything up to and including) the newline read / discarded from `stdin`.