1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2021 Joerg Vehlow <lkml@jv-coder.de> 4f08c3bdfSopenharmony_ci */ 5f08c3bdfSopenharmony_ci 6f08c3bdfSopenharmony_ci#include <stdlib.h> 7f08c3bdfSopenharmony_ci#include <stdio.h> 8f08c3bdfSopenharmony_ci#include <limits.h> 9f08c3bdfSopenharmony_ci 10f08c3bdfSopenharmony_ci#define PTS_GET_TMP_FILENAME(target, prefix) \ 11f08c3bdfSopenharmony_ci snprintf(target, sizeof(target), \ 12f08c3bdfSopenharmony_ci "%s/" prefix "_pid-%d", pts_get_tmpdir(), getpid()); 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_cistatic inline const char *pts_get_tmpdir(void) 15f08c3bdfSopenharmony_ci{ 16f08c3bdfSopenharmony_ci const char *tmpdir_env; 17f08c3bdfSopenharmony_ci tmpdir_env = getenv("TMPDIR"); 18f08c3bdfSopenharmony_ci return tmpdir_env ? tmpdir_env : "/tmp"; 19f08c3bdfSopenharmony_ci} 20