-->
Page 930
SEE ALSO
ipc(5), msgget(2), semget(2), shmget(2), stat(2)
Linux 0.99.13, 1 November 1993
ftwFile tree walk
SYNOPSIS
#include <ftw.h> int ftw(const char *directory, int(*funcptr)(const char *file, struct stat *sb, int flag), int depth);
DESCRIPTION
ftw() walks through the directory tree, starting from the indicated directory. For each found entry in the tree, it calls funcptr with the full pathname of the entry relative to directory, a pointer to the stat(2) structure for the entry and an int whose value will be one of the following:
FTW_F | Item is a normal file |
FTW_D | Item is a directory |
FTW_NS | The stat failed on the item |
FTW_DNR | Item is a directory which can't be read |
Warning: Anything other than directories, such as symbolic links, gets the FTW_F tag.
ftw() recursively calls itself for traversing found directories. To avoid using up all a program's file descriptors, depth specifies the number of simultaneous open directories. When the depth is exceeded, ftw() will become slower because directories have to be closed and reopened.
To stop the tree walk, funcptr returns a nonzero value; this value will become the return value of ftp(). Otherwise, ftw() will continue until it has traversed the entire tree (in which case it will return 0), or until it hits an error such as a malloc(3) failure, in which case it will return _1.
Because ftp() uses dynamic data structures, the only safe way to exit a tree walk is to return a nonzero value. To handle interrupts, for example, mark that the interrupt occurred and return a nonzero valuedon't use longjmp(3) unless the program is going to terminate.
SEE ALSO
stat(2)
Linux, 18 July 1993
gcvtConverts a floating-point number to a string
SYNOPSIS
#include <stdlib.h> char *gcvt(double number, size_t ndigit, char *buf);
DESCRIPTION
The gcvt() function converts number to a minimal-length, NULL-terminated ASCII string and stores the result in buf. It produces ndigit significant digits in either printf() F format or E format.
Page 931
RETURN VALUE
The gcvt() function returns the address of the string pointed to by buf.
SEE ALSO
ecvt(3), fcvt(3), sprintf(3)
29 March 1993
getcwd, get_current_dir_name, getwdGet current working directory
SYNOPSIS
#include <unistd.h> char *getcwd(char *buf, size_t size); char *get_current_working_dir_name(void); char *getwd(char *buf);
DESCRIPTION
The getcwd() function copies the absolute pathname of the current working directory to the array pointed to by buf, which is of length size.
If the current absolute pathname would require a buffer longer than size elements, NULL is returned, and errno is set to ERANGE; an application should check for this error, and allocate a larger buffer if necessary.
As an extension to the POSIX.1 standard, getcwd() allocates the buffer dynamically using malloc() if buf is NULL on call. In this case, the allocated buffer has the length size unless size is less than 0, when buf is allocated as large as necessary. It is possible (and, indeed, advisable) to free the buffers if they have been obtained this way.
get_current_dir_name, which is only prototyped if __USE_GNU is defined, will malloc(3) an array big enough to hold the current directory name. If the environment variable PWD is set, and its value is correct, that value will be returned.
getwd, which is only prototyped if __USE_BSD is defined, will not malloc(3) any memory. The buf argument should be a pointer to an array at least PATH_MAX bytes long. getwd returns only the first PATH_MAX bytes of the actual pathname.
RETURN VALUE
NULL on failure (for example, if the current directory is not readable), with errno set accordingly, and buf on success.
CONFORMS TO
POSIX.1
SEE ALSO
chdir(2), free(3), malloc(3).
GNU, 21 July 1993
getdirentriesGets directory entries in a filesystem-independent format
SYNOPSIS
#define __USE_BSD or #define __USE_MISC #include <dirent.h> ssize_t getdirentries(int fd, char *buf, size_t nbytes ,offt *basep);
Page 932
DESCRIPTION
This function reads directory entries from the directory specified by fd into buf. At most, nbytes are read. Reading starts at offset *basep, and *basep is updated with the new position after reading.
RETURN VALUE
getdirentries returns the number of bytes read, or 0 when at the end of the directory. If an error occurs, _1 is returned, and errno is set appropriately.
ERRORS
See the Linux library source code for details.
SEE ALSO
open(2), lseek(2)
BSD/MISC, 22 July 1993
getenvGets an environment variable
SYNOPSIS
#include <stdlib.h> char *getenv(const char *name);
DESCRIPTION
The getenv() function searches the environment list for a string that matches the string pointed to by name. The strings are of the form name=value.
RETURN VALUE
The getenv() function returns a pointer to the value in the environment, or NULL if there is no match.
CONFORMS TO
SVID 3, POSIX, BSD 4.3, ISO 9899
SEE ALSO
putenv(3), setenv(3), unsetenv(3)
GNU, 3 April 1993
getgrent, setgrent, endgrentGet group file entry
SYNOPSIS
#include <grp.h> #include <sys/types.h> struct group *getgrent(void); void setgrent(void); void endgrent(void);
Page 933
DESCRIPTION
The getgrent() function returns a pointer to a structure containing the group information from /etc/group. The first time it is called it returns the first entry; thereafter, it returns successive entries.
The setgrent() function rewinds the file pointer to the beginning of the /etc/group file.
The endgrent() function closes the /etc/group file.
The group structure is defined in <grp.h> as follows:
struct group { char *gr_name; /* group name */ char *gr_passwd; /* group password */ gid_t gr_gid; /* group id */ char **gr_mem; /* group members */ };
RETURN VALUE
The getgrent()function returns the group information structure, or NULL if there are no more entries or an error occurs.
ERRORS
ENOMEM | Insufficient memory to allocate group information structure. |
FILES
/etc/group group database file
CONFORMS TO
SVID 3, BSD 4.3
SEE ALSO
fgetgrent(3), getgrnam(3), getgrgid(3)
GNU, 4 April 1993
getgrnam, getgrgidGet group file entry
SYNOPSIS
#include <grp.h> #include <sys/types.h> struct group *getgrnam(const char *name); struct group *getgrgid(gid_t gid);
DESCRIPTION
The getgrnam() function returns a pointer to a structure containing the group information from /etc/group for the entry that matches the group name name.
The getgrgid() function returns a pointer to a structure containing the group information from /etc/group for the entry that matches the group id gid.
The group structure is defined in <grp.h> as follows:
struct group { char *gr_name; /* group name */ char *gr_passwd; /* group password */