Blame gl/mkstemps.c

Packit a4aae4
/* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2017 Free Software
Packit a4aae4
   Foundation, Inc.
Packit a4aae4
   This file is derived from the one in the GNU C Library.
Packit a4aae4
Packit a4aae4
   This program is free software: you can redistribute it and/or modify
Packit a4aae4
   it under the terms of the GNU Lesser General Public License as published by
Packit a4aae4
   the Free Software Foundation; either version 3 of the License, or
Packit a4aae4
   (at your option) any later version.
Packit a4aae4
Packit a4aae4
   This program is distributed in the hope that it will be useful,
Packit a4aae4
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit a4aae4
   GNU Lesser General Public License for more details.
Packit a4aae4
Packit a4aae4
   You should have received a copy of the GNU Lesser General Public License
Packit a4aae4
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit a4aae4
Packit a4aae4
#if !_LIBC
Packit a4aae4
# include <config.h>
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#include <stdlib.h>
Packit a4aae4
Packit a4aae4
#if !_LIBC
Packit a4aae4
# include <errno.h>
Packit a4aae4
# include "tempname.h"
Packit a4aae4
# define __gen_tempname gen_tempname
Packit a4aae4
# ifndef __GT_FILE
Packit a4aae4
#  define __GT_FILE GT_FILE
Packit a4aae4
# endif
Packit a4aae4
# define __set_errno(x) errno = x;
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#include <stdio.h>
Packit a4aae4
Packit a4aae4
#ifndef __GT_FILE
Packit a4aae4
# define __GT_FILE 0
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
/* Generate a unique temporary file name from XTEMPLATE.  The last six
Packit a4aae4
   characters before a suffix of length SUFFIXLEN of XTEMPLATE must be
Packit a4aae4
   "XXXXXX"; they are replaced with a string that makes the filename
Packit a4aae4
   unique.  Then open the file and return a fd. */
Packit a4aae4
int
Packit a4aae4
mkstemps (char *xtemplate, int suffixlen)
Packit a4aae4
{
Packit a4aae4
  if (suffixlen < 0)
Packit a4aae4
    {
Packit a4aae4
      __set_errno (EINVAL);
Packit a4aae4
      return -1;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
  return __gen_tempname (xtemplate, suffixlen, 0, __GT_FILE);
Packit a4aae4
}