aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-11-06 13:12:11 +0000
committerstephan <stephan@noemail.net>2022-11-06 13:12:11 +0000
commit6e8a3341ea48c15066d11281d14363b5454538c1 (patch)
treeb61d01abfeac1db485ae87b65e4d989ffa08267f /src
parentf53c0a0d4e02fbf7b536ba84eecb33ec7df6877f (diff)
downloadsqlite-6e8a3341ea48c15066d11281d14363b5454538c1.tar.gz
sqlite-6e8a3341ea48c15066d11281d14363b5454538c1.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: 49c6e438a83b9ff40ebadd3dfd5f58e6eea053575e15335909f5ee59a6dba82c
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index 635361aa9..9d4689bd9 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;"