#define _FILE_OFFSET_BITS 64
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "write12.h"

int q=0;
int u=0;

int main(int argc,char *argv[]) {
  int i,j;
  if (argc<2) {
    __write1("usage: mktemp [-q] [-u] template\n");
    return 0;
  }
  for (i=1; i<argc; ++i) {
    if (argv[i][0]=='-') {
      for (j=1; argv[i][j]; ++j) {
	switch (argv[i][j]) {
	case 'u': u=1; break;
	case 'q': q=1; break;
	default:
usage:
	  __write1("usage: mktemp [-q] [-u] template\n");
	  return 1;
	}
      }
    } else break;
  }
  if (!argv[i]) goto usage;
  if ((j=mkstemp(argv[i]))==-1) {
    if (!q) __write2("mktemp: mkstemp failed!\n");
    return 1;
  }
  if (u) unlink(argv[i]);
  __write1(argv[i]);
  return 0;
}
