diff options
author | stephan <stephan@noemail.net> | 2022-11-18 15:22:45 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-11-18 15:22:45 +0000 |
commit | 76abcfbdc0ca4834a5d82fdf42944f522f7128cd (patch) | |
tree | 82d9508de12e3d425e16685b5498aa6429eed6df /src | |
parent | d8e48fffdff1ebfbf5e0b2ded9e12ce00b1ba427 (diff) | |
parent | 6e8a3341ea48c15066d11281d14363b5454538c1 (diff) | |
download | sqlite-76abcfbdc0ca4834a5d82fdf42944f522f7128cd.tar.gz sqlite-76abcfbdc0ca4834a5d82fdf42944f522f7128cd.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index 6b038495f..db8d98766 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -11252,8 +11252,42 @@ static char *find_home_dir(int clearFlag){ } /* +** 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;" |