From a636bccabae4945f28fc7f350af375d35c4fd943 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 25 Oct 2010 13:13:53 +0000 Subject: [PATCH] Use const pointer for return value of dm_basename Fix return pointer to const as it is created from passed input const pointer. --- WHATS_NEW_DM | 1 + libdm/libdevmapper.h | 2 +- libdm/libdm-string.c | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index bccb1364a..d3f554995 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.56 - ===================================== + Fix API for dm_basename() and return const pointer for const input pointer. Add --setuuid to dmsetup rename. Add dm_task_set_newuuid to set uuid of mapped device post-creation. diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 7ed60beb8..e2f267330 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -955,7 +955,7 @@ int dm_snprintf(char *buf, size_t bufsize, const char *format, ...) /* * Returns pointer to the last component of the path. */ -char *dm_basename(const char *path); +const char *dm_basename(const char *path); /************************** * file/stream manipulation diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c index ce05a10b4..d8fca1a90 100644 --- a/libdm/libdm-string.c +++ b/libdm/libdm-string.c @@ -123,11 +123,11 @@ int dm_snprintf(char *buf, size_t bufsize, const char *format, ...) return n; } -char *dm_basename(const char *path) +const char *dm_basename(const char *path) { - char *p = strrchr(path, '/'); + const char *p = strrchr(path, '/'); - return p ? p + 1 : (char *) path; + return p ? p + 1 : path; } int dm_asprintf(char **result, const char *format, ...)