qh_str_groupname_to_gid()

Updated: April 19, 2023

Safely converts a string into a gid_t

Synopsis:

#include <qh/string.h>
int qh_str_groupname_to_gid(const char *str,
                            gid_t *gid)

Arguments:

str
The string to convert into a group ID (gid).
gid
Pointer to the location where the gid can be stored.

Library:

qh

Description:

The qh_str_groupname_to_gid() function first checks the password database to determine if the string corresponds to a group name. If it does, the group ID (gid) for that group is returned. Otherwise, the function attempts to interpret the string as a decimal number (base 10), similar to strtoll() but with more error checking on the result of the conversion, and ensures that the result fits in a gid_t. By performing these tasks, it simplifies the work the caller is required to do, which is only to validate that the return value from qh_str_groupname_to_gid() is EOK.

For more information on using this function, see the documentation for strtoll().

Returns:

EOK on success or a standard errno on failure (errno is also set, and gid isn't updated).