shell.c.in: on non-Windows platforms, check for $XDG_CONFIG_HOME/sqlite3/sqliterc before ~/.sqliterc, per request in [forum:7a16582b1e403c81|forum post 7a16582b1e403c81].
FossilOrigin-Name: 17065d095d26a814acf1e13f5cc18b21fecc58eb8c9da100458029bb139fcd35
This commit is contained in:
+39
-2
@@ -11251,9 +11251,43 @@ static char *find_home_dir(int clearFlag){
|
||||
return home_dir;
|
||||
}
|
||||
|
||||
/*
|
||||
** On non-Windows platforms, look for $XDG_CONFIG_HOME.
|
||||
** If ${XDG_CONFIG_HOME}/sqlite3/sqliterc is found, return
|
||||
** the path to it, else return 0. The result is cached for
|
||||
** subsequent calls.
|
||||
*/
|
||||
static const char *find_xdg_config(void){
|
||||
#if defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE) \
|
||||
|| defined(__RTP__) || defined(_WRS_KERNEL)
|
||||
return 0;
|
||||
#else
|
||||
static int alreadyTried = 0;
|
||||
static char *zConfig = 0;
|
||||
const char *zXdgHome;
|
||||
|
||||
if( alreadyTried!=0 ){
|
||||
return zConfig;
|
||||
}
|
||||
alreadyTried = 1;
|
||||
zXdgHome = getenv("XDG_CONFIG_HOME");
|
||||
if( zXdgHome==0 ){
|
||||
return 0;
|
||||
}
|
||||
zConfig = sqlite3_mprintf("%s/sqlite3/sqliterc", zXdgHome);
|
||||
shell_check_oom(zConfig);
|
||||
if( access(zConfig,0)!=0 ){
|
||||
sqlite3_free(zConfig);
|
||||
zConfig = 0;
|
||||
}
|
||||
return zConfig;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Read input from the file given by sqliterc_override. Or if that
|
||||
** parameter is NULL, take input from ~/.sqliterc
|
||||
** parameter is NULL, take input from the first of find_xdg_config()
|
||||
** or ~/.sqliterc which is found.
|
||||
**
|
||||
** Returns the number of errors.
|
||||
*/
|
||||
@@ -11267,7 +11301,10 @@ static void process_sqliterc(
|
||||
FILE *inSaved = p->in;
|
||||
int savedLineno = p->lineno;
|
||||
|
||||
if (sqliterc == NULL) {
|
||||
if( sqliterc == NULL ){
|
||||
sqliterc = find_xdg_config();
|
||||
}
|
||||
if( sqliterc == NULL ){
|
||||
home_dir = find_home_dir(0);
|
||||
if( home_dir==0 ){
|
||||
raw_printf(stderr, "-- warning: cannot find home directory;"
|
||||
|
||||
Reference in New Issue
Block a user