Remove non-standard asprintf from mpw-cli.
This commit is contained in:
parent
724b357dd8
commit
1e7c200865
@ -139,34 +139,41 @@ static const char *mpw_getpass(const char *prompt) {
|
|||||||
static const char *mpw_path(const char *prefix, const char *extension) {
|
static const char *mpw_path(const char *prefix, const char *extension) {
|
||||||
|
|
||||||
// Resolve user's home directory.
|
// Resolve user's home directory.
|
||||||
const char *homedir = NULL;
|
char *homeDir = NULL;
|
||||||
if (!homedir)
|
if (!homeDir)
|
||||||
homedir = getenv( "HOME" );
|
if ((homeDir = getenv( "HOME" )))
|
||||||
if (!homedir)
|
homeDir = strdup( homeDir );
|
||||||
homedir = getenv( "USERPROFILE" );
|
if (!homeDir)
|
||||||
if (!homedir) {
|
if ((homeDir = getenv( "USERPROFILE" )))
|
||||||
const char *homedrive = getenv( "HOMEDRIVE" ), *homepath = getenv( "HOMEPATH" );
|
homeDir = strdup( homeDir );
|
||||||
if (homedrive && homepath)
|
if (!homeDir) {
|
||||||
homedir = mpw_str( "%s%s", homedrive, homepath );
|
const char *homeDrive = getenv( "HOMEDRIVE" ), *homePath = getenv( "HOMEPATH" );
|
||||||
|
if (homeDrive && homePath)
|
||||||
|
homeDir = strdup( mpw_str( "%s%s", homeDrive, homePath ) );
|
||||||
}
|
}
|
||||||
if (!homedir) {
|
if (!homeDir) {
|
||||||
struct passwd *passwd = getpwuid( getuid() );
|
struct passwd *passwd = getpwuid( getuid() );
|
||||||
if (passwd)
|
if (passwd)
|
||||||
homedir = passwd->pw_dir;
|
homeDir = strdup( passwd->pw_dir );
|
||||||
}
|
}
|
||||||
if (!homedir)
|
if (!homeDir)
|
||||||
homedir = getcwd( NULL, 0 );
|
homeDir = getcwd( NULL, 0 );
|
||||||
|
|
||||||
// Compose filename.
|
// Compose filename.
|
||||||
char *path = NULL;
|
char *path = strdup( mpw_str( "%s.%s", prefix, extension ) );
|
||||||
asprintf( &path, "%s.%s", prefix, extension );
|
|
||||||
|
|
||||||
// This is a filename, remove all potential directory separators.
|
// This is a filename, remove all potential directory separators.
|
||||||
for (char *slash; (slash = strstr( path, "/" )); *slash = '_');
|
for (char *slash; (slash = strstr( path, "/" )); *slash = '_');
|
||||||
|
|
||||||
// Compose pathname.
|
// Compose pathname.
|
||||||
if (homedir)
|
if (homeDir) {
|
||||||
asprintf( &path, "%s/.mpw.d/%s", homedir, path );
|
const char *homePath = mpw_str( "%s/.mpw.d/%s", homeDir, path );
|
||||||
|
free( homeDir );
|
||||||
|
free( path );
|
||||||
|
|
||||||
|
if (homePath)
|
||||||
|
path = strdup( homePath );
|
||||||
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user