Mercurial > projects > pwm
comparison pwm.c @ 35:2a8298bafec2
Try to use $HOME for the user's home directory
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Tue, 06 Aug 2019 11:21:04 +0200 |
parents | 2552eec9b913 |
children | 131c35592054 |
comparison
equal
deleted
inserted
replaced
34:34ada71ff3e5 | 35:2a8298bafec2 |
---|---|
339 int errflag = 0; | 339 int errflag = 0; |
340 int c; | 340 int c; |
341 const char *master_password_filename = NULL; | 341 const char *master_password_filename = NULL; |
342 struct pwm_ctx ctx = { 0 }; | 342 struct pwm_ctx ctx = { 0 }; |
343 struct passwd *passwd; | 343 struct passwd *passwd; |
344 char *home; | |
344 FILE *fp = NULL; | 345 FILE *fp = NULL; |
345 | 346 |
346 setprogname(argv[0]); | 347 setprogname(argv[0]); |
347 | 348 |
348 /* set up locale and check for UTF-8 codeset */ | 349 /* set up locale and check for UTF-8 codeset */ |
392 usage(); | 393 usage(); |
393 status = EXIT_USAGE; | 394 status = EXIT_USAGE; |
394 goto out; | 395 goto out; |
395 } | 396 } |
396 | 397 |
397 passwd = getpwuid(getuid()); | 398 home = getenv("HOME"); |
398 if (passwd == NULL) { | 399 if (home == NULL) { |
399 err(1, "getpwuid"); | 400 passwd = getpwuid(getuid()); |
400 } | 401 if (passwd == NULL) { |
401 xasprintf(&ctx.dirname, "%s/.pwm", passwd->pw_dir); | 402 err(1, "getpwuid"); |
403 } | |
404 home = passwd->pw_dir; | |
405 } | |
406 xasprintf(&ctx.dirname, "%s/.pwm", home); | |
402 | 407 |
403 /* create ~/.pwm directory if necessary */ | 408 /* create ~/.pwm directory if necessary */ |
404 if ((mkdir(ctx.dirname, S_IRWXU) != 0) && (errno != EEXIST)) { | 409 if ((mkdir(ctx.dirname, S_IRWXU) != 0) && (errno != EEXIST)) { |
405 warn("failed to create directory \"%s\"", ctx.dirname); | 410 warn("failed to create directory \"%s\"", ctx.dirname); |
406 goto out; | 411 goto out; |