sys_get_temp_dir

sys_get_temp_dir(): string

Returns the temporary-file directory path (resolving the TMPDIR/TEMP/TMP environment family). The demo prints derived facts only - the path itself is environment-dependent, so it verifies "non-empty and absolute" instead.

C C23

C23
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    /* C: no API at all - read TMPDIR yourself, fall back to stdio's P_tmpdir */
    const char *d = getenv("TMPDIR");
    if (d == NULL) d = P_tmpdir; /* usually "/tmp" */
    printf("non-empty: %s\n", strlen(d) > 0 ? "true" : "false");
    printf("absolute: %s\n", d[0] == '/' ? "true" : "false");
    return 0;
}
Output
non-empty: true
absolute: true

C++ C++26

C++26
#include <filesystem>
#include <iostream>

int main() {
    // C++17: std::filesystem::temp_directory_path, same environment family
    std::filesystem::path d = std::filesystem::temp_directory_path();
    std::cout << "non-empty: " << (!d.empty() ? "true" : "false") << "\n";
    std::cout << "absolute: " << (d.is_absolute() ? "true" : "false") << "\n";
    return 0;
}
Output
non-empty: true
absolute: true

C# v11.0.100

v11.0.100
// C#: Path.GetTempPath() resolves the same environment family
string d = Path.GetTempPath();
Console.WriteLine("non-empty: " + (d.Length > 0));
Console.WriteLine("absolute: " + Path.IsPathFullyQualified(d));
Output
non-empty: True
absolute: True

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"os"
	"path/filepath"
)

func main() {
	// Go: os.TempDir resolves the same environment family
	d := os.TempDir()
	fmt.Println("non-empty:", d != "")
	fmt.Println("absolute:", filepath.IsAbs(d))
}
Output
non-empty: true
absolute: true

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        // Java: the java.io.tmpdir property, same TMPDIR/TEMP family underneath
        String d = System.getProperty("java.io.tmpdir");
        System.out.println("non-empty: " + !d.isEmpty());
        System.out.println("absolute: " + new java.io.File(d).isAbsolute());
    }
}
Output
non-empty: true
absolute: true

JavaScript v26.13.1

v26.13.1
// Node: os.tmpdir() resolves the same TMPDIR/TEMP/TMP family
const os = require("node:os");
const path = require("node:path");
const d = os.tmpdir();
console.log("non-empty:", d !== "");
console.log("absolute:", path.isAbsolute(d));
Output
non-empty: true
absolute: true

PHP v8.6.0

v8.6.0
// every language resolves the same TMPDIR/TEMP family - output is a derived fact, not the path
$dir = sys_get_temp_dir();
echo "non-empty: ", var_export($dir !== "", true), "\n";
echo "absolute: ", var_export(str_starts_with($dir, DIRECTORY_SEPARATOR)
    || preg_match("/^[A-Za-z]:[\\\\\\/]/", $dir) === 1, true), "\n";
Output
non-empty: true
absolute: true

Python v3.15.2

v3.15.2
# Python: tempfile.gettempdir() resolves TMPDIR/TEMP/TMP like everyone else
import os
import tempfile
d = tempfile.gettempdir()
print("non-empty:", d != "")
print("absolute:", os.path.isabs(d))
Output
non-empty: True
absolute: True

Rust v1.99.1

v1.99.1
fn main() {
    // Rust: std::env::temp_dir, same TMPDIR/TEMP family
    let d = std::env::temp_dir();
    println!("non-empty: {}", !d.as_os_str().is_empty());
    println!("absolute: {}", d.is_absolute());
}
Output
non-empty: true
absolute: true

TypeScript v26.13.1

v26.13.1
// TS: same resolution as JS, with types
import os from "node:os";
import path from "node:path";
const d: string = os.tmpdir();
console.log("non-empty:", d !== "");
console.log("absolute:", path.isAbsolute(d));
Output
non-empty: true
absolute: true

Language differences

C: no API - read TMPDIR yourself, falling back to stdio's P_tmpdir ("/tmp").

C++: C++17 std::filesystem::temp_directory_path().

C#: Path.GetTempPath() - the result MAY end with a directory separator; handle it before concatenating.

Go: os.TempDir() (the directory is not guaranteed to exist).

Java: System.getProperty("java.io.tmpdir").

JavaScript: Node's os.tmpdir().

PHP: resolution order is the sys_temp_dir ini setting > the TMPDIR environment variable > the system default; the return value carries NO trailing slash (consistent across platforms) - concatenate with DIRECTORY_SEPARATOR; pair it with tempnam()/tmpfile() to create temp files.

Python: tempfile.gettempdir(); use the TemporaryFile/TemporaryDirectory family to actually create temp files.

Rust: std::env::temp_dir().

TypeScript: same as JavaScript.