diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
| commit | fc00c656c96528112d05cf0edf8631bd5eaea446 (patch) | |
| tree | a6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/stdio/perror.c | |
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/stdio/perror.c')
| -rw-r--r-- | lib/libc/stdio/perror.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c new file mode 100644 index 00000000..f3f4bb19 --- /dev/null +++ b/lib/libc/stdio/perror.c @@ -0,0 +1,26 @@ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <sys/uio.h> + +void perror(const char *s) +{ + struct iovec iov[4]; + + char *errstr = strerror(errno); + + if (s != NULL && *s != '\0') { + iov[0].iov_base = (void *)s; + iov[0].iov_len = strlen(s); + iov[1].iov_base = ": "; + iov[1].iov_len = 2; + } + + iov[s != NULL && *s != '\0' ? 2 : 0].iov_base = errstr; + iov[s != NULL && *s != '\0' ? 2 : 0].iov_len = strlen(errstr); + iov[s != NULL && *s != '\0' ? 3 : 1].iov_base = "\n"; + iov[s != NULL && *s != '\0' ? 3 : 1].iov_len = 1; + + writev(STDERR_FILENO, iov, s != NULL && *s != '\0' ? 4 : 2); +} |
