Family: mk
Authors: KSB Braunsdorf
Mail: [email protected]
Version: 1.1
Bugs: None known.

Introduction

FreeBSD and some other modern OpenSource UNIX systems include a more secure version of mktemp(3). For those of us who support other flavors we include these emulation function.

Configuration

Provide a standard "machine.h" which defines:
#define EMU_ARC4RANDOM
Defined to be the integer 0 if the local UNIX flavor has arc4random() available.

Synopsis

extern char *mktemp(char *template);
extern char *mkdtemp(char *template);
extern int mkstemp(char *template);
extern int mkstemps(char *template, int suffixlen);
extern int mkutemp(char *template);
extern int mkutemps(char *template, int suffixlen);
extern int _mktemp(char *template, int suffixopt, int (*_chk)(char *, void *), void *pvParam);

Description

Each returns the same values as the FreeBSD manual page requires. See mktemp(3) for the explaination the "XXXXXX" replacement.

Provides

extern int mkstemp(char *template);
Return an open file descriptor on the new file, mode 0600;
extern int mkstemps(char *template, int suffixlen);
return an open file descriptor, as above. Do not replace and "X" characters in the last isuffixlen of the input template.
extern char *mkdtemp(char *template);
Return the name of a new directory, mode 0700.
extern int mkutemp(char *template);
extern int mkutemps(char *, int suffixlen);.
Return an open socket bound to a new unix domain socket. The suffixed version is also provided.
extern char *_mktemp(char *template, int suffixopt, int (*chk)(char *, void *), void *pvparam);
This is the generic interface that all of the above uses. A random filename is presented to the chk function for inspection. A return of 0 accepts the proposed filename, any other value rejects it. It errno is set to ENOENT another random name is proposed (else a NULL pointer is returned). The suffixopt parameter is set to the length of the suffix to skip at the end of the template.

EXAMPLE

See the test driver embedded in the module. This is intended as an emulation, as such the explaination is "it works like the original".

Diagnostics

None.

See Also

mktemp(3)

To Do List

None. There is an unused function compiler warning in some explode cases, but that's just noise.
$Id: mk.html,v 6.5 2012/03/21 16:15:05 ksb Exp $