Blender V2.61 - r43446

GHOST_SystemPathsX11.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2010 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Blender Foundation
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00032 #include "GHOST_SystemPathsX11.h"
00033 
00034 #include "GHOST_Debug.h"
00035 
00036 // For timing
00037 
00038 #include <sys/time.h>
00039 #include <unistd.h>
00040 
00041 #include <stdio.h> // for fprintf only
00042 #include <cstdlib> // for exit
00043 
00044 #ifdef WITH_XDG_USER_DIRS
00045 #  include <pwd.h> // for get home without use getenv()
00046 #  include <limits.h> // for PATH_MAX
00047 #endif
00048 
00049 #ifdef PREFIX
00050 static const char *static_path= PREFIX "/share" ;
00051 #else
00052 static const char *static_path= NULL;
00053 #endif
00054 
00055 GHOST_SystemPathsX11::GHOST_SystemPathsX11()
00056 {
00057 }
00058 
00059 GHOST_SystemPathsX11::~GHOST_SystemPathsX11()
00060 {
00061 }
00062 
00063 const GHOST_TUns8* GHOST_SystemPathsX11::getSystemDir() const
00064 {
00065     /* no prefix assumes a portable build which only uses bundled scripts */
00066     return (const GHOST_TUns8 *)static_path;
00067 }
00068 
00069 const GHOST_TUns8* GHOST_SystemPathsX11::getUserDir() const
00070 {
00071 #ifndef WITH_XDG_USER_DIRS
00072     return (const GHOST_TUns8 *)getenv("HOME");
00073 #else /* WITH_XDG_USER_DIRS */
00074     const char *home= getenv("XDG_CONFIG_HOME");
00075 
00076     if (home) {
00077         return (const GHOST_TUns8 *)home;
00078     }
00079     else {
00080         static char user_path[PATH_MAX];
00081 
00082         home= getenv("HOME");
00083 
00084         if (home == NULL) {
00085             home= getpwuid(getuid())->pw_dir;
00086         }
00087 
00088         snprintf(user_path, sizeof(user_path), "%s/.config", home);
00089         return (const GHOST_TUns8 *)user_path;
00090     }
00091 #endif /* WITH_XDG_USER_DIRS */
00092 }
00093 
00094 const GHOST_TUns8* GHOST_SystemPathsX11::getBinaryDir() const
00095 {
00096     return NULL;
00097 }
00098 
00099 void GHOST_SystemPathsX11::addToSystemRecentFiles(const char* filename) const
00100 {
00101     /* XXXXX TODO: Implementation for X11 if possible */
00102 
00103 }