** Return a pathname which is the user's home directory. A ** 0 return indicates an error of some kind. */
| 26644 | ** 0 return indicates an error of some kind. |
| 26645 | */ |
| 26646 | static char *find_home_dir(int clearFlag){ |
| 26647 | static char *home_dir = NULL; |
| 26648 | if( clearFlag ){ |
| 26649 | free(home_dir); |
| 26650 | home_dir = 0; |
| 26651 | return 0; |
| 26652 | } |
| 26653 | if( home_dir ) return home_dir; |
| 26654 | |
| 26655 | #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \ |
| 26656 | && !defined(__RTP__) && !defined(_WRS_KERNEL) && !defined(SQLITE_WASI) |
| 26657 | { |
| 26658 | struct passwd *pwent; |
| 26659 | uid_t uid = getuid(); |
| 26660 | if( (pwent=getpwuid(uid)) != NULL) { |
| 26661 | home_dir = pwent->pw_dir; |
| 26662 | } |
| 26663 | } |
| 26664 | #endif |
| 26665 | |
| 26666 | #if defined(_WIN32_WCE) |
| 26667 | /* Windows CE (arm-wince-mingw32ce-gcc) does not provide getenv() |
| 26668 | */ |
| 26669 | home_dir = "/"; |
| 26670 | #else |
| 26671 | |
| 26672 | #if defined(_WIN32) || defined(WIN32) |
| 26673 | if (!home_dir) { |
| 26674 | home_dir = getenv("USERPROFILE"); |
| 26675 | } |
| 26676 | #endif |
| 26677 | |
| 26678 | if (!home_dir) { |
| 26679 | home_dir = getenv("HOME"); |
| 26680 | } |
| 26681 | |
| 26682 | #if defined(_WIN32) || defined(WIN32) |
| 26683 | if (!home_dir) { |
| 26684 | char *zDrive, *zPath; |
| 26685 | int n; |
| 26686 | zDrive = getenv("HOMEDRIVE"); |
| 26687 | zPath = getenv("HOMEPATH"); |
| 26688 | if( zDrive && zPath ){ |
| 26689 | n = strlen30(zDrive) + strlen30(zPath) + 1; |
| 26690 | home_dir = malloc( n ); |
| 26691 | if( home_dir==0 ) return 0; |
| 26692 | sqlite3_snprintf(n, home_dir, "%s%s", zDrive, zPath); |
| 26693 | return home_dir; |
| 26694 | } |
| 26695 | home_dir = "c:\\"; |
| 26696 | } |
| 26697 | #endif |
| 26698 | |
| 26699 | #endif /* !_WIN32_WCE */ |
| 26700 | |
| 26701 | if( home_dir ){ |
| 26702 | i64 n = strlen(home_dir) + 1; |
| 26703 | char *z = malloc( n ); |
no test coverage detected