Browse Source

ncd/modules/file.c: support non-ContinuousString strings

ambrop7 13 years ago
parent
commit
9e780ac2f7
1 changed files with 10 additions and 5 deletions
  1. 10 5
      ncd/modules/file.c

+ 10 - 5
ncd/modules/file.c

@@ -189,7 +189,8 @@ static void write_func_new (void *unused, NCDModuleInst *i, const struct NCDModu
     }
     }
     
     
     // write file
     // write file
-    int res = write_file(filename_nts.data, (const uint8_t *)NCDVal_StringData(contents_arg), NCDVal_StringLength(contents_arg));
+    b_cstring contents_cstr = NCDVal_StringCstring(contents_arg);
+    int res = write_file_cstring(filename_nts.data, contents_cstr, 0, contents_cstr.length);
     NCDValNullTermString_Free(&filename_nts);
     NCDValNullTermString_Free(&filename_nts);
     if (!res) {
     if (!res) {
         ModuleLog(i, BLOG_ERROR, "failed to write file");
         ModuleLog(i, BLOG_ERROR, "failed to write file");
@@ -321,20 +322,24 @@ static struct NCDModule modules[] = {
         .func_new2 = read_func_new,
         .func_new2 = read_func_new,
         .func_die = read_func_die,
         .func_die = read_func_die,
         .func_getvar2 = read_func_getvar2,
         .func_getvar2 = read_func_getvar2,
-        .alloc_size = sizeof(struct read_instance)
+        .alloc_size = sizeof(struct read_instance),
+        .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
     }, {
     }, {
         .type = "file_write",
         .type = "file_write",
-        .func_new2 = write_func_new
+        .func_new2 = write_func_new,
+        .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
     }, {
     }, {
         .type = "file_stat",
         .type = "file_stat",
         .func_new2 = stat_func_new,
         .func_new2 = stat_func_new,
         .func_getvar2 = stat_func_getvar2,
         .func_getvar2 = stat_func_getvar2,
-        .alloc_size = sizeof(struct stat_instance)
+        .alloc_size = sizeof(struct stat_instance),
+        .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
     }, {
     }, {
         .type = "file_lstat",
         .type = "file_lstat",
         .func_new2 = lstat_func_new,
         .func_new2 = lstat_func_new,
         .func_getvar2 = stat_func_getvar2,
         .func_getvar2 = stat_func_getvar2,
-        .alloc_size = sizeof(struct stat_instance)
+        .alloc_size = sizeof(struct stat_instance),
+        .flags = NCDMODULE_FLAG_ACCEPT_NON_CONTINUOUS_STRINGS
     }, {
     }, {
         .type = NULL
         .type = NULL
     }
     }