-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add INI_CUSTOM_ALLOCATOR to allow using a custom memory allocator (#119)
Fixes #118
- Loading branch information
Showing
7 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ini_malloc(12) | ||
... [section] | ||
... foo=bar; | ||
ini_realloc(24) | ||
... bazz=buzz quxx; | ||
ini_free() | ||
basic: e=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* inih -- unit tests for custom memory allocator */ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "../ini.h" | ||
|
||
void* ini_malloc(size_t size) { | ||
printf("ini_malloc(%d)\n", (int)size); | ||
return malloc(size); | ||
} | ||
|
||
void ini_free(void* ptr) { | ||
printf("ini_free()\n"); | ||
free(ptr); | ||
} | ||
|
||
void* ini_realloc(void* ptr, size_t size) { | ||
printf("ini_realloc(%d)\n", (int)size); | ||
return realloc(ptr, size); | ||
} | ||
|
||
char Prev_section[50]; | ||
|
||
int dumper(void* user, const char* section, const char* name, | ||
const char* value) | ||
{ | ||
if (strcmp(section, Prev_section)) { | ||
printf("... [%s]\n", section); | ||
strncpy(Prev_section, section, sizeof(Prev_section)); | ||
Prev_section[sizeof(Prev_section) - 1] = '\0'; | ||
} | ||
printf("... %s=%s;\n", name, value); | ||
return 1; | ||
} | ||
|
||
void parse(const char* name, const char* string) { | ||
int e; | ||
|
||
*Prev_section = '\0'; | ||
e = ini_parse_string(string, dumper, NULL); | ||
printf("%s: e=%d\n", name, e); | ||
} | ||
|
||
int main(void) | ||
{ | ||
parse("basic", "[section]\nfoo = bar\nbazz = buzz quxx"); | ||
return 0; | ||
} |