From: Keith Busch Date: Mon, 1 Jun 2020 14:08:49 +0000 (-0700) Subject: generic whitespace strip routine X-Git-Tag: v1.0-rc0~151 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=af59d4979e10b8378fbeb76efe73917464ca374d;p=users%2Fsagi%2Flibnvme.git generic whitespace strip routine Printing routines have a need to strip white spaces too, so make this a common nvme lib routine. Signed-off-by: Keith Busch --- diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index bf0ae675..52e05670 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -186,12 +186,6 @@ nvme_ctrl_t nvmf_add_ctrl(struct nvme_fabrics_config *cfg) return nvme_scan_ctrl(d); } -static void chomp(char *s, int l) -{ - while (l && (s[l] == '\0' || s[l] == ' ')) - s[l--] = '\0'; -} - nvme_ctrl_t nvmf_connect_disc_entry(struct nvmf_disc_log_entry *e, const struct nvme_fabrics_config *defcfg, bool *discover) @@ -218,8 +212,8 @@ nvme_ctrl_t nvmf_connect_disc_entry(struct nvmf_disc_log_entry *e, switch (e->adrfam) { case NVMF_ADDR_FAMILY_IP4: case NVMF_ADDR_FAMILY_IP6: - chomp(e->traddr, NVMF_TRADDR_SIZE); - chomp(e->trsvcid, NVMF_TRSVCID_SIZE); + nvme_chomp(e->traddr, NVMF_TRADDR_SIZE); + nvme_chomp(e->trsvcid, NVMF_TRSVCID_SIZE); cfg.traddr = e->traddr; cfg.trsvcid = e->trsvcid; break; @@ -231,7 +225,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(struct nvmf_disc_log_entry *e, case NVMF_TRTYPE_FC: switch (e->adrfam) { case NVMF_ADDR_FAMILY_FC: - chomp(e->traddr, NVMF_TRADDR_SIZE), + nvme_chomp(e->traddr, NVMF_TRADDR_SIZE), cfg.traddr = e->traddr; cfg.trsvcid = NULL; break; diff --git a/src/nvme/util.h b/src/nvme/util.h index 88f99d99..05629ccb 100644 --- a/src/nvme/util.h +++ b/src/nvme/util.h @@ -226,4 +226,15 @@ int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype, */ int nvme_open(const char *name); +/** + * nvme_chomp() - Strip trailing white space + * &s: String to strip + * @l: Maximum length of string + */ +static inline void nvme_chomp(char *s, int l) +{ + while (l && (s[l] == '\0' || s[l] == ' ')) + s[l--] = '\0'; +} + #endif /* _LIBNVME_UTIL_H */