-->
Page 946
void setservent(int stayopen); void endservent(void);
DESCRIPTION
The getservent()function reads the next line from the file /etc/services and returns a structure, servent, containing the broken out fields from the line. The /etc/services file is opened if necessary.
The getservbyname()function returns a servent structure for the line from /etc/services that matches the service name using protocol proto.
The getservbyport()function returns a servent structure for the line that matches the port port given in network byte order using protocol proto.
The setservent()function opens and rewinds the /etc/services file. If stayopen is true (1), the file will not be closed between calls to getservbyname() and getservbyport().
The endservent() function closes /etc/services.
The servent structure is defined in <netdb.h> as follows:
struct servent { char *s_name; /* official service name */ char **s_aliases; /* alias list */ int s_port; /* port number */ char *s_proto; /* protocol to use */ }
The members of the servent structure are:
s_name | The official name of the service. |
s_aliases | A zero-terminated list of alternative names for the service. |
s_port | The port number for the service, given in network byte order. |
s_proto | The name of the protocol to use with this service. |
RETURN VALUE
The getservent(), getservbyname(), and getservbyport() functions return the servent structure, or a NULL pointer if an error occurs or the end of the file is reached.
FILES
/etc/services | Services database file |
CONFORMS TO
BSD 4.3
SEE ALSO
getprotoent(3), getnetent(3), services(5)
BSD, 22 April 1996
getusershell, setusershell, endusershellGet legal user shells
SYNOPSIS
#include <unistd.h> char *getusershell(void);
Page 947
void setusershell(void); void endusershell(void);
DESCRIPTION
The getusershell() function returns the next line from the file /etc/shells, opening the file if necessary. The line should contain the pathname of a valid user shell. If /etc/shells does not exist or is unreadable, getusershell() behaves as if /bin/sh and /bin/csh were listed in the file.
The setusershell() function rewinds /etc/shells.
The endusershell() function closes /etc/shells.
RETURN VALUE
The getusershell() function returns a NULL pointer on end of file.
FILES
/etc/shells
CONFORMS TO
BSD 4.3
SEE ALSO
shells(5)
BSD, 4 July 1993
getutent, getutid, getutline, pututline, setutent, endutent, utmpnameAccess utmp file entries
SYNOPSIS
#include <utmp.h> struct utmp *getutent(void); struct utmp *getutid(struct utmp *ut); struct utmp *getutline(struct utmp *ut); void pututline(struct utmp *ut); void setutent(void); void endutent(void); void utmpname(const char *file);
DESCRIPTION
utmpname() sets the name of the utmp-format file for the other utmp functions to access. If utmpname() is not used to set the filename before the other functions are used, they assume PATH_UTMP, as defined in <paths.h>.
setutent() rewinds the file pointer to the beginning of the utmp file. It is generally a good idea to call it before any of the other functions.
endutent()closes the utmp file. It should be called when the user code is done accessing the file with the other functions.
getutent() reads a line from the current file position in the utmp file. It returns a pointer to a structure containing the fields of the line.
getutid()searches forward from the current file position in the utmp file based on ut. If ut->ut_type is RUN_LVL, BOOT_TIME, NEW_TIME, or OLD_TIME, getutid() will find the first entry whose ut_type field matches ut->ut_type. If ut->ut_type is
Page 948
INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, getutid() will find the first entry whose ut_id field matches ut->ut_id.
getutline() searches forward from the current file position in the utmp file. It scans entries whose ut type is USER_PROCESS or LOGIN_PROCESS and returns the first one whose ut_line field matches ut->ut_line.
pututline()writes the utmp structure ut into the utmp file. It uses getutid() to search for the proper place in the file to insert the new entry. If it cannot find an appropriate slot for ut, pututline() will append the new entry to the end of the file.
RETURN VALUE
getutent(), getutid(), and getutline() return a pointer to a struct utmp, which is defined in <utmp.h>.
FILES
/var/run/utmpDatabase of currently logged-in users
/var/log/wtmpDatabase of past user logins
CONFORMS TO
XPG 2, SVID 2, Linux FSSTND 1.2
SEE ALSO
utmp(5)
Linux libc 5.0.0, 22 March 1995
getw, putwInput and output of words (ints)
SYNOPSIS
#include <stdio.h> int getw(FILE *stream); int putw(int w,FILE*stream);
DESCRIPTION
getw reads a word (that is, an int) from stream. It's provided for compatibility with SVID. I recommend you use fread(3) instead. putw writes the word w (that is, an int) to stream. It is provided for compatibility with SVID, but I recommend you use fwrite(3) instead.
RETURN VALUES
Normally, getw returns the word read, and putw returns the word written. On error, they return EOF.
BUGS
The value returned on error is also a legitimate data value. ferror(3) can be used to distinguish between the two cases.
CONFORMS TO
SVID
SEE ALSO
fread(3), fwrite(3), ferror(3), getc(3), putc(3)
GNU, 16 September 1995
Page 949
glob, globfreeFind pathnames matching a pattern; free memory from glob()
SYNOPSIS
#include <glob.h> int glob(const char *pattern, int flags, int errfunc(const char * epath, int eerrno), glob_t *pglob); void globfree(glob_t *pglob);
DESCRIPTION
The glob() function searches for all the pathnames matching pattern according to the rules used by the shell (see glob(7)). No tilde expansion or parameter substitution is done.
The globfree() function frees the dynamically allocated storage from an earlier call to glob().
The results of a glob() call are stored in the structure pointed to by pglob, which is a glob_t that is declared in <glob.h> as
typedef struct { int gl_pathc; /* Count of paths matched so far */ char **gl_pathv; /* List of matched pathnames. */ int gl_offs; /* Slots to reserve in `gl pathv'. */ int gl_flags; /* Flags for globbing */ } glob_t;
Results are stored in dynamically allocated storage.
The parameter flags is made up of bitwise OR of zero or more the following symbolic constants, which modify the of behavior of glob():
GLOB_ERR | Return on read error (because a directory does not have read permission, for example). |
GLOB_MARK | Append a slash to each path which corresponds to a directory. |
GLOB_NOSORT | Don't sort the returned pathnames (they are by default). |
GLOB_DOOFS | pglob->gl_offs slots will be reserved at the beginning of the list of strings in pglob->pathv. |
GLOB_NOCHECK | If no pattern matches, return the original pattern. |
GLOB_APPEND | Append to the results of a previous call. Do not set this flag on the first invocation of glob(). |
GLOB_NOESCAPE | Meta characters cannot be quoted by backslashes. |
GLOB_PERIOD | A leading period can be matched by meta characters. |
If errfunc is not NULL, it will be called in case of an error with the arguments epath, a pointer to the path that failed, and eerrno, the value of errno as returned from one of the calls to opendir(), readdir(), or stat(). If errfunc returns nonzero, or if GLOB_ERR is set, glob() will terminate after the call to errfunc.
Upon successful return, pglob->gl_pathc contains the number of matched pathnames and pglob->gl_pathv a pointer to the list of matched pathnames. The first pointer after the last pathname is NULL.
It is possible to call glob() several times. In that case, the GLOB_APPEND flag has to be set in flags on the second and later invocations.
RETURN VALUES
On successful completion, glob() returns 0. Other possible returns are
GLOB_NOSPACE | For running out of memory, |
GLOB_ABEND | For a read error, and |
GLOB_NOMATCH | For no found matches. |