MCPcopy Create free account
hub / github.com/apache/cloudberry / pqGetHomeDirectory

Function pqGetHomeDirectory

src/interfaces/libpq/fe-connect.c:7483–7505  ·  view source on GitHub ↗

* Obtain user's home directory, return in given buffer * * On Unix, this actually returns the user's home directory. On Windows * it returns the PostgreSQL-specific application data folder. * * This is essentially the same as get_home_path(), but we don't use that * because we don't want to pull path.c into libpq (it pollutes application * namespace). * * Returns true on success, false o

Source from the content-addressed store, hash-verified

7481 * there (which it isn't).
7482 */
7483bool
7484pqGetHomeDirectory(char *buf, int bufsize)
7485{
7486#ifndef WIN32
7487 char pwdbuf[BUFSIZ];
7488 struct passwd pwdstr;
7489 struct passwd *pwd = NULL;
7490
7491 (void) pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd);
7492 if (pwd == NULL)
7493 return false;
7494 strlcpy(buf, pwd->pw_dir, bufsize);
7495 return true;
7496#else
7497 char tmppath[MAX_PATH];
7498
7499 ZeroMemory(tmppath, sizeof(tmppath));
7500 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, tmppath) != S_OK)
7501 return false;
7502 snprintf(buf, bufsize, "%s/postgresql", tmppath);
7503 return true;
7504#endif
7505}
7506
7507/*
7508 * To keep the API consistent, the locking stubs are always provided, even

Callers 3

initialize_SSLFunction · 0.85
connectOptions2Function · 0.85
parseServiceInfoFunction · 0.85

Calls 2

pqGetpwuidFunction · 0.85
strlcpyFunction · 0.85

Tested by

no test coverage detected