| 1 |
/* Glue functions for the minIni library, based on the C/C++ stdio library |
| 2 |
* |
| 3 |
* Or better said: this file contains macros that maps the function interface |
| 4 |
* used by minIni to the standard C/C++ file I/O functions. |
| 5 |
* |
| 6 |
* By CompuPhase, 2008-2014 |
| 7 |
* This "glue file" is in the public domain. It is distributed without |
| 8 |
* warranties or conditions of any kind, either express or implied. |
| 9 |
*/ |
| 10 |
|
| 11 |
/* map required file I/O types and functions to the standard C library */ |
| 12 |
#include <stdio.h> |
| 13 |
|
| 14 |
#define INI_FILETYPE FILE* |
| 15 |
#define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL) |
| 16 |
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL) |
| 17 |
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL) |
| 18 |
#define ini_close(file) (fclose(*(file)) == 0) |
| 19 |
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL) |
| 20 |
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0) |
| 21 |
#define ini_rename(source,dest) (rename((source), (dest)) == 0) |
| 22 |
#define ini_remove(filename) (remove(filename) == 0) |
| 23 |
|
| 24 |
#define INI_FILEPOS long int |
| 25 |
#define ini_tell(file,pos) (*(pos) = ftell(*(file))) |
| 26 |
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0) |
| 27 |
|
| 28 |
/* for floating-point support, define additional types and functions */ |
| 29 |
#define INI_REAL float |
| 30 |
#define ini_ftoa(string,value) sprintf((string),"%f",(value)) |
| 31 |
#define ini_atof(string) (INI_REAL)strtod((string),NULL) |