Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created March 22, 2019 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpmens/c62cca8dc6d4e16ed2145a4b848b9c7c to your computer and use it in GitHub Desktop.
Save jpmens/c62cca8dc6d4e16ed2145a4b848b9c7c to your computer and use it in GitHub Desktop.
FILE *open_tmpfile (void) {
struct cs_status cs;
int tmpfd;
FILE *tmpfile;
mode_t mask;
char *tmpdir;
char const * const template="%s/sponge.XXXXXX";
trapsignals();
cs = cs_enter();
tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
tmpdir = "/tmp";
/* Subtract 2 for `%s' and add 1 for the trailing NULL. */
tmpname=malloc(strlen(tmpdir) + strlen(template) - 2 + 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment