---
name: "uid_from_user"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/gid_from_group"
---

# uid\_from\_user(3)

cache password and group entries

Part of [gid\_from\_group(3)](/gid_from_group/3.md).

## NAME

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

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

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

*const* *char* *\**\

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

*int*\

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

*int*\

**pwcache\_userdb**(*int (\*setpassent)(int)*, *void (\*endpwent)(void)*, *struct passwd \* (\*getpwnam)(const char \*)*, *struct passwd \* (\*getpwuid)(uid\_t)*);

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

*const* *char* *\**\

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

*int*\

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

*int*\

**pwcache\_groupdb**(*int (\*setgroupent)(int)*, *void (\*endgrent)(void)*, *struct group \* (\*getgrnam)(const char \*)*, *struct group \* (\*getgrgid)(gid\_t)*);

## 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 **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 **uid\_from\_user**() function returns the uid associated with the argument *name*. The uid 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 uid associated with the *name*, the **uid\_from\_user**() function returns -1; otherwise it stores the uid at the location pointed to by *uid* and returns 0.

The **gid\_from\_group**() function returns the gid associated with the argument *name*. The gid 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 gid associated with the *name*, the **gid\_from\_group**() function returns -1; otherwise it stores the gid at the location pointed to by *gid* and returns 0.

The **pwcache\_userdb**() function changes the user database access routines which **user\_from\_uid**() and **uid\_from\_user**() call to search for users. The caches are flushed and the existing **endpwent**() method is called before switching to the new routines. *getpwnam* and *getpwuid* must be provided, and *setpassent* and *endpwent* may be NULL pointers.

The **pwcache\_groupdb**() function changes the group database access routines which **group\_from\_gid**() and **gid\_from\_group**() call to search for groups. The caches are flushed and the existing **endgrent**() method is called before switching to the new routines. *getgrnam* and *getgrgid* must be provided, and *setgroupent* and *endgrent* may be NULL pointers.

## ERRORS

If insufficient memory is available, **user\_from\_uid**() and **group\_from\_gid**() may return NULL pointers. *errno* is set to ENOMEM.

## SEE ALSO

[getgrgid(3)](/getgrgid/3.md), [getgrnam(3)](/getgrnam/3.md), [getpwnam(3)](/getpwnam/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.

The **pwcache\_userdb**() and **pwcache\_groupdb**() functions first appeared in NetBSD 1.6 and FreeBSD 10.0.
