Previous | Table of Contents | Next

Page 1054

RETURN VALUE

The tmpfile() function returns a stream descriptor, or NULL if a unique filename cannot be generated or the unique file cannot be opened.

ERRORS

EACCES Search permission denied for directory in file's path prefix
EEXIST Unable to generate a unique filename
EMFILE Too many file descriptors in use by process
ENFILE Too many files open in system
EROFS Read-only filesystem

CONFORMS TO

SVID 3, POSIX, BSD 4.3, ISO 9899

SEE ALSO

mktemp(3), mkstemp(3), tmpnam(3), tempnam(3)

GNU, 3 April 1993

tmpnam

tmpnam—Creates a name for a temporary file

SYNOPSIS

#include <stdio.h>
char *tmpnam(char *s);

DESCRIPTION

The tmpnam() function generates a unique temporary filename using the path prefix P_tmpdir defined in <stdio.h>. If the argument s is NULL, tmpnam() returns the address of an internal static area that holds the filename, which is overwritten by subsequent calls to tmpnam(). If s is not NULL, the filename is returned in s.

RETURN VALUE

The tmpnam() function returns a pointer to the unique temporary filename, or NULL if a unique name cannot be generated.

ERRORS

EEXIST Unable to generate a unique filename

CONFORMS TO

SVID 3, POSIX, BSD 4.3, ISO 9899

SEE ALSO

mktemp(3), mkstemp(3), tempnam(3), tmpfile(3)

GNU, 3 April 1993

Page 1055

toascii

toascii—Converts character to ASCII

SYNOPSIS

#include <ctype.h>
int toascii (int c);

DESCRIPTION

toascii() converts c to a 7-bit unsigned char value that fits into the ASCII character set, by clearing the high-order bits.

RETURN VALUE

The value returned is that of the converted character.

CONFORMS TO

SVID, BSD

BUGS

Many people will be unhappy if you use this function. This function will convert accented letters into random characters.

SEE ALSO

isascii(3), toupper(3), tolower(3)

GNU, 16 September 1995

toupper, tolower

toupper, tolower—Convert letter to uppercase or lowercase

SYNOPSIS

#include <ctype.h>
int toupper (int c);
int tolower (int c);

DESCRIPTION

toupper() converts the letter c to uppercase, if possible.

tolower() converts the letter c to lowercase, if possible.

RETURN VALUE

The value returned is that of the converted letter, or c if the conversion was not possible.

CONFORMS TO

ANSI C, BSD 4.3

BUGS

The details of what constitutes an uppercase or lowercase letter depend on the current locale. For example, the default locale does not know about umlauts, so no conversion is done for them.

In some non-English locales, there are lowercase letters with no corresponding uppercase equivalent; the German sharp s is one example.

Page 1056

SEE ALSO

isalpha(3), setlocale(3), locale(7)

GNU, 4 April 1993


tsearch, tfind, tdelete, twalk

tsearch, tfind, tdelete, twalk—Manage a binary tree

SYNOPSIS

#include <search.h>
void *tsearch (const void *key,void **rootp,
int (*compar)(const void *, const void *));
void *tfind (const void *key, const void **rootp,
int (*compar)(const void *, const void *));
void *tdelete (const void *key,void**rootp,
int (*compar)(const void *, const void *));
void twalk (const void *root,void (*action)(const void*nodep,
const VISIT which,
const int depth));

DESCRIPTION

tsearch, tfind, twalk, and tdelete manage a binary tree. They are generalized from Knuth (6.2.2) Algorithm T. The first field in each node of the tree is a pointer to the corresponding data item. (The calling program must store the actual data.) compar points to a comparison routine, which takes pointers to two items. It should return an integer that is negative, zero, or positive, depending on whether the first item is less than, equal to, or greater than the second.

tsearch searches the tree for an item. key points to the item to be searched for. rootp points to a variable that points to the root of the tree. If the tree is empty, then the variable that rootp points to should be set to NULL. If the item is found in the tree, then tsearch returns a pointer to it. If it is not found, then tsearch adds it, and returns a pointer to the newly added item.

tfind is like tsearch, except that if the item is not found, then tfind returns NULL.

tdelete deletes an item from the tree. Its arguments are the same as for tsearch.

twalk performs depth-first, left-to-right traversal of a binary tree. root points to the starting node for the traversal. If that node is not the root, then only part of the tree will be visited. twalk calls the user function action each time a node is visited (that is, three times for an internal node, and once for a leaf). action, in turn, takes three arguments. The first is a pointer to the node being visited. The second is an integer that takes on the values preorder, postorder, and endorder depending on whether this is the first, second, or third visit to the internal node, or leaf if it is the single visit to a leaf node. (These symbols are defined in <search.h>.) The third argument is the depth of the node, with zero being the root.

RETURN VALUE

tsearch returns a pointer to a matching item in the tree, or to the newly added item, or NULL if there was insufficient memory to add the item. tfind returns a pointer to the item, or NULL if no match is found. If there are multiple elements that match the key, the element returned is unspecified.

tdelete returns a pointer to the parent of the item deleted, or NULL if the item was not found.

tsearch, tfind, and tdelete also return NULL if rootp was NULL on entry.

WARNINGS

twalk takes a pointer to the root, while the other functions take a pointer to a variable that points to the root.

twalk uses postorder to mean "after the left subtree, but before the right subtree." Some authorities would call this inorder, and reserve postorder to mean "after both subtrees."

Previous | Table of Contents | Next

1