Browse Source

Moving toward standard

Piotr Czajkowski 6 years ago
parent
commit
3fe3ef02c2
3 changed files with 10 additions and 5 deletions
  1. 7 2
      keyval.c
  2. 2 2
      keyval.h
  3. 1 1
      makefile

+ 7 - 2
keyval.c

@@ -4,9 +4,14 @@
 #include <strings.h> //strcasecmp (from POSIX)
 #include "keyval.h"
 
-keyval *keyval_new(char *key, void *value){
+keyval *keyval_new(char *key, char *value){
 	keyval *out = malloc(sizeof(keyval));
-	*out = (keyval){.key = strdup(key), .value=strdup(value)};
+	out->key = malloc(strlen(key)+1);
+	out->value = malloc(strlen(value)+1);
+
+	strcpy(out->key, key);
+	strcpy(out->value, value);
+
 	return out;
 }
 

+ 2 - 2
keyval.h

@@ -1,10 +1,10 @@
 // Borrowed from https://github.com/b-k/21st-Century-Examples
 typedef struct keyval{
 	char *key;
-	void *value;
+	char *value;
 } keyval;
 
-keyval *keyval_new(char *key, void *value);
+keyval *keyval_new(char *key, char *value);
 keyval *keyval_copy(keyval const *in);
 void keyval_free(keyval *in);
 int keyval_matches(keyval const *in, char const *key);

+ 1 - 1
makefile

@@ -1,4 +1,4 @@
-CFLAGS=`pkg-config --cflags --libs libxml-2.0` -g -Wall -Wextra -O3 -std=gnu99
+CFLAGS=`pkg-config --cflags --libs libxml-2.0` -g -Wall -Wextra -O3 -std=c99
 LDLIBS=`pkg-config --libs libxml-2.0` -larchive
 objects=keyval.o dict.o comments.o zip.o xmlbuff.o
 mingwCFLAGS=`x86_64-w64-mingw32-pkg-config --cflags --libs libxml-2.0` -g -Wall -Wextra -O3 -std=gnu99