diff --git a/lib/chibi/system.sld b/lib/chibi/system.sld index e1b1faae..d0b64389 100644 --- a/lib/chibi/system.sld +++ b/lib/chibi/system.sld @@ -24,5 +24,5 @@ (getpwuid_r user (make-string 1024))))) (define (group-information group) (safe-car (if (string? group) - (getgrnam_r group (make-string 1024)) - (getgrgid_r group (make-string 1024))))))))) + (getgrnam-safe group (make-string 1024)) + (getgrgid-safe group (make-string 1024))))))))) diff --git a/lib/chibi/system.stub b/lib/chibi/system.stub index 1a99755b..15302f2f 100644 --- a/lib/chibi/system.stub +++ b/lib/chibi/system.stub @@ -83,15 +83,36 @@ (cond-expand (emscripten) (else - (define-c errno getgrgid_r - (gid_t (result group) + (c-declare " + int getgrnam_safe(const char* name, struct group* grp, + char* buf, size_t buflen, + struct group** result) { + int res = getgrnam_r(name, grp, buf, buflen, result); + if (res == 0 && result == NULL) { + res = errno ? errno : ENOENT; + } + return res; + } + int getgrgid_safe(gid_t gid, struct group* grp, + char* buf, size_t buflen, + struct group** result) { + int res = getgrgid_r(gid, grp, buf, buflen, result); + if (res == 0 && result == NULL) { + res = errno ? errno : ENOENT; + } + return res; + } +") + + (define-c errno getgrgid-safe + (gid_t (result group) + (link string) + (value (string-size arg2) int) + (result pointer group))) + + (define-c errno getgrnam-safe + (string (result group) (link string) (value (string-size arg2) int) - (result pointer group))) - - (define-c errno getgrnam_r - (string (result group) - (link string) - (value (string-size arg2) int) - (result pointer group))))) + (result pointer group)))))