~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/SceneManagers/EmberPagingSceneManager/src/filetutils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
*                                                                         *
 
3
*   This program is free software; you can redistribute it and/or modify  *
 
4
*   it under the terms of the GNU Lesser General Public License as        *
 
5
*   published by the Free Software Foundation; either version 2 of the    *
 
6
*   License, or (at your option) any later version.                       *
 
7
*                                                                         *
 
8
***************************************************************************/
 
9
 
 
10
#include "OgrePagingLandScapePrecompiledHeaders.h"
 
11
 
 
12
// #include "OgreNoMemoryMacros.h"
 
13
 
 
14
 
 
15
#include <sys/types.h>
 
16
#include <sys/stat.h>
 
17
 
 
18
#ifdef _WIN32
 
19
#   include <windows.h>
 
20
#   include <direct.h>
 
21
#   include <io.h>
 
22
 
 
23
#   define S_ISDIR(mode) (mode&S_IFDIR)
 
24
#   define STRUCT_STAT  struct _stat
 
25
#   define CHDIR        _chdir
 
26
#   define GETCWD       _getcwd
 
27
#   define MKDIR(A)     _mkdir(A)
 
28
#   define STAT(A,S)    _stat(A,S)
 
29
#else //_LINUX _APPLE
 
30
 
 
31
#ifdef _APPLE
 
32
#   include <malloc/malloc.h>
 
33
#else 
 
34
#   include <stdlib.h>
 
35
#endif
 
36
#   include <unistd.h>
 
37
#   include <sys/param.h>
 
38
 
 
39
#   define MAX_PATH MAXPATHLEN
 
40
#   define STRUCT_STAT  struct stat
 
41
#   define CHDIR        chdir
 
42
#   define GETCWD       getcwd
 
43
#   define MKDIR(A)     mkdir(A, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)// set mode of directory to drwxr-xr-x.
 
44
#   define STAT(A,S)    stat(A,S)
 
45
#endif  //_LINUX _APPLE
 
46
 
 
47
//-----------------------------------------------------------------------
 
48
static char* GetCurrDir()
 
49
{
 
50
    // GETCWD MALLOCS A BUFFER. REMEMBER TO FREE IT.
 
51
    return GETCWD(0,0);;
 
52
}
 
53
 
 
54
#ifdef __cplusplus
 
55
extern "C" { 
 
56
#endif
 
57
 
 
58
//-----------------------------------------------------------------------
 
59
bool DirExists(const char *Dirname)
 
60
{
 
61
    STRUCT_STAT st; 
 
62
 
 
63
    if (STAT(Dirname, &st)) 
 
64
    {
 
65
        // doesn't exist; must create it
 
66
        return false;
 
67
    }
 
68
    if (S_ISDIR(st.st_mode) == 0) 
 
69
    {
 
70
        // it's not a dir, must create a dir        
 
71
        return false;
 
72
    }
 
73
    return true;
 
74
}
 
75
//-----------------------------------------------------------------------
 
76
char * ChangeToDir (const char *Dirname)
 
77
{
 
78
    STRUCT_STAT st;
 
79
 
 
80
    if (STAT(Dirname, &st))
 
81
        {
 
82
        // doen't exist; must create it
 
83
        MKDIR (Dirname);
 
84
        }
 
85
    if (S_ISDIR(st.st_mode) == 0) 
 
86
        {
 
87
        // it's not a dir, must create a dir
 
88
        MKDIR (Dirname);
 
89
        }
 
90
    char *oldDirname = GetCurrDir ();
 
91
    CHDIR(Dirname);
 
92
    return oldDirname;
 
93
}
 
94
 
 
95
 
 
96
void RetablishDir(char *oldDirname)
 
97
{
 
98
    if (oldDirname != NULL) 
 
99
     {
 
100
        ChangeToDir (oldDirname);
 
101
        // FREE MALLOC'ED GETCWD BUFFER.
 
102
        free (oldDirname);
 
103
    }
 
104
}
 
105
 
 
106
#ifdef __cplusplus
 
107
}/* end extern C definitions */ 
 
108
#endif