mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libutil/util_sys: Use util_readlink() for consistent error handling
Avoid code duplication and inconsistent error handling by replacing readlink() with util_readlink(), which is used project-wide to standardize readlink() usage. Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Jan Polensky <japo@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
d4ee1ff01f
commit
e7203069cc
@@ -24,8 +24,6 @@
|
|||||||
#include "lib/util_path.h"
|
#include "lib/util_path.h"
|
||||||
#include "lib/util_sys.h"
|
#include "lib/util_sys.h"
|
||||||
|
|
||||||
/* lstat() doesn't work for sysfs files, a fixed size is therefore inevitable */
|
|
||||||
#define READLINK_SIZE 256
|
|
||||||
#define PAGE_SIZE 4096
|
#define PAGE_SIZE 4096
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,10 +135,10 @@ int util_sys_get_base_dev(dev_t dev, dev_t *base_dev)
|
|||||||
*/
|
*/
|
||||||
int util_sys_get_dev_addr(const char *dev, char *addr)
|
int util_sys_get_dev_addr(const char *dev, char *addr)
|
||||||
{
|
{
|
||||||
char device[READLINK_SIZE], *result;
|
|
||||||
unsigned int maj, min;
|
unsigned int maj, min;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
ssize_t len;
|
char *linkdir;
|
||||||
|
char *result;
|
||||||
dev_t base;
|
dev_t base;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
@@ -160,19 +158,18 @@ int util_sys_get_dev_addr(const char *dev, char *addr)
|
|||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
len = readlink(path, device, READLINK_SIZE - 1);
|
linkdir = util_readlink(path);
|
||||||
free(path);
|
free(path);
|
||||||
if (len != -1)
|
if (!linkdir)
|
||||||
device[len] = '\0';
|
|
||||||
else
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
result = strrchr(device, '/');
|
result = strrchr(linkdir, '/');
|
||||||
if (result)
|
if (result)
|
||||||
result++;
|
result++;
|
||||||
else
|
else
|
||||||
result = device;
|
result = linkdir;
|
||||||
strcpy(addr, result);
|
strcpy(addr, result);
|
||||||
|
free(linkdir);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user