示例#1
0
DIR *vlc_opendir (const char *dirname)
{
    wchar_t *wpath = widen_path (dirname);
    if (wpath == NULL)
        return NULL;

    vlc_DIR *p_dir = malloc (sizeof (*p_dir));
    if (unlikely(p_dir == NULL))
    {
        free(wpath);
        return NULL;
    }

    if (wpath[0] == L'\0' || (wcscmp (wpath, L"\\") == 0))
    {
        free (wpath);
        /* Special mode to list drive letters */
        p_dir->wdir = NULL;
        p_dir->u.drives = GetLogicalDrives ();
        return (void *)p_dir;
    }

    assert (wpath[0]); // wpath[1] is defined
    p_dir->u.insert_dot_dot = !wcscmp (wpath + 1, L":\\");

    _WDIR *wdir = _wopendir (wpath);
    free (wpath);
    if (wdir == NULL)
    {
        free (p_dir);
        return NULL;
    }
    p_dir->wdir = wdir;
    return (void *)p_dir;
}
/*
  opendir implementation which emulates a virtual root with the drive
  letters presented as directories. 
*/
UNFS3_WIN_DIR *win_opendir(const char *name)
{
    wchar_t *winpath;
    UNFS3_WIN_DIR *ret;

    ret = malloc(sizeof(UNFS3_WIN_DIR));
    if (!ret) {
	logmsg(LOG_CRIT, "win_opendir: Unable to allocate memory");
	return NULL;
    }

    if (!strcmp("/", name)) {
	/* Emulate root */
	ret->stream = NULL;
	ret->currentdrive = 0;
	ret->logdrives = GetLogicalDrives();
    } else {
	winpath = intpath2winpath(name);
	if (!winpath) {
	    free(ret);
	    errno = EINVAL;
	    return NULL;
	}

	ret->stream = _wopendir(winpath);
	free(winpath);
	if (ret->stream == NULL) {
	    free(ret);
	    ret = NULL;
	}
    }

    return ret;
}
示例#3
0
/*< private >
 * g_dir_open_with_errno:
 * @path: the path to the directory you are interested in.
 * @flags: Currently must be set to 0. Reserved for future use.
 *
 * Opens a directory for reading.
 *
 * This function is equivalent to g_dir_open() except in the error case,
 * errno will be set accordingly.
 *
 * This is useful if you want to construct your own error message.
 *
 * Returns: a newly allocated #GDir on success, or %NULL on failure,
 *   with errno set accordingly.
 *
 * Since: 2.38
 */
GDir *
g_dir_open_with_errno (const gchar *path,
                       guint        flags)
{
  GDir dir;
#ifdef G_OS_WIN32
  gint saved_errno;
  wchar_t *wpath;
#endif

  g_return_val_if_fail (path != NULL, NULL);

#ifdef G_OS_WIN32
  wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);

  g_return_val_if_fail (wpath != NULL, NULL);

  dir.wdirp = _wopendir (wpath);
  saved_errno = errno;
  g_free (wpath);
  errno = saved_errno;

  if (dir.wdirp == NULL)
    return NULL;
#else
  dir.dirp = opendir (path);

  if (dir.dirp == NULL)
    return NULL;
