Example #1
0
int my_rmdir (const TCHAR *name)
{
        struct my_opendir_s *od;
        int cnt;
        TCHAR tname[MAX_DPATH];
        memset(tname, 0, sizeof(TCHAR) * MAX_DPATH);

        /* SHFileOperation() ignores FOF_NORECURSION when deleting directories.. */
        od = my_opendir (name);
        if (!od) {
//                SetLastError (ERROR_FILE_NOT_FOUND);
                return -1;
        }
        cnt = 0;
        while (my_readdir (od, tname)) {
                if (!_tcscmp (tname, _T(".")) || !_tcscmp (tname, _T("..")))
                        continue;
                cnt++;
                break;
        }
        my_closedir (od);
        if (cnt > 0) {
//                SetLastError (ERROR_CURRENT_DIRECTORY);
                return -1;
        }

	return rmdir (name);
}
Example #2
0
/** WARNING: mask does *not* work !! */
struct my_opendir_s *my_opendir (const TCHAR *name, const TCHAR *mask) {
  struct my_opendir_s *mod;
  TCHAR tmp[MAX_DPATH];
  unsigned int len=strlen(name);

  DebOut("name: %s, mask: %s\n", name, mask);

  tmp[0] = 0;
#if 0
  if (currprefs.win32_filesystem_mangle_reserved_names == false)
    _tcscpy (tmp, PATHPREFIX);
  _tcscat (tmp, name);
  DebOut("lastchar: %c\n", name[len-1]);
  if(! (name[len-1]=='/' || name[len-1]==':')) {
    _tcscat (tmp, _T("/"));
  }
  _tcscat (tmp, mask);
  DebOut("tmp: %s\n", tmp);
#else
  strcpy(tmp, name);
#endif

  mod = xmalloc (struct my_opendir_s, 1);
  if(!mod) return NULL;

  mod->h=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, TAG_END);
  if(!mod->h) goto ERROR;

  mod->lock=Lock(tmp, ACCESS_READ); /* TODO: ACCESS_READ or ACCESS_WRITE!? */
  if(!mod->lock) {
    DebOut("unable to lock: %s\n", tmp);
    goto ERROR;
  }

  if(!Examine(mod->lock, mod->h)) {
    DebOut("Examine failed!\n");
    goto ERROR;
  }

  if(!(mod->h->fib_DirEntryType > 0 )) {
    DebOut("%s is NOT a directory!\n", tmp);
    goto ERROR;
  }

  DebOut("ok\n");

  return mod;
ERROR:

  my_closedir(mod);
  return NULL;
}
Example #3
0
File: ls.c Project: otto-peep/ft_ls
void	ls_rec(t_mem *s, char *path)
{
	DIR				*rep;
	struct dirent	*fichier;
	t_fil			*list;

	rep = NULL;
	list = NULL;
	if (my_opendir(path, &rep, s) != 0)
	{
		while ((fichier = readdir(rep)) != NULL)
			ft_add_file(s, fichier, path, &list);
		if (my_closedir(path, &rep) != 0)
			ls_rec2(s, &list, path);
	}
}
Example #4
0
File: fsdb.c Project: engur/PUAE
/* Find the name REL in directory DIRNAME.  If we find a file that
 * has exactly the same name, return REL.  If we find a file that
 * has the same name when compared case-insensitively, return a
 * malloced string that contains the name we found.  If no file
 * exists that compares equal to REL, return 0.  */
TCHAR *fsdb_search_dir (const TCHAR *dirname, TCHAR *rel)
{
	TCHAR *p = 0;
	struct dirent *de;
	TCHAR fn[MAX_DPATH];

	struct my_opendir_s *dir = my_opendir (dirname);
	/* This really shouldn't happen...  */
	if (! dir)
		return 0;

	while (p == 0 && (de = my_readdir (dir, fn)) != 0) {
		if (strcmp (de->d_name, rel) == 0)
			p = rel;
		else if (strcasecmp (de->d_name, rel) == 0)
			p = my_strdup (de->d_name);
	}
	my_closedir (dir);
	return p;
}
Example #5
0
/* dirwalk: aplica fcn a todos los archivos de dir */
void dirwalk( char *dir, void (*fcn)(char *) ){
  char name[ MAX_PATH ];
  Dirent *dp;
  myDIR *dfd;

  if( (dfd = my_opendir( dir )) == NULL ){
    fprintf( stderr, "dirwalk: no se puede abrir %s\n", dir );
    return;
  }

  while( (dp = my_readdir( dfd )) != NULL ){
    if( strcmp( dp->name, "." ) == 0 || strcmp( dp->name, ".." ) )
      continue;   /* se ignora a si mismo y a su padre  */
    if( strlen( dir ) + strlen( dp->name ) + 2 > sizeof( name ) )
      fprintf( stderr, "dirwalk: nombre %s %s demasiado largo\n",
               dir, dp->name );
    else {
      sprintf( name, "%s/%s", dir, dp->name );
      (*fcn)( name );
    }
  }

  my_closedir( dfd );
}