Commit 9bcbf3d02bc4085f5427204488816f3bf9ce4aec

Baptiste 2024-08-06T20:11:58

fix compilation on debian

diff --git a/libkc3/file.c b/libkc3/file.c
index dfbbdc8..70dc7f3 100644
--- a/libkc3/file.c
+++ b/libkc3/file.c
@@ -150,8 +150,7 @@ s_list ** file_list (const s_str *path, s_list **dest)
   }
   tail = &tmp;
   while ((dirent = readdir(dir))) {
-    *tail = list_new_str_alloc_copy(dirent->d_namlen,
-                                    dirent->d_name, NULL);
+    *tail = list_new_str_1_alloc(dirent->d_name, NULL);
     if (! *tail) {
       list_delete_all(tmp);
       closedir(dir);
diff --git a/libkc3/list_init.c b/libkc3/list_init.c
index c04366a..c4449c6 100644
--- a/libkc3/list_init.c
+++ b/libkc3/list_init.c
@@ -377,6 +377,18 @@ s_list * list_init_str_1 (s_list *list, char *p_free, const char *p,
   return list;
 }
 
+s_list * list_init_str_1_alloc (s_list *list, const char *p,
+                                s_list *next)
+{
+  s_list tmp = {0};
+  assert(list);
+  list_init(&tmp, next);
+  if (! tag_init_str_1_alloc(&tmp.tag, p))
+    return NULL;
+  *list = tmp;
+  return list;
+}
+
 s_list * list_init_str_alloc_copy (s_list *list, uw size,
                                    const char *p, s_list *next)
 {
@@ -1002,6 +1014,19 @@ s_list * list_new_str_1 (char *p_free, const char *p, s_list *next)
   return list;
 }
 
+s_list * list_new_str_1_alloc (const char *p, s_list *next)
+{
+  s_list *list;
+  list = list_new(next);
+  if (! list)
+    return NULL;
+  if (! tag_init_str_1_alloc(&list->tag, p)) {
+    free(list);
+    return NULL;
+  }
+  return list;
+}
+
 s_list * list_new_str_alloc_copy (uw size, const char *p, s_list *next)
 {
   s_list *list;
diff --git a/libkc3/list_init.h b/libkc3/list_init.h
index 77ffcf2..d90d614 100644
--- a/libkc3/list_init.h
+++ b/libkc3/list_init.h
@@ -58,6 +58,8 @@ s_list * list_init_str (s_list *list, char *p_free, uw size,
                         const char *p, s_list *next);
 s_list * list_init_str_1 (s_list *list, char *p_free, const char *p,
                           s_list *next);
+s_list * list_init_str_1_alloc (s_list *list, const char *p,
+                                s_list *next);
 s_list * list_init_str_alloc_copy (s_list *list, uw size,
                                    const char *p, s_list *next);
 s_list * list_init_str_concatenate (s_list *list, const s_str *a,
@@ -129,6 +131,7 @@ s_list * list_new_s64 (s64 i, s_list *next);
 s_list * list_new_str (char *p_free, uw size, const char *p,
                        s_list *next);
 s_list * list_new_str_1 (char *p_free, const char *p, s_list *next);
+s_list * list_new_str_1_alloc (const char *p, s_list *next);
 s_list * list_new_str_alloc_copy (uw size, const char *p, s_list *next);
 s_list * list_new_str_concatenate (const s_str *a, const s_str *b,
                                    s_list *next);
@@ -192,6 +195,7 @@ s_list * list_s32 (s_list *list, s32 i);
 s_list * list_s64 (s_list *list, s64 i);
 s_list * list_str (s_list *list, char *p_free, uw size, const char *p);
 s_list * list_str_1 (s_list *list, char *p_free, const char *p);
+s_list * list_str_1_alloc (s_list *list, const char *p);
 s_list * list_str_alloc_copy (s_list *list, uw size, const char *p);
 s_list * list_str_concatenate (s_list *list, const s_str *a,
                                const s_str *b);
diff --git a/libkc3/str.c b/libkc3/str.c
index 4c3bbb5..8226538 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -201,6 +201,23 @@ s_str * str_init_1 (s_str *str, char *free, const char *p)
   *str = tmp;
   return str;
 }
+
+s_str * str_init_1_alloc (s_str *str, const char *p)
+{
+  uw size;
+  s_str tmp = {0};
+  assert(str);
+  size = strlen(p);
+  tmp.free.p = alloc(size + 1);
+  if (! tmp.free.p)
+    return NULL;
+  tmp.size = size;
+  tmp.ptr.p = tmp.free.p;
+  memcpy(tmp.free.p, p, size);
+  *str = tmp;
+  return str;
+}
+
 s_str * str_init_alloc (s_str *str, uw size)
 {
   s_str tmp = {0};
diff --git a/libkc3/tag_init.c b/libkc3/tag_init.c
index 20777ac..b48a0cb 100644
--- a/libkc3/tag_init.c
+++ b/libkc3/tag_init.c
@@ -371,6 +371,17 @@ s_tag * tag_init_str_1 (s_tag *tag, char *p_free, const char *p)
   return tag;
 }
 
+s_tag * tag_init_str_1_alloc (s_tag *tag, const char *p)
+{
+  s_tag tmp = {0};
+  assert(tag);
+  tmp.type = TAG_STR;
+  if (! str_init_1_alloc(&tmp.data.str, p))
+    return NULL;
+  *tag = tmp;
+  return tag;
+}
+
 s_tag * tag_init_str_alloc_copy (s_tag *tag, uw size, const char *p)
 {
   s_tag tmp = {0};
@@ -987,6 +998,20 @@ s_tag * tag_new_str_1 (char *p_free, const char *p)
   return tag;
 }
 
+s_tag * tag_new_str_1_alloc (const char *p)
+{
+  s_tag *tag;
+  tag = alloc(sizeof(s_tag));
+  if (! tag)
+    return NULL;
+  tag->type = TAG_STR;
+  if (! str_init_1_alloc(&tag->data.str, p)) {
+    free(tag);
+    return NULL;
+  }
+  return tag;
+}
+
 s_tag * tag_new_str_alloc_copy (uw size, const char *p)
 {
   s_tag *tag;
@@ -1607,6 +1632,18 @@ s_tag * tag_str_1 (s_tag *tag, char *p_free, const char *p)
   return tag;
 }
 
+s_tag * tag_str_1_alloc (s_tag *tag, const char *p)
+{
+  s_tag tmp = {0};
+  assert(tag);
+  tag_clean(tag);
+  tmp.type = TAG_STR;
+  if (! str_init_1_alloc(&tmp.data.str, p))
+    return NULL;
+  *tag = tmp;
+  return tag;
+}
+
 s_tag * tag_str_alloc_copy (s_tag *tag, uw size, const char *p)
 {
   s_tag tmp = {0};
diff --git a/libkc3/tag_init.h b/libkc3/tag_init.h
index 4d60669..066b7cf 100644
--- a/libkc3/tag_init.h
+++ b/libkc3/tag_init.h
@@ -49,6 +49,7 @@ s_tag * tag_init_s32 (s_tag *tag, s32 i);
 s_tag * tag_init_s64 (s_tag *tag, s64 i);
 s_tag * tag_init_str (s_tag *tag, char *p_free, uw size, const char *p);
 s_tag * tag_init_str_1 (s_tag *tag, char *p_free, const char *p);
+s_tag * tag_init_str_1_alloc (s_tag *tag, const char *p);
 s_tag * tag_init_str_alloc_copy (s_tag *tag, uw size, const char *p);
 s_tag * tag_init_str_concatenate (s_tag *tag, const s_str *a,
                                   const s_str *b);
@@ -110,6 +111,7 @@ s_tag * tag_new_s32 (s32 i);
 s_tag * tag_new_s64 (s64 i);
 s_tag * tag_new_str (char *p_free, uw size, const char *p);
 s_tag * tag_new_str_1 (char *p_free, const char *p);
+s_tag * tag_new_str_1_alloc (const char *p);
 s_tag * tag_new_str_alloc_copy (uw size, const char *p);
 s_tag * tag_new_str_concatenate (const s_str *a, const s_str *b);
 s_tag * tag_new_str_concatenate_list (const s_list **src);
@@ -168,6 +170,7 @@ s_tag * tag_s32 (s_tag *tag, s32 i);
 s_tag * tag_s64 (s_tag *tag, s64 i);
 s_tag * tag_str (s_tag *tag, char *p_free, uw size, const char *p);
 s_tag * tag_str_1 (s_tag *tag, char *p_free, const char *p);
+s_tag * tag_str_1_alloc (s_tag *tag, const char *p);
 s_tag * tag_str_alloc_copy (s_tag *tag, uw size, const char *p);
 s_tag * tag_str_concatenate (s_tag *tag, const s_str *a,
                              const s_str *b);
diff --git a/libkc3/tag_init.rb b/libkc3/tag_init.rb
index 845a39a..f44ace9 100644
--- a/libkc3/tag_init.rb
+++ b/libkc3/tag_init.rb
@@ -367,6 +367,8 @@ class TagInitList
        TagInit.new("str", "1", "TAG_STR", :init_mode_init,
                    [Arg.new("char *", "p_free"),
                     Arg.new("const char *", "p")]),
+       TagInit.new("str", "1_alloc", "TAG_STR", :init_mode_init,
+                   [Arg.new("const char *", "p")]),
        TagInit.new("str", "alloc_copy", "TAG_STR", :init_mode_init,
                    [Arg.new("uw", "size"),
                     Arg.new("const char *", "p")]),