sttmpfiles(3)
πΈ sttmpfiles β temporary files handling, but make it cute πΈ
okay bestie, so this is the ShapeTools Toolkit Library page about temporary files, and ngl it's lowkey the most responsible little group of functions you'll ever meet. It's stTmpFile, stRegisterFile, stUnRegisterFile, and stRmRegisteredFiles, and they're all about making sure your temp files don't just β¨lingerβ¨ like a situationship after you're done. Periodt.
β¨ SYNOPSIS β¨
#include <config.h>
#include <sttk.h>
char*stTmpFile (char *path);
voidstRegisterFile (char *fileName);
voidstUnRegisterFile (char *fileName);
voidstRmRegisteredFiles (void);
π DESCRIPTION π
So like, four functions, four jobs, one shared mission: no bogus temp files surviving your program's messy exit. Let's go one by one, bestie. π«Ά
stTmpFileβ it creates a unique filename for a temporary file, registers it (yes, the waystRegisterFiledoes, see below π), and hands it back to you. But here's the tea: the return value lives in static memory, so it gets overwritten on the very next call ofstTmpFile. So don't be out here holding onto that pointer like it's your forever girl β it is NOT. Also the temp file lives in the/tmpdirectory. That's just where it's at. πstRegisterFileβ takes yourfileNameand adds it to an internal static list of file names. Why? Because this list is literally keeping track of every temp file that needs to get deleted by the time the program finishes running. And when your program dies an abnormal death (signal vibes π), the termination handler can callstRmRegisteredFilesto nuke all the registered files. Which means: no bogus temp files left behind after a crash. Iconic behaviour, honestly.stUnRegisterFileβ takesfileNameand removes it from that internal list. You should call this when the corresponding file was already removed through the regular control flow. Like, if it's already gone, tell the list it's gone. Be polite. Communication is key. πstRmRegisteredFilesβ the cleanup queen π. It removes all the files named in the internal list that got built up bystTmpFileandstRegisterFile, then clears the list. And if there are bogus entries in there β names with no corresponding file, we've all been there π β they're just ignored. No drama. Also, heads up: invokingstCatchSigs(3)makesstRmRegisteredFilesget called when any of these signals show up:SIGQUIT,SIGFPE,SIGBUS,SIGSEGV, andSIGTERM. AndstCleanup(3)also callsstRmRegisteredFiles. So yeah, it's got friends looking out for it. π
bestie note: the whole point of this system is that abnormal termination doesn't leave your /tmp looking like a crime scene. Register your files, unregister them when you clean up normally, and let the signal handlers handle the rest. π§
π¦ SEE ALSO π¦
π LIMITS π
okay so there IS a cap, and it's giving "small but mighty":
- The maximum number of temporary files you can register is 16.
That's it. Sixteen. So like, register responsibly, bestie. β
and that's the whole page, fr fr π this was sttk-1.7, dated Thu Jun 24 17:43:36 1993 β yes, 1993, she's vintage and she ATE, no cap. mwah π
π¦ where this page comes from
- debian bookworm: atfs-dev 1.4pl6-15+b1
- ubuntu jammy: atfs-dev 1.4pl6-15
- ubuntu noble: atfs-dev 1.4pl6-16.1build1
- ubuntu resolute: atfs-dev 1.4pl6-17
- ubuntu stonking: atfs-dev 1.4pl6-17
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms