Remove useless test before freeing something.
[vlc/pdherbemont.git] / src / config / core.c
blob3b8d91c33c4a7cf21444a14b1c9e5080216d7bda
1 /*****************************************************************************
2 * core.c management of the modules configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2007 the VideoLAN team
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc/vlc.h>
29 #include "../libvlc.h"
30 #include "vlc_keys.h"
31 #include "vlc_charset.h"
32 #include "vlc_configuration.h"
34 #include <errno.h> /* errno */
35 #include <assert.h>
36 #include <limits.h>
38 #ifdef HAVE_UNISTD_H
39 # include <unistd.h> /* getuid() */
40 #endif
42 #if defined(HAVE_GETPWUID)
43 # include <pwd.h> /* getpwuid() */
44 #endif
46 #if defined( HAVE_SYS_STAT_H )
47 # include <sys/stat.h>
48 #endif
49 #if defined( HAVE_SYS_TYPES_H )
50 # include <sys/types.h>
51 #endif
52 #if defined( WIN32 )
53 # if !defined( UNDER_CE )
54 # include <direct.h>
55 # endif
56 #include <tchar.h>
57 #endif
59 #include "configuration.h"
60 #include "modules/modules.h"
62 static inline char *strdupnull (const char *src)
64 return src ? strdup (src) : NULL;
67 /* Item types that use a string value (i.e. serialized in the module cache) */
68 int IsConfigStringType (int type)
70 static const unsigned char config_types[] =
72 CONFIG_ITEM_STRING, CONFIG_ITEM_FILE, CONFIG_ITEM_MODULE,
73 CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_MODULE_CAT, CONFIG_ITEM_PASSWORD,
74 CONFIG_ITEM_MODULE_LIST, CONFIG_ITEM_MODULE_LIST_CAT
77 /* NOTE: this needs to be changed if we ever get more than 255 types */
78 return memchr (config_types, type, sizeof (config_types)) != NULL;
82 int IsConfigIntegerType (int type)
84 static const unsigned char config_types[] =
86 CONFIG_ITEM_INTEGER, CONFIG_ITEM_KEY, CONFIG_ITEM_BOOL,
87 CONFIG_CATEGORY, CONFIG_SUBCATEGORY
90 return memchr (config_types, type, sizeof (config_types)) != NULL;
94 /*****************************************************************************
95 * config_GetType: get the type of a variable (bool, int, float, string)
96 *****************************************************************************
97 * This function is used to get the type of a variable from its name.
98 * Beware, this is quite slow.
99 *****************************************************************************/
100 int __config_GetType( vlc_object_t *p_this, const char *psz_name )
102 module_config_t *p_config;
103 int i_type;
105 p_config = config_FindConfig( p_this, psz_name );
107 /* sanity checks */
108 if( !p_config )
110 return 0;
113 switch( p_config->i_type )
115 case CONFIG_ITEM_BOOL:
116 i_type = VLC_VAR_BOOL;
117 break;
119 case CONFIG_ITEM_INTEGER:
120 case CONFIG_ITEM_KEY:
121 i_type = VLC_VAR_INTEGER;
122 break;
124 case CONFIG_ITEM_FLOAT:
125 i_type = VLC_VAR_FLOAT;
126 break;
128 case CONFIG_ITEM_MODULE:
129 case CONFIG_ITEM_MODULE_CAT:
130 case CONFIG_ITEM_MODULE_LIST:
131 case CONFIG_ITEM_MODULE_LIST_CAT:
132 i_type = VLC_VAR_MODULE;
133 break;
135 case CONFIG_ITEM_STRING:
136 i_type = VLC_VAR_STRING;
137 break;
139 case CONFIG_ITEM_PASSWORD:
140 i_type = VLC_VAR_STRING;
141 break;
143 case CONFIG_ITEM_FILE:
144 i_type = VLC_VAR_FILE;
145 break;
147 case CONFIG_ITEM_DIRECTORY:
148 i_type = VLC_VAR_DIRECTORY;
149 break;
151 default:
152 i_type = 0;
153 break;
156 return i_type;
159 /*****************************************************************************
160 * config_GetInt: get the value of an int variable
161 *****************************************************************************
162 * This function is used to get the value of variables which are internally
163 * represented by an integer (CONFIG_ITEM_INTEGER and
164 * CONFIG_ITEM_BOOL).
165 *****************************************************************************/
166 int __config_GetInt( vlc_object_t *p_this, const char *psz_name )
168 module_config_t *p_config;
170 p_config = config_FindConfig( p_this, psz_name );
172 /* sanity checks */
173 if( !p_config )
175 msg_Err( p_this, "option %s does not exist", psz_name );
176 return -1;
179 if (!IsConfigIntegerType (p_config->i_type))
181 msg_Err( p_this, "option %s does not refer to an int", psz_name );
182 return -1;
185 return p_config->value.i;
188 /*****************************************************************************
189 * config_GetFloat: get the value of a float variable
190 *****************************************************************************
191 * This function is used to get the value of variables which are internally
192 * represented by a float (CONFIG_ITEM_FLOAT).
193 *****************************************************************************/
194 float __config_GetFloat( vlc_object_t *p_this, const char *psz_name )
196 module_config_t *p_config;
198 p_config = config_FindConfig( p_this, psz_name );
200 /* sanity checks */
201 if( !p_config )
203 msg_Err( p_this, "option %s does not exist", psz_name );
204 return -1;
207 if (!IsConfigFloatType (p_config->i_type))
209 msg_Err( p_this, "option %s does not refer to a float", psz_name );
210 return -1;
213 return p_config->value.f;
216 /*****************************************************************************
217 * config_GetPsz: get the string value of a string variable
218 *****************************************************************************
219 * This function is used to get the value of variables which are internally
220 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
221 * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE).
223 * Important note: remember to free() the returned char* because it's a
224 * duplicate of the actual value. It isn't safe to return a pointer to the
225 * actual value as it can be modified at any time.
226 *****************************************************************************/
227 char * __config_GetPsz( vlc_object_t *p_this, const char *psz_name )
229 module_config_t *p_config;
231 p_config = config_FindConfig( p_this, psz_name );
233 /* sanity checks */
234 if( !p_config )
236 msg_Err( p_this, "option %s does not exist", psz_name );
237 return NULL;
240 if (!IsConfigStringType (p_config->i_type))
242 msg_Err( p_this, "option %s does not refer to a string", psz_name );
243 return NULL;
246 /* return a copy of the string */
247 vlc_mutex_lock( p_config->p_lock );
248 char *psz_value = strdupnull (p_config->value.psz);
249 vlc_mutex_unlock( p_config->p_lock );
251 return psz_value;
254 /*****************************************************************************
255 * config_PutPsz: set the string value of a string variable
256 *****************************************************************************
257 * This function is used to set the value of variables which are internally
258 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
259 * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE).
260 *****************************************************************************/
261 void __config_PutPsz( vlc_object_t *p_this,
262 const char *psz_name, const char *psz_value )
264 module_config_t *p_config;
265 vlc_value_t oldval, val;
267 p_config = config_FindConfig( p_this, psz_name );
270 /* sanity checks */
271 if( !p_config )
273 msg_Warn( p_this, "option %s does not exist", psz_name );
274 return;
277 if (!IsConfigStringType (p_config->i_type))
279 msg_Err( p_this, "option %s does not refer to a string", psz_name );
280 return;
283 vlc_mutex_lock( p_config->p_lock );
285 /* backup old value */
286 oldval.psz_string = (char *)p_config->value.psz;
288 if ((psz_value != NULL) && *psz_value)
289 p_config->value.psz = strdup (psz_value);
290 else
291 p_config->value.psz = NULL;
293 p_config->b_dirty = VLC_TRUE;
295 val.psz_string = (char *)p_config->value.psz;
297 vlc_mutex_unlock( p_config->p_lock );
299 if( p_config->pf_callback )
301 p_config->pf_callback( p_this, psz_name, oldval, val,
302 p_config->p_callback_data );
305 /* free old string */
306 free( oldval.psz_string );
309 /*****************************************************************************
310 * config_PutInt: set the integer value of an int variable
311 *****************************************************************************
312 * This function is used to set the value of variables which are internally
313 * represented by an integer (CONFIG_ITEM_INTEGER and
314 * CONFIG_ITEM_BOOL).
315 *****************************************************************************/
316 void __config_PutInt( vlc_object_t *p_this, const char *psz_name, int i_value )
318 module_config_t *p_config;
319 vlc_value_t oldval, val;
321 p_config = config_FindConfig( p_this, psz_name );
323 /* sanity checks */
324 if( !p_config )
326 msg_Warn( p_this, "option %s does not exist", psz_name );
327 return;
330 if (!IsConfigIntegerType (p_config->i_type))
332 msg_Err( p_this, "option %s does not refer to an int", psz_name );
333 return;
336 /* backup old value */
337 oldval.i_int = p_config->value.i;
339 /* if i_min == i_max == 0, then do not use them */
340 if ((p_config->min.i == 0) && (p_config->max.i == 0))
342 p_config->value.i = i_value;
344 else if (i_value < p_config->min.i)
346 p_config->value.i = p_config->min.i;
348 else if (i_value > p_config->max.i)
350 p_config->value.i = p_config->max.i;
352 else
354 p_config->value.i = i_value;
357 p_config->b_dirty = VLC_TRUE;
359 val.i_int = p_config->value.i;
361 if( p_config->pf_callback )
363 p_config->pf_callback( p_this, psz_name, oldval, val,
364 p_config->p_callback_data );
368 /*****************************************************************************
369 * config_PutFloat: set the value of a float variable
370 *****************************************************************************
371 * This function is used to set the value of variables which are internally
372 * represented by a float (CONFIG_ITEM_FLOAT).
373 *****************************************************************************/
374 void __config_PutFloat( vlc_object_t *p_this,
375 const char *psz_name, float f_value )
377 module_config_t *p_config;
378 vlc_value_t oldval, val;
380 p_config = config_FindConfig( p_this, psz_name );
382 /* sanity checks */
383 if( !p_config )
385 msg_Warn( p_this, "option %s does not exist", psz_name );
386 return;
389 if (!IsConfigFloatType (p_config->i_type))
391 msg_Err( p_this, "option %s does not refer to a float", psz_name );
392 return;
395 /* backup old value */
396 oldval.f_float = p_config->value.f;
398 /* if f_min == f_max == 0, then do not use them */
399 if ((p_config->min.f == 0) && (p_config->max.f == 0))
401 p_config->value.f = f_value;
403 else if (f_value < p_config->min.f)
405 p_config->value.f = p_config->min.f;
407 else if (f_value > p_config->max.f)
409 p_config->value.f = p_config->max.f;
411 else
413 p_config->value.f = f_value;
416 p_config->b_dirty = VLC_TRUE;
418 val.f_float = p_config->value.f;
420 if( p_config->pf_callback )
422 p_config->pf_callback( p_this, psz_name, oldval, val,
423 p_config->p_callback_data );
427 /*****************************************************************************
428 * config_FindConfig: find the config structure associated with an option.
429 *****************************************************************************
430 * FIXME: This function really needs to be optimized.
431 * FIXME: And now even more.
432 *****************************************************************************/
433 module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
435 vlc_list_t *p_list;
436 int i_index;
438 if( !psz_name ) return NULL;
440 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
442 for( i_index = 0; i_index < p_list->i_count; i_index++ )
444 module_config_t *p_item, *p_end;
445 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
447 if( !p_parser->i_config_items )
448 continue;
450 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
451 p_item < p_end;
452 p_item++ )
454 if( p_item->i_type & CONFIG_HINT )
455 /* ignore hints */
456 continue;
457 if( !strcmp( psz_name, p_item->psz_name )
458 || ( p_item->psz_oldname
459 && !strcmp( psz_name, p_item->psz_oldname ) ) )
461 vlc_list_release( p_list );
462 return p_item;
467 vlc_list_release( p_list );
469 return NULL;
472 /*****************************************************************************
473 * config_Free: frees a duplicated module's configuration data.
474 *****************************************************************************
475 * This function frees all the data duplicated by config_Duplicate.
476 *****************************************************************************/
477 void config_Free( module_t *p_module )
479 int i;
481 for (size_t j = 0; j < p_module->confsize; j++)
483 module_config_t *p_item = p_module->p_config + j;
485 free( p_item->psz_type );
486 free( p_item->psz_name );
487 free( p_item->psz_text );
488 free( p_item->psz_longtext );
489 free( p_item->psz_oldname );
491 if (IsConfigStringType (p_item->i_type))
493 free (p_item->value.psz);
494 free (p_item->orig.psz);
495 free (p_item->saved.psz);
498 if( p_item->ppsz_list )
499 for( i = 0; i < p_item->i_list; i++ )
500 free( p_item->ppsz_list[i] );
501 if( p_item->ppsz_list_text )
502 for( i = 0; i < p_item->i_list; i++ )
503 free( p_item->ppsz_list_text[i] );
504 free( p_item->ppsz_list );
505 free( p_item->ppsz_list_text );
506 free( p_item->pi_list );
508 if( p_item->i_action )
510 for( i = 0; i < p_item->i_action; i++ )
512 free( p_item->ppsz_action_text[i] );
514 free( p_item->ppf_action );
515 free( p_item->ppsz_action_text );
519 free (p_module->p_config);
520 p_module->p_config = NULL;
523 /*****************************************************************************
524 * config_SetCallbacks: sets callback functions in the duplicate p_config.
525 *****************************************************************************
526 * Unfortunatly we cannot work directly with the module's config data as
527 * this module might be unloaded from memory at any time (remember HideModule).
528 * This is why we need to duplicate callbacks each time we reload the module.
529 *****************************************************************************/
530 void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig,
531 size_t n )
533 for (size_t i = 0; i < n; i++)
535 p_new->pf_callback = p_orig->pf_callback;
536 p_new++;
537 p_orig++;
541 /*****************************************************************************
542 * config_UnsetCallbacks: unsets callback functions in the duplicate p_config.
543 *****************************************************************************
544 * We simply undo what we did in config_SetCallbacks.
545 *****************************************************************************/
546 void config_UnsetCallbacks( module_config_t *p_new, size_t n )
548 for (size_t i = 0; i < n; i++)
550 p_new->pf_callback = NULL;
551 p_new++;
555 /*****************************************************************************
556 * config_ResetAll: reset the configuration data for all the modules.
557 *****************************************************************************/
558 void __config_ResetAll( vlc_object_t *p_this )
560 int i_index;
561 vlc_list_t *p_list;
562 module_t *p_module;
564 /* Acquire config file lock */
565 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
567 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
569 for( i_index = 0; i_index < p_list->i_count; i_index++ )
571 p_module = (module_t *)p_list->p_values[i_index].p_object ;
572 if( p_module->b_submodule ) continue;
574 for (size_t i = 0; i < p_module->confsize; i++ )
576 if (IsConfigIntegerType (p_module->p_config[i].i_type))
577 p_module->p_config[i].value.i = p_module->p_config[i].orig.i;
578 else
579 if (IsConfigFloatType (p_module->p_config[i].i_type))
580 p_module->p_config[i].value.f = p_module->p_config[i].orig.f;
581 else
582 if (IsConfigStringType (p_module->p_config[i].i_type))
584 free ((char *)p_module->p_config[i].value.psz);
585 p_module->p_config[i].value.psz =
586 strdupnull (p_module->p_config[i].orig.psz);
591 vlc_list_release( p_list );
592 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
596 * config_GetDataDir: find directory where shared data is installed
598 * @return a string (always succeeds).
600 const char *config_GetDataDir( void )
602 #if defined (WIN32) || defined (UNDER_CE)
603 return vlc_global()->psz_vlcpath;
604 #elif defined(__APPLE__) || defined (SYS_BEOS)
605 static char path[PATH_MAX] = "";
607 if( *path == '\0' )
609 snprintf( path, sizeof( path ), "%s/share",
610 vlc_global()->psz_vlcpath );
611 path[sizeof( path ) - 1] = '\0';
613 return path;
614 #else
615 return DATA_PATH;
616 #endif
619 /*****************************************************************************
620 * config_GetHomeDir, config_GetUserDir: find the user's home directory.
621 *****************************************************************************
622 * This function will try by different ways to find the user's home path.
623 * Note that this function is not reentrant, it should be called only once
624 * at the beginning of main where the result will be stored for later use.
625 *****************************************************************************/
626 static char *GetDir( vlc_bool_t b_appdata )
628 const char *psz_localhome = NULL;
630 #if defined(WIN32) && !defined(UNDER_CE)
631 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
632 LPWSTR );
633 #ifndef CSIDL_FLAG_CREATE
634 # define CSIDL_FLAG_CREATE 0x8000
635 #endif
636 #ifndef CSIDL_APPDATA
637 # define CSIDL_APPDATA 0x1A
638 #endif
639 #ifndef CSIDL_PROFILE
640 # define CSIDL_PROFILE 0x28
641 #endif
642 #ifndef SHGFP_TYPE_CURRENT
643 # define SHGFP_TYPE_CURRENT 0
644 #endif
646 HINSTANCE shfolder_dll;
647 SHGETFOLDERPATH SHGetFolderPath ;
649 /* load the shfolder dll to retrieve SHGetFolderPath */
650 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
652 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
653 _T("SHGetFolderPathW") );
654 if ( SHGetFolderPath != NULL )
656 wchar_t whomedir[MAX_PATH];
658 /* get the "Application Data" folder for the current user */
659 if( S_OK == SHGetFolderPath( NULL,
660 (b_appdata ? CSIDL_APPDATA :
661 CSIDL_PROFILE) | CSIDL_FLAG_CREATE,
662 NULL, SHGFP_TYPE_CURRENT,
663 whomedir ) )
665 FreeLibrary( shfolder_dll );
666 return FromWide( whomedir );
669 FreeLibrary( shfolder_dll );
672 #elif defined(UNDER_CE)
674 #ifndef CSIDL_APPDATA
675 # define CSIDL_APPDATA 0x1A
676 #endif
678 wchar_t whomedir[MAX_PATH];
680 /* get the "Application Data" folder for the current user */
681 if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) )
682 return FromWide( whomedir );
683 #endif
685 psz_localhome = getenv( "HOME" );
686 if( psz_localhome == NULL )
688 #if defined(HAVE_GETPWUID)
689 struct passwd *p_pw;
690 (void)b_appdata;
692 if( ( p_pw = getpwuid( getuid() ) ) != NULL )
693 psz_localhome = p_pw->pw_dir;
694 else
695 #endif
697 psz_localhome = getenv( "TMP" );
698 if( psz_localhome == NULL )
699 psz_localhome = "/tmp";
703 return FromLocaleDup( psz_localhome );
707 * Get the user's home directory
709 char *config_GetHomeDir( void )
711 return GetDir( VLC_FALSE );
715 * Get the user's main data and config directory:
716 * - on windows that's the App Data directory;
717 * - on other OSes it's the same as the home directory.
719 char *config_GetUserDir( void ); /* XXX why does gcc wants a declaration ?
720 * --funman */
721 char *config_GetUserDir( void )
723 return GetDir( VLC_TRUE );
727 * Get the user's VLC configuration directory
729 char *config_GetConfigDir( libvlc_int_t *p_libvlc )
731 char *psz_dir;
732 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
733 char *psz_parent = config_GetUserDir();
734 if( !psz_parent ) psz_parent = p_libvlc->psz_homedir;
735 if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
736 return NULL;
737 return psz_dir;
738 #else
739 /* XDG Base Directory Specification - Version 0.6 */
740 char *psz_env = getenv( "XDG_CONFIG_HOME" );
741 if( psz_env )
743 if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
744 return NULL;
745 return psz_dir;
747 psz_env = getenv( "HOME" );
748 if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */
749 if( asprintf( &psz_dir, "%s/.config/vlc", psz_env ) == -1 )
750 return NULL;
751 return psz_dir;
752 #endif
756 * Get the user's VLC data directory
757 * (used for stuff like the skins, custom lua modules, ...)
759 char *config_GetUserDataDir( libvlc_int_t *p_libvlc )
761 char *psz_dir;
762 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
763 char *psz_parent = config_GetUserDir();
764 if( !psz_parent ) psz_parent = p_libvlc->psz_homedir;
765 if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
766 return NULL;
767 return psz_dir;
768 #else
769 /* XDG Base Directory Specification - Version 0.6 */
770 char *psz_env = getenv( "XDG_DATA_HOME" );
771 if( psz_env )
773 if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
774 return NULL;
775 return psz_dir;
777 psz_env = getenv( "HOME" );
778 if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */
779 if( asprintf( &psz_dir, "%s/.local/share/vlc", psz_env ) == -1 )
780 return NULL;
781 return psz_dir;
782 #endif
786 * Get the user's VLC cache directory
787 * (used for stuff like the modules cache, the album art cache, ...)
789 char *config_GetCacheDir( libvlc_int_t *p_libvlc )
791 char *psz_dir;
792 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
793 char *psz_parent = config_GetUserDir();
794 if( !psz_parent ) psz_parent = p_libvlc->psz_homedir;
795 if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
796 return NULL;
797 return psz_dir;
798 #else
799 /* XDG Base Directory Specification - Version 0.6 */
800 char *psz_env = getenv( "XDG_CACHE_HOME" );
801 if( psz_env )
803 if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
804 return NULL;
805 return psz_dir;
807 psz_env = getenv( "HOME" );
808 if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */
809 if( asprintf( &psz_dir, "%s/.cache/vlc", psz_env ) == -1 )
810 return NULL;
811 return psz_dir;
812 #endif