]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
string: making shortening function global
authorVictor Julien <victor@inliniac.net>
Fri, 19 Jul 2019 13:07:46 +0000 (15:07 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 19 Jul 2019 14:09:37 +0000 (16:09 +0200)
src/util-device.c
src/util-misc.c
src/util-misc.h

index 1187c62532b26ad25b9ad38cd331f5a7eb5ee6e7..d6cc5b6b941442ba226655a595a9136ff1449002 100644 (file)
@@ -19,6 +19,7 @@
 #include "conf.h"
 #include "util-device.h"
 #include "util-ioctl.h"
+#include "util-misc.h"
 
 #include "device-storage.h"
 
@@ -189,33 +190,6 @@ const char *LiveGetDeviceName(int number)
     return NULL;
 }
 
-static void ShortenString(const char *input,
-    char *output, size_t output_size, char c)
-{
-    const size_t str_len = strlen(input);
-    size_t half = (output_size - 1) / 2;
-
-    /* If the output size is an even number */
-    if (half * 2 == (output_size - 1)) {
-        half = half - 1;
-    }
-
-    size_t spaces = (output_size - 1) - (half * 2);
-
-    /* Add the first half to the new string */
-    snprintf(output, half+1, "%s", input);
-
-    /* Add the amount of spaces wanted */
-    size_t length = half;
-    for (size_t i = half; i < half + spaces; i++) {
-        char s[2] = "";
-        snprintf(s, sizeof(s), "%c", c);
-        length = strlcat(output, s, output_size);
-    }
-
-    snprintf(output + length, half + 1, "%s", input + (str_len - half));
-}
-
 /** \internal
  *  \brief Shorten a device name that is to long
  *
index e41554a0788328232e3c52c28215a97bb22afda6..c706215a8f76a15a2eade759f96c58a5c50103d6 100644 (file)
@@ -217,6 +217,33 @@ int ParseSizeStringU64(const char *size, uint64_t *res)
     return 0;
 }
 
+void ShortenString(const char *input,
+    char *output, size_t output_size, char c)
+{
+    const size_t str_len = strlen(input);
+    size_t half = (output_size - 1) / 2;
+
+    /* If the output size is an even number */
+    if (half * 2 == (output_size - 1)) {
+        half = half - 1;
+    }
+
+    size_t spaces = (output_size - 1) - (half * 2);
+
+    /* Add the first half to the new string */
+    snprintf(output, half+1, "%s", input);
+
+    /* Add the amount of spaces wanted */
+    size_t length = half;
+    for (size_t i = half; i < half + spaces; i++) {
+        char s[2] = "";
+        snprintf(s, sizeof(s), "%c", c);
+        length = strlcat(output, s, output_size);
+    }
+
+    snprintf(output + length, half + 1, "%s", input + (str_len - half));
+}
+
 /*********************************Unittests********************************/
 
 #ifdef UNITTESTS
index 2245f829331ac197cdc408c25e69a7018efd1813..e39e48795289ac6bea1a4adafb1578f95c8d9770 100644 (file)
@@ -52,4 +52,7 @@ void UtilMiscRegisterTests(void);
 void ParseSizeInit(void);
 void ParseSizeDeinit(void);
 
+void ShortenString(const char *input,
+    char *output, size_t output_size, char c);
+
 #endif /* __UTIL_MISC_H__ */