Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/mktemp/mktemp.c
Show All 31 Lines | |||||
* BSD-like OS without mkstemp(). It's been modified over the years | * BSD-like OS without mkstemp(). It's been modified over the years | ||||
* to use mkstemp() rather than the original O_CREAT|O_EXCL/fstat/lstat | * to use mkstemp() rather than the original O_CREAT|O_EXCL/fstat/lstat | ||||
* etc style hacks. | * etc style hacks. | ||||
* A cleanup, misc options and mkdtemp() calls were added to try and work | * A cleanup, misc options and mkdtemp() calls were added to try and work | ||||
* more like the OpenBSD version - which was first to publish the interface. | * more like the OpenBSD version - which was first to publish the interface. | ||||
*/ | */ | ||||
#include <err.h> | #include <err.h> | ||||
#include <getopt.h> | |||||
#include <paths.h> | #include <paths.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#ifndef lint | #ifndef lint | ||||
static const char rcsid[] = | static const char rcsid[] = | ||||
"$FreeBSD$"; | "$FreeBSD$"; | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
static void usage(void); | static void usage(void); | ||||
static const struct option long_opts[] = { | |||||
{"directory", no_argument, NULL, 'd'}, | |||||
{"quiet", no_argument, NULL, 'q'}, | |||||
{"dry-run", no_argument, NULL, 'u'}, | |||||
{NULL, no_argument, NULL, 0}, | |||||
}; | |||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
int c, fd, ret; | int c, fd, ret; | ||||
char *tmpdir; | char *tmpdir; | ||||
const char *prefix; | const char *prefix; | ||||
char *name; | char *name; | ||||
int dflag, qflag, tflag, uflag; | int dflag, qflag, tflag, uflag; | ||||
ret = dflag = qflag = tflag = uflag = 0; | ret = dflag = qflag = tflag = uflag = 0; | ||||
prefix = "mktemp"; | prefix = "mktemp"; | ||||
name = NULL; | name = NULL; | ||||
while ((c = getopt(argc, argv, "dqt:u")) != -1) | while ((c = getopt_long(argc, argv, "dqt:u", long_opts, NULL)) != -1) | ||||
switch (c) { | switch (c) { | ||||
case 'd': | case 'd': | ||||
dflag++; | dflag++; | ||||
break; | break; | ||||
case 'q': | case 'q': | ||||
qflag++; | qflag++; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |