---
name: "uid_from_user"
section: "3bsd"
platform: "linux"
package: "libbsd"
version: "0.12.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/pwcache/3bsd"
---

# uid\_from\_user(3bsd)

cache password and group entries

Part of [pwcache(3bsd)](/pwcache/3bsd.md).

## NAME

**user\_from\_uid**, **uid\_from\_user**, **group\_from\_gid**, **gid\_from\_group** – cache password and group entries

## LIBRARY

library “libbsd”

## SYNOPSIS

**#include \<pwd.h\>**

(See [libbsd(7)](/libbsd/7.md) for include usage.)

*int*\

**uid\_from\_user**(*const char \*name*, *uid\_t \*uid*);

*const* *char* *\**\

**user\_from\_uid**(*uid\_t uid*, *int nouser*);

**#include \<grp.h\>**

*int*\

**gid\_from\_group**(*const char \*name*, *gid\_t \*gid*);

*const* *char* *\**\

**group\_from\_gid**(*gid\_t gid*, *int nogroup*);

## DESCRIPTION

The **user\_from\_uid**() function returns the user name associated with the argument *uid*. The user name is cached so that multiple calls with the same *uid* do not require additional calls to [getpwuid(3)](/getpwuid/3.md). If there is no user associated with the *uid*, a pointer is returned to a string representation of the *uid*, unless the argument *nouser* is non-zero, in which case a null pointer is returned.

The **uid\_from\_user**() function returns the user ID associated with the argument *name*. The user ID is cached so that multiple calls with the same *name* do not require additional calls to [getpwnam(3)](/getpwnam/3.md). If there is no user ID associated with the *name*, the **uid\_from\_user**() function returns -1; otherwise it stores the user ID at the location pointed to by *uid* and returns 0.

The **group\_from\_gid**() function returns the group name associated with the argument *gid*. The group name is cached so that multiple calls with the same *gid* do not require additional calls to [getgrgid(3)](/getgrgid/3.md). If there is no group associated with the *gid*, a pointer is returned to a string representation of the *gid*, unless the argument *nogroup* is non-zero, in which case a null pointer is returned.

The **gid\_from\_group**() function returns the group ID associated with the argument *name*. The group ID is cached so that multiple calls with the same *name* do not require additional calls to [getgrnam(3)](/getgrnam/3.md). If there is no group ID associated with the *name*, the **gid\_from\_group**() function returns -1; otherwise it stores the group ID at the location pointed to by *gid* and returns 0.

## SEE ALSO

[getgrgid(3)](/getgrgid/3.md), [getpwuid(3)](/getpwuid/3.md)

## HISTORY

The **user\_from\_uid**() and **group\_from\_gid**() functions first appeared in 4.4BSD.

The **uid\_from\_user**() and **gid\_from\_group**() functions first appeared in NetBSD 1.4 and OpenBSD 6.4.
