When a byte-oriented stream function touches a stream, that stream
should be set to byte-oriented mode if it hasn't been set yet. If
it has been set, the opertion should only succeed if the stream is
already in byte-oriented mode.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
This function is used to set the orientation of a stream to either
byte-oriented or wchar-oriented.
More info on this function is here:
https://man7.org/linux/man-pages/man3/fwide.3p.html
This implementation only impmlemnts the manual switching and does
not yet guard against using a byte-oriented stream with wchar
functions and vice versa. Those step will come in additional
commits.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
realpath: Fixing undefined behaviour in the second test. If the call fails the resolved_name argument cannot be used for error checking because its state is undefined by SUSv2.
pipe: Changing the order of close and write error handling code. Errors in close could overwrite errno after write errors, returning incorrect error messages.
gmtime: Removed duplicate checks
Other fixes for fseek, rename, mktime, putwchar
This will allow us to redefine the exit function.
For example:
```
#define exit(code) { \
fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
__FILE__, __LINE__, #code, __func__); \
_exit(code); \
}
```