bakaid commented on a change in pull request #590: MINIFICPP-621 Nanofi 
Tailfile example
URL: https://github.com/apache/nifi-minifi-cpp/pull/590#discussion_r294886759
 
 

 ##########
 File path: nanofi/src/core/string_utils.c
 ##########
 @@ -0,0 +1,165 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "core/cstructs.h"
+#include "core/string_utils.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int validate_list(struct token_list * tk_list) {
+    if (tk_list && tk_list->head && tk_list->tail && tk_list->size > 0) {
+        return 1;
+    }
+    return 0;
+}
+
+void add_token_to_list(struct token_list * tk_list, char * begin, uint64_t 
len) {
+    struct token_node * new_node = (struct token_node *)malloc(sizeof(struct 
token_node));
+    new_node->data = (char *)malloc((len+1) * sizeof(char));
+    strncpy(new_node->data, begin, len);
+    new_node->data[len] = '\0';
+    new_node->next = NULL;
+
+    if (!tk_list->head) {
+        tk_list->head = tk_list->tail = new_node;
+        tk_list->size++;
+        tk_list->total_bytes += len;
+        return;
+    }
+
+    tk_list->tail->next = new_node;
+    tk_list->tail = new_node;
+    tk_list->size++;
+    tk_list->total_bytes += len;
+}
+
+void free_token_node(struct token_node * node) {
+    if (node) {
+        free(node->data);
+    }
+    free(node);
+    memset(node, 0, sizeof(struct token_node));
+}
+
+void free_all_tokens(struct token_list * tks) {
+    while (tks && tks->head) {
+        struct token_node * node = tks->head;
+        tks->head = tks->head->next;
+        free_token_node(node);
+    }
+}
+
+void print_token_list(token_list * tokens) {
+    if (tokens) {
+        token_node * head = tokens->head;
+        int i = 0;
+        while (head) {
+            printf("Token %d : %s Length = %d\n", i, head->data, 
strlen(head->data));
 
 Review comment:
   strlen returns a size_t, the printf format specifier for it should be %zu, 
not %d.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to