* 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
| 7481 | * there (which it isn't). |
| 7482 | */ |
| 7483 | bool |
| 7484 | pqGetHomeDirectory(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 |
no test coverage detected