shopping-list

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 63d8a0b5408bdc17bf6d738bce2248d0d3b94748
parent b378b0b2bd52af6fc56fd873b68c03349061c9b9
Author: mrgrouse <mrgrouse@mrgrouse.com>
Date:   Thu, 20 Aug 2026 05:01:33 -0400

move functions to functions.c, write getconfigdir()

Diffstat:
Afunctions.c | 30++++++++++++++++++++++++++++++
Mmain.c | 6++++--
2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/functions.c b/functions.c @@ -0,0 +1,30 @@ +#include <errno.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +const char *getconfigdir(); + +const char *getconfigdir() { + static const char confdirname[] = "shoplist"; + char *XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME"); + + if (XDG_CONFIG_HOME == NULL) { + fprintf(stderr, "XDG_CONFIG_HOME not in env"); + return "X"; + } + + /* the size of the final string, + * typically "/home/user/.config/shoplist" + */ + size_t finalsize = (sizeof(char) * (strlen(XDG_CONFIG_HOME) + strlen(confdirname) + 1)); + + char *final = (char *)malloc(finalsize); + + sprintf(final, "%s/%s", XDG_CONFIG_HOME, confdirname); + + return final; + +} + diff --git a/main.c b/main.c @@ -23,7 +23,9 @@ * * */ -#include <stdio.h> + +#include "functions.c" + int main(int argc, char *argv[]) { switch (argv[1][0]) { case 'n': @@ -37,7 +39,7 @@ int main(int argc, char *argv[]) { break; case 'd': if (argc <= 3) - del_item(argv[]) + del_item(argv[]); } return 0;