source: abuse/trunk/src/sdlport/jdir.cpp

Last change on this file was 555, checked in by Sam Hocevar, 12 years ago

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

File size: 2.2 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This program is free software; you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation; either version 2 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program; if not, write to the Free Software Foundation,
18 *  Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 */
20
[555]21#if defined HAVE_CONFIG_H
22#   include "config.h"
23#endif
[56]24
[2]25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
[131]28
29#include <sys/types.h>
30#include <dirent.h>
[2]31#include <unistd.h>
[56]32
[2]33void get_directory(char *path, char **&files, int &tfiles, char **&dirs, int &tdirs)
34{
[124]35    struct dirent *de;
36    files = NULL;
37    dirs = NULL;
38    tfiles = 0;
39    tdirs = 0;
40    DIR *d = opendir( path );
[2]41
[124]42    if( !d )
43        return;
[2]44
[124]45    char **tlist = NULL;
46    int t = 0;
47    char curdir[200];
48    getcwd( curdir, 200 );
49    chdir( path );
[2]50
[124]51    do
52    {
53        de = readdir( d );
54        if( de )
55        {
56            t++;
[129]57            tlist = (char **)realloc(tlist,sizeof(char *)*t);
[131]58            tlist[t-1] = strdup(de->d_name);
[124]59        }
60    } while( de );
61    closedir( d );
[2]62
[124]63    for( int i=0; i < t; i++ )
64    {
65        d = opendir( tlist[i] );
66        if( d )
67        {
68            tdirs++;
[129]69            dirs = (char **)realloc(dirs,sizeof(char *)*tdirs);
[131]70            dirs[tdirs-1] = strdup(tlist[i]);
[124]71            closedir( d );
72        }
73        else
74        {
75            tfiles++;
[129]76            files = (char **)realloc(files,sizeof(char *)*tfiles);
[131]77            files[tfiles-1] = strdup(tlist[i]);
[124]78        }
[129]79        free( tlist[i] );
[124]80    }
81    if( t )
[129]82        free( tlist );
[124]83    chdir( curdir );
[2]84}
Note: See TracBrowser for help on using the repository browser.