コード例 #1
0
int
mkstemps(char *__template, int suffixlen)
{
   char      *suffix;
   DWORD      val;
   size_t     length;
   int        i;

   if (!__template || (suffixlen < 0))
     return 0;

   if (!_mkstemp_init(__template, &suffix, &length, &val, (size_t) suffixlen))
     return -1;

   for (i = 0; i < 32768; i++)
     {
        int fd;

        val = _mkstemp(suffix, val);

        fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
        if (fd >= 0)
          return fd;
     }

   errno = EEXIST;
   return -1;
}
コード例 #2
0
int
mkstemp(char *__template)
{
   char      *suffix;
   DWORD      val;
   size_t     length;
   int        i;

   if (!__template)
     return 0;

   if (!_mkstemp_init(__template, &suffix, &length, &val))
     return -1;

   for (i = 0; i < 32768; i++)
     {
        int fd;

        val = _mkstemp(suffix, val);

#ifndef __MINGW32CE__
        fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
#else /* ! __MINGW32CE__ */
        {
           FILE    *f;
           wchar_t *wtemplate;

           wtemplate = evil_char_to_wchar(__template);
           if (!wtemplate)
             return -1;
           f = _wfopen(wtemplate, L"rwb");
           free(wtemplate);
           if (!f)
             {
                errno = EEXIST;
                return -1;
             }
           fd = (int)_fileno(f);
        }
#endif /* __MINGW32CE__ */
        if (fd >= 0)
          return fd;
     }

   errno = EEXIST;
   return -1;
}
コード例 #3
0
EAPI char *
mkdtemp(char *__template)
{
   char      *suffix;
   DWORD      val;
   size_t     length;
   int        i;

   if (!__template)
     {
        errno = EINVAL;
	return NULL;
     }

   if (!_mkstemp_init(__template, &suffix, &length, &val))
     return NULL;

   for (i = 0; i < 32768; i++)
     {
        val = _mkstemp(suffix, val);

	if (mkdir(__template))
	  return __template;

	if (errno == EFAULT ||
	    errno == ENOSPC ||
	    errno == ENOMEM ||
	    errno == ENOENT ||
	    errno == ENOTDIR ||
	    errno == EPERM ||
	    errno == EROFS)
	  return NULL;
     }

   errno = EEXIST;
   return NULL;
}