static int number_of_file(char *path)
{
	int count = 0;
#ifdef WIN32
	struct _wdirent *entry;
	_WDIR *dirp = (_WDIR *)subsurface_opendir(path);
#else
	struct dirent *entry;
	DIR *dirp = (DIR *)subsurface_opendir(path);
#endif

	while (dirp) {
#ifdef WIN32
		entry = _wreaddir(dirp);
		if (!entry)
			break;
#else
		entry = readdir(dirp);
		if (!entry)
			break;
		if (entry->d_type == DT_REG) /* If the entry is a regular file */
#endif
		count++;
	}
#ifdef WIN32
	_wclosedir(dirp);
#else
	closedir(dirp);
#endif
	return count;
}
Exemple #2
0
void *vlc_opendir_wrapper( const char *psz_path )
{
    vlc_DIR *p_dir = NULL;
    DIR *p_real_dir = NULL;

    if ( psz_path == NULL || psz_path[0] == '\0'
          || (psz_path[0] == '\\' && psz_path[1] == '\0') )
    {
        /* Special mode to list drive letters */
        p_dir = malloc( sizeof(vlc_DIR) );
        if( !p_dir )
            return NULL;
        p_dir->p_real_dir = NULL;
        p_dir->i_drives = GetLogicalDrives();
        return (void *)p_dir;
    }

    p_real_dir = opendir( psz_path );
    if ( p_real_dir == NULL )
        return NULL;

    p_dir = malloc( sizeof(vlc_DIR) );
    if( !p_dir )
    {
        _wclosedir( p_real_dir );
        return NULL;
    }
    p_dir->p_real_dir = p_real_dir;
    p_dir->b_insert_back = ( psz_path[1] == ':' && psz_path[2] == '\\'
                              && psz_path[3] =='\0' );
    return (void *)p_dir;
}
int win_closedir(UNFS3_WIN_DIR * dir)
{
    if (dir->stream == NULL) {
	free(dir);
	return 0;
    } else {
	return _wclosedir(dir->stream);
    }
}
Exemple #4
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;
}
Exemple #5
0
/**
 * g_dir_close:
 * @dir: a #GDir* created by g_dir_open()
 *
 * Closes the directory and deallocates all related resources.
 **/
void
g_dir_close (GDir *dir)
{
  g_return_if_fail (dir != NULL);

#ifdef G_OS_WIN32
  _wclosedir (dir->wdirp);
#else
  closedir (dir->dirp);
#endif
  g_free (dir);
}
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);
	}
Exemple #7
0
/**
 * @brief Close a directory
 */
int _win_closedir(DIR *dirp)
{
  /* closedir sets errno */
  if (plibc_utf8_mode() == 1)
  {
    struct plibc_WDIR *pwd;
    int result;
    pwd = (struct plibc_WDIR *) dirp;
    if (pwd->self != pwd)
    {
      errno = EINVAL;
      return -1;
    }
    result = _wclosedir(pwd->mingw_wdir);
    free (pwd);
    return result;
  }
  else
    return closedir(dirp);
}
Exemple #8
0
int closedir(DIR* dirp)
{
	int ok;
	if (dirp) {

		/* Close wide-character directory stream */
		ok = _wclosedir(dirp->wdirp);
		dirp->wdirp = NULL;

		/* Release multi-byte character version */
		free(dirp);

	}
	else {

		/* Invalid directory stream */
		dirent_set_errno(EBADF);
		ok = /*failure*/-1;

	}
	return ok;
}
Exemple #9
0
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;
  }
Exemple #10
0
__int64
lisp_closedir(_WDIR *dir)
{
  return _wclosedir(dir);
}
Exemple #11
0
_WDIR* _wopendir(const wchar_t* dirname)
{
	_WDIR *dirp = NULL;
	int error;

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

	/* Allocate new _WDIR structure */
	dirp = (_WDIR*)malloc(sizeof(struct _WDIR));
	if (dirp != NULL) {
		DWORD n;

		/* Reset _WDIR structure */
		dirp->handle = INVALID_HANDLE_VALUE;
		dirp->patt = NULL;
		dirp->cached = 0;

		/* Compute the length of full path plus zero terminator */
		n = GetFullPathNameW(dirname, 0, NULL, NULL);

		/* Allocate room for absolute directory name and search pattern */
		dirp->patt = (wchar_t*)malloc(sizeof(wchar_t) * n + 16);
		if (dirp->patt) {

			/*
			* Convert relative directory name to an absolute one.  This
			* allows rewinddir() to function correctly even when current
			* working directory is changed between opendir() and rewinddir().
			*/
			n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
			if (n > 0) {
				wchar_t *p;

				/* Append search pattern \* to the directory name */
				p = dirp->patt + n;
				if (dirp->patt < p) {
					switch (p[-1]) {
					case '\\':
					case '/':
					case ':':
						/* Directory ends in path separator, e.g. c:\temp\ */
						/*NOP*/;
						break;

					default:
						/* Directory name doesn't end in path separator */
						*p++ = '\\';
					}
				}
				*p++ = '*';
				*p = '\0';

				/* Open directory stream and retrieve the first entry */
				if (dirent_first(dirp)) {
					/* Directory stream opened successfully */
					error = 0;
				}
				else {
					/* Cannot retrieve first entry */
					error = 1;
					dirent_set_errno(ENOENT);
				}

			}
			else {
				/* Cannot retrieve full path name */
				dirent_set_errno(ENOENT);
				error = 1;
			}

		}
		else {
			/* Cannot allocate memory for search pattern */
			error = 1;
		}

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

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

	return dirp;
}
Exemple #12
0
int closedir_( int dir ){
	if( _bbusew ) return _wclosedir( (_WDIR*)dir );
	return closedir( (DIR*)dir );
}