fix compilation on debian
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
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")]),