agendafs
A filesystem for your calendar.
git clone git://mccd.space/agendafscommit 2c713772ae19d0d6cdae756c6c189a9e3c880932
parent fc64e546a15397c35b733af6e27e8406753e0ef3
Author: Marc Coquand <marc@coquand.email>
Date: Wed, 23 Jul 2025 22:12:53 +0200
Refactor
Diffstat:
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/agenda_entry.c b/agenda_entry.c
@@ -669,9 +669,7 @@ set_node_categories(memory_region *mreg, const struct tree_node *node,
return write_ical_file(mreg, node, component);
}
- char *null_terminated_categories = rmalloc(mreg, s + 1);
- strncpy(null_terminated_categories, new_categories, s);
- null_terminated_categories[s] = '\0';
+ char *null_terminated_categories = rstrndup(mreg, new_categories, s);
icalproperty *new_cat_prop =
icalproperty_new_categories(null_terminated_categories);
diff --git a/mregion.c b/mregion.c
@@ -36,6 +36,16 @@ rmalloc(memory_region *region, size_t size)
return ptr;
}
+// Copies and null terminates a string
+char *
+rstrndup(memory_region *mreg, const char *src, size_t len)
+{
+ char *buf = rmalloc(mreg, len + 1);
+ memcpy(buf, src, len);
+ buf[len] = '\0';
+ return buf;
+}
+
void
rfree_all(memory_region *region)
{
diff --git a/mregion.h b/mregion.h
@@ -33,6 +33,9 @@ void
rfree_all(memory_region *region);
char *
+rstrndup(memory_region *mreg, const char *src, size_t len);
+
+char *
rstrins(memory_region *region, const char *str, size_t offset, const char *buf,
size_t size);
// String functions