Add nl_srterror

This commit is contained in:
Harshit-Dhanwalkar 2026-06-21 19:15:08 +05:30
parent ff1ec552da
commit 96369d6f94
2 changed files with 11 additions and 6 deletions

View file

@ -1,5 +1,6 @@
#include "nl_errno.h"
#include "nl_syscall.h"
#include <stddef.h>
int errno = 0;
@ -24,14 +25,16 @@ static const struct {
{28, "No space left on device"}, {32, "Broken pipe"},
{110, "Connection timed out"}, {0, (const char *)0}};
void nl_perror(const char *msg) {
const char *estr = "Unknown error";
const char *nl_strerror(int e) {
for (int i = 0; _errtab[i].msg; i++) {
if (_errtab[i].code == errno) {
estr = _errtab[i].msg;
break;
}
if (_errtab[i].code == e)
return _errtab[i].msg;
}
return "Unknown error";
}
void nl_perror(const char *msg) {
const char *estr = nl_strerror(errno);
if (msg && msg[0]) {
_ewrite(msg, _slen(msg));
_ewrite(": ", 2);

View file

@ -5,8 +5,10 @@
extern int errno;
const char *nl_strerror(int err);
void nl_perror(const char *msg);
#define perror(msg) nl_perror(msg)
#define strerror(e) nl_strerror(e)
#endif