コード例 #1
0
ファイル: syscall_ex.c プロジェクト: charlestac/smileos
/*********************************************************************************************************
** Function name:           mkdir
** Descriptions:            创建目录
** input parameters:        path                目录路径
**                          mode                模式
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int mkdir(const char *path, mode_t mode)
{
    return _mkdir_r(_REENT, path, mode);
}
コード例 #2
0
ファイル: mktemp.c プロジェクト: Alexpux/Cygwin
static int
_gettemp (struct _reent *ptr,
       char *path,
       register int *doopen,
       int domkdir,
       size_t suffixlen,
       int flags)
{
  register char *start, *trv;
  char *end;
#ifdef __USE_INTERNAL_STAT64
  struct stat64 sbuf;
#else
  struct stat sbuf;
#endif
  unsigned int pid;

  pid = _getpid_r (ptr);
  for (trv = path; *trv; ++trv)		/* extra X's get set to 0's */
    continue;
  if (trv - path < suffixlen)
    {
      ptr->_errno = EINVAL;
      return 0;
    }
  trv -= suffixlen;
  end = trv;
  while (path < trv && *--trv == 'X')
    {
      *trv = (pid % 10) + '0';
      pid /= 10;
    }
  if (end - trv < 6)
    {
      ptr->_errno = EINVAL;
      return 0;
    }

  /*
   * Check the target directory; if you have six X's and it
   * doesn't exist this runs for a *very* long time.
   */

  for (start = trv + 1;; --trv)
    {
      if (trv <= path)
	break;
      if (*trv == '/')
	{
	  *trv = '\0';
#ifdef __USE_INTERNAL_STAT64
	  if (_stat64_r (ptr, path, &sbuf))
#else
	  if (_stat_r (ptr, path, &sbuf))
#endif
	    return (0);
	  if (!(sbuf.st_mode & S_IFDIR))
	    {
	      ptr->_errno = ENOTDIR;
	      return (0);
	    }
	  *trv = '/';
	  break;
	}
    }

  for (;;)
    {
#if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 4
      if (domkdir)
	{
#ifdef HAVE_MKDIR
	  if (_mkdir_r (ptr, path, 0700) == 0)
	    return 1;
	  if (ptr->_errno != EEXIST)
	    return 0;
#else /* !HAVE_MKDIR */
	  ptr->_errno = ENOSYS;
	  return 0;
#endif /* !HAVE_MKDIR */
	}
      else
#endif /* _ELIX_LEVEL */
      if (doopen)
	{
	  if ((*doopen = _open_r (ptr, path, O_CREAT | O_EXCL | O_RDWR | flags,
				  0600)) >= 0)
	    return 1;
	  if (ptr->_errno != EEXIST)
	    return 0;
	}
#ifdef __USE_INTERNAL_STAT64
      else if (_stat64_r (ptr, path, &sbuf))
#else
      else if (_stat_r (ptr, path, &sbuf))
#endif
	return (ptr->_errno == ENOENT ? 1 : 0);

      /* tricky little algorithm for backward compatibility */
      for (trv = start;;)
	{
	  if (trv == end)
	    return 0;
	  if (*trv == 'z')
	    *trv++ = 'a';
	  else
	    {
	      /* Safe, since it only encounters 7-bit characters.  */
	      if (isdigit ((unsigned char) *trv))
		*trv = 'a';
	      else
		++ * trv;
	      break;
	    }
	}
    }
  /*NOTREACHED*/
}