Errno and EINVAL

Hello,

I would like to get rid of this c import, but couldn’t find EINVAL or errno in std lib.

There is only std.c.errno()

Any suggestions? Maybe there is even a way to write it more idiomatic.

const c = @cImport({
        @cInclude("errno.h");
    });
    if (std.c.unveil(null,null) == -1) {
        if (c.errno == c.EINVAL) {
            return Error.UnveilInvalidPermissions;
        } else {
            std.log.err("{s}", .{std.c.gai_strerror(c.errno)});
            return Error.UnveilLock;
        }
    }

Thanks : )

I think you can look at this code from 0.15.2 #std.posix.errno

And EINVAL is std.c.E.INVAL

2 Likes

Thanks.

const unveil_errno = std.c.errno(std.c.unveil(null,null));
    if (unveil_errno != .SUCCESS) {
        if (unveil_errno == std.c.E.INVAL) {
            return Error.UnveilInvalidPermissions;
        } else {
            std.log.err("{s}", .{std.c.gai_strerror(unveil_errno)});
            return Error.UnveilLock;
        }
    }

Thoughts on this?

Still not sure about std.c_gai_strerror()

What means gai?

getaddrinfo https://linux.die.net/man/3/gai_strerror

From this gai_strerror(3p) - Linux manual page my guess is that it is getaddrinfo abbreviated/used as a prefix to “namespace” those functions, I think it only makes sense to use that function if the errnos you are dealing with are part of the same kind / same family of functions.

std.c.E and std.c.EAI (expected by gai_strerror) are different enumerations and I think you shouldn’t pass a value of the former to a function expecting the latter, but I am not super familiar with the APIs.

I don’t think there is a function to convert std.c.E into an error message in the standard library, at least I didn’t find any.