#endif

  return g_memdup (&dir, sizeof dir);
}
示例#4
0
文件: dirent.c 项目: andry-tino/phash
DIR* opendir(const char* dirname)
{
	struct DIR *dirp;
	int error;

	/* Must have directory name */
	if (dirname == NULL || dirname[0] == '\0') {
		dirent_set_errno(ENOENT);
		return NULL;
	}

	/* Allocate memory for DIR structure */
	dirp = (DIR*)malloc(sizeof(struct DIR));
	if (dirp) {
		wchar_t wname[PATH_MAX];
		size_t n;

		/* Convert directory name to wide-character string */
		error = dirent_mbstowcs_s(&n, wname, PATH_MAX, dirname, PATH_MAX);
		if (!error) {

			/* Open directory stream using wide-character name */
			dirp->wdirp = _wopendir(wname);
			if (dirp->wdirp) {
				/* Directory stream opened */
				error = 0;
			}
			else {
				/* Failed to open directory stream */
				error = 1;
			}

		}
		else {
			/*
			* Cannot convert file name to wide-character string.  This
			* occurs if the string contains invalid multi-byte sequences or
			* the output buffer is too small to contain the resulting
			* string.
			*/
			error = 1;
		}

	}
	else {
		/* Cannot allocate DIR structure */
		error = 1;
	}

	/* Clean up in case of error */
	if (error  &&  dirp) {
		free(dirp);
		dirp = NULL;
	}

	return dirp;
}
示例#5
0
/* here we return a void pointer instead of _WDIR or DIR pointer */
void *subsurface_opendir(const char *path)
{
	_WDIR *ret = NULL;
	if (!path)
		return ret;
	wchar_t *wpath = utf8_to_utf16(path);
	if (wpath)
		ret = _wopendir(wpath);
	free((void *)wpath);
	return (void *)ret;
}
示例#6
0
int main(int argc, char **argv)
{
    struct _wdirent *di;
    _WDIR *h = _wopendir (L".");
    if (!h)
        return 1;
    while ((di = _wreaddir (h)) != NULL)
        printf ("%ws\n", di->d_name);
    _wclosedir (h);
    return 0;
}
示例#7
0
void GetDirContents(const std::wstring& path, 
					std::list<std::wstring>& contents)
	{
	_WDIR* currDir =  _wopendir(path.c_str());
	if(currDir == NULL)
		{
		return;
		}
	
	_wdirent* currElem = _wreaddir(currDir);
	
	while (currElem)
		{
		contents.push_back(currElem->d_name);
		currElem = _wreaddir(currDir);
		}
	_wclosedir(currDir);
	}
示例#8
0
文件: savedialog.cpp 项目: Try/game
std::vector<std::wstring> SaveDialog::filesInDir( const std::wstring &dirName ){
  std::vector<std::wstring> vec;
  (void)dirName;

#ifndef __ANDROID__
  _WDIR *dir = _wopendir ( dirName.c_str() );//data->curDir;
  struct _wdirent *ent;
  
  //dir = _wopendir ( dirName.c_str() );
  if (dir != NULL) {
    /* print all the files and directories within directory */
    while ((ent = _wreaddir (dir)) != NULL) {
      vec.push_back( ent->d_name );
      }
    _wclosedir (dir);
    } else {
    //return EXIT_FAILURE;
    }
#endif

  return vec;
  }
示例#9
0
_WDIR *
lisp_opendir(wchar_t *path)
{
  return _wopendir(path);
}
示例#10
0
/**
 * g_dir_open:
 * @path: the path to the directory you are interested in. On Unix
 *         in the on-disk encoding. On Windows in UTF-8
 * @flags: Currently must be set to 0. Reserved for future use.
 * @error: return location for a #GError, or %NULL.
 *         If non-%NULL, an error will be set if and only if
 *         g_dir_open() fails.
 *
 * Opens a directory for reading. The names of the files in the
 * directory can then be retrieved using g_dir_read_name().
 *
 * Return value: a newly allocated #GDir on success, %NULL on failure.
 *   If non-%NULL, you must free the result with g_dir_close()
 *   when you are finished with it.
 **/
GDir *
g_dir_open (const gchar  *path,
            guint         flags,
            GError      **error)
{
  GDir *dir;
#ifdef G_OS_WIN32
  wchar_t *wpath;
#else
  gchar *utf8_path;
#endif

  g_return_val_if_fail (path != NULL, NULL);

#ifdef G_OS_WIN32
  wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, error);

  if (wpath == NULL)
    return NULL;

  dir = g_new (GDir, 1);

  dir->wdirp = _wopendir (wpath);
  g_free (wpath);

  if (dir->wdirp)
    return dir;

  /* error case */

  g_set_error (error,
	       G_FILE_ERROR,
	       g_file_error_from_errno (errno),
	       _("Error opening directory '%s': %s"),
	       path, g_strerror (errno));
  
  g_free (dir);
      
  return NULL;
#else
  dir = g_new (GDir, 1);

  dir->dirp = opendir (path);

  if (dir->dirp)
    return dir;

  /* error case */
  utf8_path = g_filename_to_utf8 (path, -1,
				  NULL, NULL, NULL);
  g_set_error (error,
               G_FILE_ERROR,
               g_file_error_from_errno (errno),
               _("Error opening directory '%s': %s"),
	       utf8_path, g_strerror (errno));

  g_free (utf8_path);
  g_free (dir);

  return NULL;
#endif
}
示例#11
0
int opendir_( BBString *path ){
	if( _bbusew ) return (int)_wopendir( bbTmpWString(path) );
	return (int)opendir( bbTmpCString(path) );
}