String type: Not include \0 in show_version
[vpp.git] / src / vlibapi / api_types.h
index 759298e..8a86612 100644 (file)
@@ -32,13 +32,12 @@ typedef struct
 static inline int
 vl_api_to_api_string (u32 len, const char *buf, vl_api_string_t * str)
 {
-  if (strncpy_s ((char *) str->buf, len, buf, len - 1) != 0)
-    len = 0;
+  clib_memcpy(str->buf, buf, len);
   str->length = clib_host_to_net_u32 (len);
   return len + sizeof (u32);
 }
 
-/* Return a C string from API string */
+/* Return a pointer to the API string (not nul terminated */
 static inline u8 *
 vl_api_from_api_string (vl_api_string_t * astr)
 {
@@ -51,4 +50,10 @@ vl_api_string_len (vl_api_string_t * astr)
   return clib_net_to_host_u32 (astr->length);
 }
 
+static inline char *
+vl_api_from_api_string_c (vl_api_string_t *astr)
+{
+  return strndup((char *)astr->buf, clib_net_to_host_u32(astr->length));
+}
+
 #endif