source: abuse/tags/pd/macabuse/imlib/port/dos4gw/jdir.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 874 bytes
Line 
1#include <direct.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include "jmalloc.hpp"
6
7
8void get_directory(char *path, char **&files, int &tfiles, char **&dirs, int &tdirs)
9{
10  struct dirent *de;
11  files=NULL;
12  dirs=NULL;
13  tfiles=0;
14  tdirs=0;
15  DIR *d=opendir(path);
16  if (!d) return ;
17  char curdir[200];
18  getcwd(curdir,200);
19  chdir(path);
20
21  do
22  {
23    de=readdir(d);
24    if (de)
25    {
26      if (de->d_attr&_A_SUBDIR)
27      {     
28        tdirs++;
29        dirs=(char **)jrealloc(dirs,sizeof(char *)*tdirs,"dir list");
30        dirs[tdirs-1]=strcpy((char *)jmalloc(strlen(de->d_name)+1,"tmp file name"),de->d_name);
31      } else
32      {
33        tfiles++;
34        files=(char **)jrealloc(files,sizeof(char *)*tfiles,"dir list");
35        files[tfiles-1]=strcpy((char *)jmalloc(strlen(de->d_name)+1,"tmp file name"),de->d_name);
36      }
37    }
38  } while (de);
39  closedir(d);
40  chdir(curdir);
41}
42
43
44
Note: See TracBrowser for help on using the repository browser.