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 way stRegisterFile does, 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 of stTmpFile. 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 /tmp directory. That's just where it's at. 🏠
  • stRegisterFile β€” takes your fileName and 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 call stRmRegisteredFiles to nuke all the registered files. Which means: no bogus temp files left behind after a crash. Iconic behaviour, honestly.
  • stUnRegisterFile β€” takes fileName and 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 by stTmpFile and stRegisterFile, 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: invoking stCatchSigs(3) makes stRmRegisteredFiles get called when any of these signals show up: SIGQUIT, SIGFPE, SIGBUS, SIGSEGV, and SIGTERM. And stCleanup(3) also calls stRmRegisteredFiles. 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