---
name: "tst_tmpdir"
section: "3"
platform: "linux"
package: "ltp-dev"
version: "20091231+dfsg-1"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/tst_tmpdir"
---

# tst\_tmpdir(3)

create a unique testing directory and make it current. tst\_rmdir - remove the directory created by tst\_tmpdir.

## NAME

tst\_tmpdir - create a unique testing directory and make it current.\
 tst\_rmdir - remove the directory created by **tst\_tmpdir**.

## SYNOPSIS

**void tst\_tmpdir()**

**void tst\_rmdir()**

**extern char \*TESTDIR;**

## DESCRIPTION

The **tst\_tmpdir()** function uses the first three characters of the **TCID** global variable as the prefix in forming a unique directory name (via **tempnam**(3S)).  The directory is then created and made the current working directory.

If **tst\_tmpdir()** cannot form a unique directory name, create the directory, or **chdir** to the directory, it uses **tst\_brk()** to issue "BROK" messages for all test cases.  It then exits via **tst\_exit()**. Because **tst\_tmpdir()** exits in the event of a problem, a test must call it **before** performing any operations that would require running a cleanup routine.

The **tst\_rmdir()** function recursively removes the directory created by **tst\_tmpdir()**.  This function should be used **only** as a companion to **tst\_tmpdir()** and should be called immediately prior to the test exiting via **tst\_exit()**.

**tst\_rmdir()** uses the **system**(3S) library routine (which in turn calls [**fork**(2)](/fork/2.md)), so tests that use it **cannot** treat SIGCLD as an unexpected signal.

Users may gain access to the name of the temporary directory by declaring the external character pointer **TESTDIR**.

## DIAGNOSTICS

The **tst\_rmdir()** function will check the **TESTDIR** global variable to ensure that the user is not attempting to remove the root directory or some unspecified directories with a "\*" parameter.  All error/warning messages are delivered through **tst\_res()**.

## SEE ALSO

[fork(2)](/fork/2.md), system(3S), [tst\_res(3)](/tst_res/3.md), tmpnam(3S).
