// O_TMPFILE isn't available until Linux 3.11, so we fall back to this on // older kernels. AOSP was on a new enough kernel in the Lollipop timeframe, // so this code should be obsolete by 2025. static FILE* __tmpfile_dir_legacy(constchar* tmp_dir) { char* path = nullptr; if (asprintf(&path, "%s/tmp.XXXXXXXXXX", tmp_dir) == -1) { return nullptr;
}
int fd = mkstemp(path); if (fd == -1) {
free(path); return nullptr;
}
// Unlink the file now so that it's removed when closed.
unlink(path);
free(path);
// Can we still use the file now it's unlinked? // File systems without hard link support won't have the usual Unix semantics. struct stat sb; if (fstat(fd, &sb) == -1) {
ErrnoRestorer errno_restorer;
close(fd); return nullptr;
}
return __fd_to_fp(fd);
}
constchar* __get_TMPDIR() { // Use $TMPDIR if set, or fall back to /data/local/tmp otherwise. // Useless for apps, but good enough for the shell. constchar* tmpdir = getenv("TMPDIR"); return (tmpdir == nullptr) ? "/data/local/tmp" : tmpdir;
}
char* tempnam(constchar* dir, constchar* prefix) { // This function is a terrible idea, marked deprecated in our headers, // and marked obsolescent by POSIX.1-2008, but we make some effort anyway // since we can't easily remove it...
// $TMPDIR overrides any directory passed in. constchar* tmpdir = getenv("TMPDIR"); if (tmpdir != nullptr) dir = tmpdir;
// If we still have no directory, we'll give you a default. // It's useless for apps, but good enough for the shell. if (dir == nullptr) dir = "/data/local/tmp";
// Default prefix? if (prefix == nullptr) prefix = "tempnam.";
// Make up a mktemp(3) template and defer to it for the real work. char* path = nullptr; if (asprintf(&path, "%s/%sXXXXXXXXXX", dir, prefix) == -1) return nullptr; if (mktemp(path) == nullptr) {
free(path); return nullptr;
} return path;
}
char* tmpnam(char* s) { // This function is a terrible idea, marked deprecated in our headers, // and marked obsolescent by POSIX-1.2008, but we make some effort anyway // since we can't easily remove it...
// Default buffer? staticchar buf[L_tmpnam]; if (s == nullptr) s = buf;
// Make up a mktemp(3) template and defer to it for the real work.
snprintf(s, L_tmpnam, "%s/tmpnam.XXXXXXXXXX", __get_TMPDIR()); return mktemp(s);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.