]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
generic whitespace strip routine
authorKeith Busch <kbusch@kernel.org>
Mon, 1 Jun 2020 14:08:49 +0000 (07:08 -0700)
committerKeith Busch <kbusch@kernel.org>
Mon, 1 Jun 2020 14:08:49 +0000 (07:08 -0700)
Printing routines have a need to strip white spaces too, so make this a
common nvme lib routine.

Signed-off-by: Keith Busch <kbusch@kernel.org>
src/nvme/fabrics.c
src/nvme/util.h

index bf0ae67547bde9065459b0bc9f0a65ab4d9b97ce..52e05670d9a9d7ed77f210c37a23454e5aeb4221 100644 (file)
@@ -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;
index 88f99d99358e8022cda0b8006c3cc2b9a61afbc6..05629ccb52692e43117bdd62bff6a67806b5b049 100644 (file)
@@ -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 */