MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / find_home_dir

Function find_home_dir

modules/dasSQLITE/sqlite/shell.c:26646–26709  ·  view source on GitHub ↗

** Return a pathname which is the user's home directory. A ** 0 return indicates an error of some kind. */

Source from the content-addressed store, hash-verified

26644** 0 return indicates an error of some kind.
26645*/
26646static 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 );

Callers 2

process_sqlitercFunction · 0.85
wmainFunction · 0.85

Calls 2

strlen30Function · 0.85
freeFunction · 0.50

Tested by

no test coverage detected