2 * Tools : memory management, file loading and saving
12 #include <sys/types.h>
16 #include <sys/types.h>
19 void *xmalloc(size_t size
) {
20 void *ret
= malloc(size
);
29 char *xstrdup(const char *string
) {
30 char *ret
= strdup(string
);
39 int getbool(const char *value
) {
40 if (strcmp(value
, "0") == 0) return FALSE
;
41 if (strcmp(value
, "1") == 0) return TRUE
;
42 if (strcasecmp(value
, "true") == 0) return TRUE
;
43 if (strcasecmp(value
, "false") == 0) return FALSE
;
44 if (strcasecmp(value
, "yes") == 0) return TRUE
;
45 if (strcasecmp(value
, "no") == 0) return FALSE
;
46 if (strcasecmp(value
, "on") == 0) return TRUE
;
47 if (strcasecmp(value
, "off") == 0) return FALSE
;
48 printf("Error in converting \"%s\" to boolean value.\n", value
);
55 return getenv("HOME");
56 else if (getenv("USER") && getpwnam(getenv("USER")))
57 return getpwnam (getenv ("USER") )->pw_dir
;
58 else if (getenv ("LOGNAME") && getpwnam(getenv("LOGNAME")))
59 return getpwnam(getenv("LOGNAME"))->pw_dir
;
60 else if ((getuid() != -1) && (getpwuid(getuid())))
61 return getpwuid(getuid())->pw_dir
;
67 char *get_file(const char *datestr
) {
68 char *Home
= robust_home();
69 int len
= strlen(Home
) + strlen(DEFAULT_CONFIGDIR
) + strlen(datestr
);
70 char *filename
= xmalloc(len
+ 3);
72 sprintf(filename
, "%s/%s/%s", Home
, DEFAULT_CONFIGDIR
, datestr
);