functions.c (943B)
1 #include <errno.h> 2 #include <stddef.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 const char *getconfigdir(); 8 void new_list(char *sarg) { 9 return; 10 } 11 void list_items(char *sarg) { 12 return; 13 } 14 void add_item(char *sarg, char *narg) { 15 return; 16 } 17 void del_item(char *fargv) { 18 return; 19 } 20 /* TODO: 21 * new_list(argv[2]) 22 * list_items(argv[2]) 23 * add_item(argv[2], argv[3]) 24 * del_item(argv[?]) 25 */ 26 27 const char *getconfigdir() { 28 static const char confdirname[] = "shoplist"; 29 char *XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME"); 30 31 if (XDG_CONFIG_HOME == NULL) { 32 fprintf(stderr, "XDG_CONFIG_HOME not in env"); 33 return "X"; 34 } 35 36 /* the size of the final string, 37 * typically "/home/user/.config/shoplist" 38 */ 39 size_t finalsize = 40 (sizeof(char) * (strlen(XDG_CONFIG_HOME) + strlen(confdirname) + 1)); 41 42 char *final = malloc(finalsize); 43 44 sprintf(final, "%s/%s", XDG_CONFIG_HOME, confdirname); 45 46 return final; 47 }