X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions.cc;h=5a9feacb8754920113c6b339ecc99c8f5482878a;hb=f0d3a824ed9acb9f6e3080683abe2bcc8b0cd6bd;hp=1bf2ffa1b541eb9a02085036f03a3dc34f674ba1;hpb=10f3d6bf1bc11c235779ae735f30758cfb035686;p=awesomized%2Flibmemcached diff --git a/libmemcached/options.cc b/libmemcached/options.cc index 1bf2ffa1..5a9feacb 100644 --- a/libmemcached/options.cc +++ b/libmemcached/options.cc @@ -48,6 +48,10 @@ memcached_return_t memcached_parse_options(memcached_st *self, char const *optio memset(&pp, 0, sizeof(type_st)); + WATCHPOINT_ASSERT(self); + if (! self) + return MEMCACHED_INVALID_ARGUMENTS; + pp.buf= option_string; pp.memc= self; pp.length= length; @@ -62,10 +66,28 @@ memcached_return_t memcached_parse_options(memcached_st *self, char const *optio return MEMCACHED_SUCCESS; } -memcached_return_t memcached_parse_file_options(memcached_st *ptr, const char *filename) +memcached_return_t memcached_parse_file_options(memcached_st *self, const char *filename) { - (void)ptr; - (void)filename; + FILE *fp= fopen(filename, "r"); + + if (! fp) + return memcached_set_errno(self, errno, NULL); - return MEMCACHED_SUCCESS; + char buffer[BUFSIZ]; + memcached_return_t rc= MEMCACHED_INVALID_ARGUMENTS; + while (fgets(buffer, sizeof(buffer), fp)) + { + size_t length= strlen(buffer); + + if (length == 1 and buffer[0] == '\n') + continue; + + rc= memcached_parse_options(self, buffer, length); + + if (rc != MEMCACHED_SUCCESS) + break; + } + fclose(fp); + + return rc; }