-->

Previous | Table of Contents | Next

Page 934


        gid_t    gr_gid;      /* group id */

        char     **gr_mem;    /* group members */

};

RETURN VALUE

The getgrnam()and getgrgid() functions return the group information structure, or NULL if the matching entry is not found or an error occurs.

ERRORS

ENOMEM Insufficient memory to allocate group information structure.

FILES

/etc/group group database file

CONFORMS TO

SVID 3, POSIX, BSD 4.3

SEE ALSO

fgetgrent(3), getgrent(3), setgrent(3), endgrent(3)

GNU, 4 April 1993

getlogin, cuserid

getlogin, cuserid—Get username

SYNOPSIS


#include <unistd.h>

char * getlogin ( void );

#include <stdio.h>

char * cuserid ( char *string );

DESCRIPTION

getlogin returns a pointer to a string containing the name of the user logged in on the controlling terminal of the process, or a null pointer if this information cannot be determined. The string is statically allocated and might be overwritten on subsequent calls to this function or to cuserid.

cuserid returns a pointer to a string containing a username associated with the effective user ID of the process. If string is not a null pointer, it should be an array that can hold at least L_cuserid characters; the string is returned in this array. Otherwise, a pointer to a string in a static area is returned. This string is statically allocated and might be overwritten on subsequent calls to this function or to getlogin.

The macro L_cuserid is an integer constant that indicates how long an array you might need to store a username. L_cuserid is declared in stdio.h.

These functions let your program positively identify the user who is running (cuserid) or the user who logged in this session (getlogin). (These can differ when setuid programs are involved.) The user cannot do anything to fool these functions.

For most purposes, it is more useful to use the environment variable LOGNAME to find out who the user is. This is more flexible precisely because the user can set LOGNAME arbitrarily.

ERRORS

ENOMEM Insufficient memory to allocate passwd structure.

Page 935

getmntent, setmntent, addmntent, endmntent, hasmntopt

FILES

The /etc/passwd password database file /etc/utmp (or /var/adm/utmp, or wherever your utmp file lives these days—the proper location depends on your libc version)

CONFORMS TO

POSIX.1. System V has a cuserid function that uses the real user ID rather than the effective user ID. The cuserid function was included in the 1988 version of POSIX, but was removed from the 1990 version.

BUGS

Unfortunately, it is often rather easy to fool getlogin(). Sometimes it does not work at all, because some program messed up the utmp file. Often, it gives only the first eight characters of the login name. The user currently logged in on the controlling tty of your program need not be the user who started it.

Nobody knows precisely what cuserid() does; so

Simply, do not use cuserid().

SEE ALSO

geteuid(2), getuid(2)

Linux 1.2.13, 3 September 1995

getmntent, setmntent, addmntent, endmntent, hasmntopt

getmntent, setmntent, addmntent, endmntent, hasmntopt—Get filesystem descriptor file entry

SYNOPSIS


#include <stdio.h>

#include <mntent.h>

FILE *setmntent(const char *filep, const char *type);

struct mntent *getmntent(FILE *filep);

int addmntent(FILE *filep, const struct mntent *mnt);

int endmntent(FILE *filep);

char *hasmntopt(const struct mntent *mnt, const char *opt);

DESCRIPTION

These routines are used to access the filesystem description file /etc/fstab and the mounted filesystem description file /etc/mstab.

The setmntent() function opens the filesystem description file filep and returns a file pointer that can be used by getmntent(). The argument type is the type of access required and can take the same values as the mode argument of fopen(3).

The getmntent() function reads the next line from the filesystem description file filep and returns a pointer to a structure containing the broken-out fields from a line in the file. The pointer points to a static area of memory that is overwritten by subsequent calls to getmntent().

The addmntent() function adds the mntent structure mnt to the end of the open file filep.

The endmntent() function closes the filesystem description file filep.

The hasmntopt() function scans the mnt_opts field of the mntent structure mnt for a substring that matches opt. (See <mntent.h> for valid mount options.)

Page 936

The mntent structure is defined in <mntent.h> as follows:


struct mntent {

        char     *mnt_fsname;     /* name of mounted filesystem */

        char     *mnt_dir;       /* filesystem path prefix */

        char     *mnt_type;      /* mount type (see mntent.h) */

        char     *mnt_opts;      /* mount options (see mntent.h) */

        int      mnt_freq;       /* dump frequency in days */

        int      mnt_passno;     /* pass number on parallel fsck */

};

RETURN VALUE

The getmntent() function returns a pointer to the mntent structure or NULL on failure.

The addmntent() function returns 0 on success and 1 on failure.

The endmntent() functions always returns 1.

The hasmntopt() function returns the address of the substring if a match is found, and NULL otherwise.

FILES

/etc/fstab filesystem description file

/etc/mtab mounted filesystem description file

CONFORMS TO

BSD 4.3

SEE ALSO

fopen(3), fstab(5)

27 June 1993

getnetent, getnetbyaddr, getnetbyname, setnetent, endnetent

getnetent, getnetbyaddr, getnetbyname, setnetent, endnetent—Get network entry

SYNTAX


#include <netdb.h>

struct netent *getnetent()

struct netent *getnetbyname(name)

char *name;

struct netent *getnetbyaddr(net, type)

long net; int type;

void setnetent(stayopen)

int stayopen;

void endnetent()

DESCRIPTION

The getnetent, getnetbyname, and getnetbyaddr subroutines each return a pointer to an object with the following structure, containing the broken-out fields of a line in the network database, /etc/networks:


struct netent {

        char     *n_name;      /* official name of net */

        char     **n_aliases;  /* alias list */

        int      n_addrtype;   /* net number type */

        long     n_net;        /* net number */

};

Previous | Table of Contents | Next