MCPcopy Create free account
hub / github.com/Tencent/phxsql / ini_buffer_reader

Function ini_buffer_reader

phxcomm/configparser/inih-master/examples/ini_buffer.c:23–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21} buffer_ctx;
22
23static char* ini_buffer_reader(char* str, int num, void* stream) {
24 buffer_ctx* ctx = (buffer_ctx*) stream;
25 int idx = 0;
26 char newline = 0;
27
28 if (ctx->bytes_left <= 0)
29 return NULL;
30
31 for (idx = 0; idx < num - 1; ++idx) {
32 if (idx == ctx->bytes_left)
33 break;
34
35 if (ctx->ptr[idx] == '\n')
36 newline = '\n';
37 else if (ctx->ptr[idx] == '\r')
38 newline = '\r';
39
40 if (newline)
41 break;
42 }
43
44 memcpy(str, ctx->ptr, idx);
45 str[idx] = 0;
46
47 ctx->ptr += idx + 1;
48 ctx->bytes_left -= idx + 1;
49
50 if (newline && ctx->bytes_left > 0
51 && ((newline == '\r' && ctx->ptr[0] == '\n') || (newline == '\n' && ctx->ptr[0] == '\r'))) {
52 ctx->bytes_left--;
53 ctx->ptr++;
54 }
55 return str;
56}
57
58static int handler(void* user, const char* section, const char* name, const char* value) {
59 configuration* pconfig = (configuration*) user;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected