Whamcloud - gitweb
LU-12373 pcc: uncache the pcc copies when remove a PCC backend
[fs/lustre-release.git] / lustre / utils / liblustreapi_json.c
index 10e8e76..4c730ce 100644 (file)
@@ -3,7 +3,7 @@
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * (C) Copyright 2014 Intel Corporation.
+ * Copyright (c) 2014, Intel Corporation.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the GNU Lesser General Public License
@@ -41,7 +41,7 @@
 #include <unistd.h>
 #endif
 
-#include <libcfs/libcfs.h>
+#include <libcfs/util/string.h>
 #include <lustre/lustreapi.h>
 
 /** Quick-n'-dirty JSON string escape routine.
@@ -54,7 +54,7 @@
  * http://json.org/
  * http://www.ietf.org/rfc/rfc4627.txt (section 2.5)
  */
-int llapi_json_escape_string(char **out_string, char *in_string)
+static int json_escape_string(char **out_string, char *in_string)
 {
        int     i;
        char    escape_chars[] = {'\b', '\f', '\n', '\r', '\t', '"', '\\',
@@ -141,14 +141,14 @@ int llapi_json_write_list(struct llapi_json_item_list **json_items, FILE *fp)
                        fprintf(fp, "%d", item->lji_integer);
                        break;
                case LLAPI_JSON_BIGNUM:
-                       fprintf(fp, LPU64, item->lji_u64);
+                       fprintf(fp, "%llu", (unsigned long long)item->lji_u64);
                        break;
                case LLAPI_JSON_REAL:
                        fprintf(fp, "%f", item->lji_real);
                        break;
                case LLAPI_JSON_STRING:
-                       if (llapi_json_escape_string(&escaped_string,
-                                                    item->lji_string) < 0) {
+                       if (json_escape_string(&escaped_string,
+                                              item->lji_string) < 0) {
                                if (escaped_string != NULL)
                                        free(escaped_string);
                                return -errno;
@@ -276,7 +276,7 @@ int llapi_json_add_item(struct llapi_json_item_list **json_items,
        if (new_item->lji_key == NULL)
                return -ENOMEM;
 
-       strlcpy(new_item->lji_key, key, len);
+       snprintf(new_item->lji_key, len, "%s", key);
        new_item->lji_type = type;
        new_item->lji_next = NULL;
 
@@ -295,7 +295,7 @@ int llapi_json_add_item(struct llapi_json_item_list **json_items,
                new_item->lji_string = calloc(len, sizeof(char));
                if (new_item->lji_string == NULL)
                        return -ENOMEM;
-               strlcpy(new_item->lji_string, (char *)val, len);
+               snprintf(new_item->lji_string, len, "%s", (char *)val);
                break;
        default:
                llapi_err_noerrno(LLAPI_MSG_ERROR, "Unknown JSON type: %d",