mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
util_path: Simplify logic and get rid of goto
Signed-off-by: Jens Remus <jremus@linux.ibm.com> Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -150,18 +150,14 @@ bool util_path_is_writable(const char *fmt, ...)
|
||||
*/
|
||||
bool util_path_is_reg_file(const char *fmt, ...)
|
||||
{
|
||||
bool rc = false;
|
||||
struct stat sb;
|
||||
va_list ap;
|
||||
char *path;
|
||||
bool rc;
|
||||
|
||||
UTIL_VASPRINTF(&path, fmt, ap);
|
||||
if (stat(path, &sb)) {
|
||||
rc = false;
|
||||
goto free_str;
|
||||
}
|
||||
rc = S_ISREG(sb.st_mode) ? true : false;
|
||||
free_str:
|
||||
if (stat(path, &sb) == 0)
|
||||
rc = S_ISREG(sb.st_mode) ? true : false;
|
||||
free(path);
|
||||
return rc;
|
||||
}
|
||||
@@ -179,18 +175,14 @@ free_str:
|
||||
*/
|
||||
bool util_path_is_dir(const char *fmt, ...)
|
||||
{
|
||||
bool rc = false;
|
||||
struct stat sb;
|
||||
va_list ap;
|
||||
char *path;
|
||||
bool rc;
|
||||
|
||||
UTIL_VASPRINTF(&path, fmt, ap);
|
||||
if (stat(path, &sb)) {
|
||||
rc = false;
|
||||
goto free_str;
|
||||
}
|
||||
rc = S_ISDIR(sb.st_mode) ? true : false;
|
||||
free_str:
|
||||
if (stat(path, &sb) == 0)
|
||||
rc = S_ISDIR(sb.st_mode) ? true : false;
|
||||
free(path);
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user