Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #138 Create temp file

Create a new temporary file on the filesystem.

import "os"
tmpfile, err := os.CreateTemp("", "")

tmpfile has type *os.File.

Use tmpfile.Name() if you need the path string.

Consider defer os.Remove(tmpfile.Name()) for cleanup.
#include <stdlib.h>
const char tmpl[] = "XXXXXX.tmp";
int fd = mkstemp(tmpl);

Template must contain six X characters that will be modified by mkstemp

New implementation...
< >
programming-idioms.org