示例#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
static int
check_fsid (uid_t uid, gid_t gid)
{
    int fd;
    char path[] = "/tmp/testfsuidsupp.XXXXXX";
    struct stat sb;

    fd = _mkstemp (path);
    _fstat (fd, &sb);
    _unlink (path);

    return (sb.st_uid == uid && sb.st_gid == gid);
}
示例#3
0
/* Create a test file and return its path.
 */
static char *
create_file (uid_t uid, gid_t gid, mode_t mode)
{
    int fd;
    static char path[] = "/tmp/testfsuidsupp.XXXXXX";

    fd = _mkstemp (path);
    _fchown (fd, 0, TEST_SGID);
    _fchmod (fd, 0040);

    msg ("file created %d:%d mode 0%o", uid, gid, mode);

    return path;
}
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;
}
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;
}