#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>

#ifndef O_TMPFILE
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
#define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT)
#endif

int main (int argc, char **argv)
{
        int fd, dfd;
        const char *subpath = ".";

	if (argc < 2)
	  errx (1, "usage: %s DIR", argv[0]);

        dfd = open(argv[1], O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY);
	if (dfd < 0)
	  err (1, "open(/var/tmp");

        fd = openat (dfd, subpath, O_WRONLY | O_CLOEXEC | O_TMPFILE, 0600);
	if (fd < 0)
	  err (1, "openat(O_TMPFILE)");

        return 0;
}
