summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-13 07:06:14 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-13 07:06:30 +0800
commitb188f0557911ddb353f8b78d6770ba9fd0114329 (patch)
treefe54cdb1a6fac9bf6822427597c9596f5a3dc066
parent07435e79294202706ccf71f91eab48bcd122c459 (diff)
Just use memset instead of a special init function
-rw-r--r--catalog.c2
-rw-r--r--icclient/product.h3
-rw-r--r--ord.c2
-rw-r--r--product.c15
4 files changed, 3 insertions, 19 deletions
diff --git a/catalog.c b/catalog.c
index caaef04..92dce73 100644
--- a/catalog.c
+++ b/catalog.c
@@ -41,7 +41,7 @@ size_t icclient_catalog_results(void *data, size_t size, size_t nmemb, void *use
for (size_t i = 0; i < length; i++) {
catalog->products[i] = malloc(sizeof(struct icclient_product));
struct icclient_product *product = catalog->products[i];
- icclient_product_init(product);
+ memset(product, '\0', sizeof(struct icclient_product));
json_object *object = json_object_array_get_idx(products, i);
struct json_object_iterator iterator = json_object_iter_begin(object);
struct json_object_iterator iterator_end = json_object_iter_end(object);
diff --git a/icclient/product.h b/icclient/product.h
index c3e91bd..8fa6bc3 100644
--- a/icclient/product.h
+++ b/icclient/product.h
@@ -23,11 +23,10 @@ struct icclient_product {
extern "C" {
#endif
- void icclient_product_init(struct icclient_product *product);
void icclient_product_free(struct icclient_product *product);
#ifdef __cplusplus
}
#endif
-#endif // ICCLIENT_PRODUCT_H
+#endif
diff --git a/ord.c b/ord.c
index 18e1bd2..07e6e64 100644
--- a/ord.c
+++ b/ord.c
@@ -36,7 +36,7 @@ void icclient_ord_order(const char *sku, const icclient_catalog *catalog,
icclient_product **products = ((icclient_catalog *)catalog)->products;
qsort(products, catalog->length, sizeof(icclient_product *), prodcmp);
icclient_product *key_product = malloc(sizeof(icclient_product));
- icclient_product_init(key_product);
+ memset(key_product, '\0', sizeof(icclient_product));
key_product->sku = malloc(strlen(sku) + 1);
strcpy(key_product->sku, sku);
icclient_product *product = *(icclient_product **)bsearch(&key_product
diff --git a/product.c b/product.c
index fcb16be..0323192 100644
--- a/product.c
+++ b/product.c
@@ -1,20 +1,6 @@
#include <stdlib.h>
#include "icclient/product.h"
-void icclient_product_init(struct icclient_product *product)
-{
- product->sku = NULL;
- product->description = NULL;
- product->comment = NULL;
- product->thumb = NULL;
- product->image = NULL;
- product->price = .0;
- product->prod_group = NULL;
- product->weight = .0;
- product->author = NULL;
- product->crosssell = NULL;
-}
-
void icclient_product_free(struct icclient_product *product)
{
if (product->crosssell)
@@ -34,5 +20,4 @@ void icclient_product_free(struct icclient_product *product)
free(product->description);
free(product->sku);
free(product);
- product = NULL;
}