diff options
author | Jin Yoon <jinny.yoon@samsung.com> | 2017-08-29 17:15:56 +0900 |
---|---|---|
committer | Jin Yoon <jinny.yoon@samsung.com> | 2017-08-29 17:15:56 +0900 |
commit | c7be84bcd2468c7f129be33af0b30a705aed0a2c (patch) | |
tree | 073b1e4426a3eaf2df0ebc82efd64bbd4ae9e137 | |
parent | b888e2837b7c763f8e3cf1b01309906159770143 (diff) | |
download | position-finder-server-c7be84bcd2468c7f129be33af0b30a705aed0a2c.tar.gz position-finder-server-c7be84bcd2468c7f129be33af0b30a705aed0a2c.tar.bz2 position-finder-server-c7be84bcd2468c7f129be33af0b30a705aed0a2c.zip |
Use CBOR file after copying it
-rw-r--r-- | src/connectivity.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/connectivity.c b/src/connectivity.c index f5d9fe3..9410f3c 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -388,18 +388,60 @@ error: _send_response(request, NULL, IOTCON_RESPONSE_ERROR); } +static void _copy_file(const char *in_filename, const char *out_filename) +{ + char buf[BUFSIZE] = { 0, }; + size_t nread = 0; + FILE *in = NULL; + FILE *out = NULL; + + ret_if(!in_filename); + ret_if(!out_filename); + + in = fopen(in_filename, "r"); + ret_if(!in); + + out = fopen(out_filename, "w"); + goto_if(!out, error); + + rewind(in); + while ((nread = fread(buf, 1, sizeof(buf), in)) > 0) { + if (fwrite (buf, 1, nread, out) < nread) { + _E("critical error to copy a file"); + break; + } + } + + fclose(in); + fclose(out); + + return; + +error: + fclose(out); +} + int connectivity_init(void) { int ret = -1; char buf[PATH_MAX] = {0,}; + char data[PATH_MAX] = {0,}; char *prefix = NULL; prefix = app_get_resource_path(); retv_if(!prefix, -1); snprintf(buf, sizeof(buf)-1, "%s%s", prefix, "iotcon-test-svr-db-server.dat"); free(prefix); + prefix = NULL; + + prefix = app_get_data_path(); + retv_if(!prefix, -1); + snprintf(data, sizeof(data)-1, "%s%s", prefix, "iotcon-test-svr-db-server.dat"); + free(prefix); + + _copy_file(buf, data); - ret = iotcon_initialize(buf); + ret = iotcon_initialize(data); retv_if(IOTCON_ERROR_NONE != ret, -1); ret = iotcon_set_device_name(ULTRASONIC_RESOURCE_TYPE); |