aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2024-08-13 11:08:28 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2024-08-13 11:08:28 +0200
commit1cf817eba1ab8c2ee46a73c6bea9b7e70e418cdd (patch)
treecc20815272d706ad1b78a9c302ec52185a3d979a
parent9642e3625d97de5aca850943ed33fffb3b61f180 (diff)
downloadproperties-1cf817eba1ab8c2ee46a73c6bea9b7e70e418cdd.tar.gz
properties-1cf817eba1ab8c2ee46a73c6bea9b7e70e418cdd.zip
Add `cpyval` function
-rw-r--r--properties.y12
1 files changed, 10 insertions, 2 deletions
diff --git a/properties.y b/properties.y
index 0f8c8d4..7bdd864 100644
--- a/properties.y
+++ b/properties.y
@@ -4,6 +4,15 @@
#include <stdlib.h>
#include "utils/string.h"
+char *
+cpyval(size_t number,
+ size_t size,
+ char *value)
+{
+ char *dest = calloc(number, size);
+ return strcat(dest, value);
+}
+
%}
%token KEY DIV VALUE
@@ -28,8 +37,7 @@ property: KEY DIV value {
;
value: VALUE {
- $$.value = calloc(2, sizeof(char));
- strcat($$.value, $1.value);
+ $$.value = cpyval(2, sizeof(char), $1.value);
}
| value VALUE {
char *s = strdup($$.value);