summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2023-06-01 09:27:48 +0200
committerJes Sorensen <jes@trained-monkey.org>2023-10-26 23:28:23 +0200
commit67417d9222c505103357191bb0e0ae300892e8a9 (patch)
treeec4990547c9556b08af0b7a098f44d4b9622eeae /lib.c
parentmdadm: set ident.devname if applicable (diff)
downloadmdadm-67417d9222c505103357191bb0e0ae300892e8a9.tar.xz
mdadm-67417d9222c505103357191bb0e0ae300892e8a9.zip
mdadm: refactor ident->name handling
Create dedicated setter for name in mddev_ident and propagate it. Following changes are made: - move duplicated code from config.c and mdadm.c into new function. - Add error enum in mdadm.h. - Use MD_NAME_MAX instead of hardcoded value in mddev_ident. - Use secure functions. - Add more detailed verification of the name. - make error messages reusable for cmdline and config: - for cmdline, these are errors so use pr_err(). - for config, these are just warnings, so use pr_info(). Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 8a4b48e0..03198e2d 100644
--- a/lib.c
+++ b/lib.c
@@ -27,6 +27,24 @@
#include <ctype.h>
#include <limits.h>
+/**
+ * is_string_lq() - Check if string length with NULL byte is lower or equal to requested.
+ * @str: string to check.
+ * @max_len: max length.
+ *
+ * @str length must be bigger than 0 and be lower or equal @max_len, including termination byte.
+ */
+bool is_string_lq(const char * const str, size_t max_len)
+{
+ assert(str);
+
+ size_t _len = strnlen(str, max_len);
+
+ if (_len > 0 && _len < max_len)
+ return true;
+ return false;
+}
+
bool is_dev_alive(char *path)
{
if (!path)