agendafs
A filesystem for your calendar.
git clone git://mccd.space/agendafscommit 14f9a718a0e5503115702044bcea54fc34788fe3
parent d054c04831aa11cf98359551f1d71f1a4e6170cb
Author: Marc Coquand <marc@coquand.email>
Date: Sun, 1 Jun 2025 20:09:52 +0100
Simplify
Diffstat:
| M | main.c | | | 26 | +++++++++++--------------- |
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/main.c b/main.c
@@ -806,38 +806,34 @@ timestamp_from_filename(const char *filename)
const char *basename = strrchr(filename, '/');
if (basename != NULL) {
- basename++; // Skip the '/' to get the actual filename
+ basename++;
}
else {
- basename = filename; // No path, use the original filename
+ basename = filename;
}
- regmatch_t matches[4];
+ regmatch_t matches[3];
- int ret = regexec(®ex_fuse_file, basename, 4, matches, 0);
- if (ret != 0)
+ if (regexec(®ex_fuse_file, basename, 3, matches, 0) != 0)
return INVALID_TIME;
// Extract YYYYMMDD and HH:MM
char date_str[9] = {0};
char time_str[6] = {0};
- int len_date = matches[1].rm_eo - matches[1].rm_so;
- int len_time = matches[2].rm_eo - matches[2].rm_so;
-
- if (len_date != 8 || len_time != 5)
- return (time_t)-1;
-
- strncpy(date_str, basename + matches[1].rm_so, len_date);
- strncpy(time_str, basename + matches[2].rm_so, len_time);
+ snprintf(date_str, sizeof(date_str), "%.*s",
+ matches[1].rm_eo - matches[1].rm_so,
+ basename + matches[1].rm_so);
+ snprintf(time_str, sizeof(time_str), "%.*s",
+ matches[2].rm_eo - matches[2].rm_so,
+ basename + matches[2].rm_so);
int year, month, day, hour, minute;
-
if (sscanf(date_str, "%4d%2d%2d", &year, &month, &day) != 3)
return INVALID_TIME;
if (sscanf(time_str, "%2d:%2d", &hour, &minute) != 2)
- return (time_t)-1;
+ return INVALID_TIME;
struct tm tm_time = {0};
tm_time.tm_year = year - 1900;