DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

usersgroups(S)


usersgroups -- get users groups

Syntax

cc ... -lc
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>

int usersgroups (name, basegid, vectorsize, gidvector, stream) const char *name; const gid_t basegid; const int vectorsize; gid_t *gidvector; FILE *stream;

Description

The usersgroups function searches the group file, /etc/group, for the username specified by name, and, when the username is found, adds each corresponding group ID to gidvector. If basegid is not equal to NULLGROUP it is added to gidvector as the first element. gidvector is terminated by a group ID of NULLGROUP. vectorsize indicates the number of entries which may be placed in gidvector (including the terminator).

If stream is non-zero it is used to write warning and error messages to. usersgroups outputs warning messages when groups which the specified user is a member of are encountered after gidvector is full, and when the user is listed as being a member of a group more than once. If stream is a null pointer, the checks are still applied and the number of warnings still returned, but no output is written.

Return values

Upon successful completion the number of warnings is returned. Otherwise a value of -1 is returned, and errno is set to indicate the error.

Diagnostics

usersgroups will fail if:

[EINVAL]
vectorsize is less than one.

Warning

usersgroups uses routines based on getgrent(S). If the invoking program uses any of these routines, the group structure will be overwritten and the current position in the group file changed in the call to usersgroups.

usersgroups uses stdio(S), which causes programs which call it, not otherwise using standard I/O, to increase in size more than might be expected.

Files

/etc/group

See also

getgroups(S), initgroups(S), setgroups(S)

Standards conformance

usersgroups is an extension of AT&T System V provided by the Santa Cruz Operation.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003