aboutsummaryrefslogtreecommitdiff
path: root/testcases/open_posix_testsuite/include/tempfile.h
blob: 0fd27cee3a2141ddfbf2eba8a49e8a256273f407 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (c) 2021 Joerg Vehlow <lkml@jv-coder.de>
 */

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#define PTS_GET_TMP_FILENAME(target, prefix) \
    snprintf(target, sizeof(target), \
    "%s/" prefix "_pid-%d", pts_get_tmpdir(), getpid());

static inline const char *pts_get_tmpdir(void)
{
    const char *tmpdir_env;
    tmpdir_env = getenv("TMPDIR");
    return tmpdir_env ? tmpdir_env : "/tmp";
}