Write unix configuration to .cgminer/cgminer.conf by default and prompt to overwrite if given a filename from the menu that exists.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/main.c b/main.c
index ebe0fc7..a372db4 100644
--- a/main.c
+++ b/main.c
@@ -25,6 +25,10 @@
#include <stdarg.h>
#include <assert.h>
#include <signal.h>
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
#ifndef WIN32
#include <sys/resource.h>
#endif
@@ -45,9 +49,7 @@
#if defined(unix)
#include <errno.h>
#include <fcntl.h>
- #include <unistd.h>
#include <sys/wait.h>
- #include <sys/types.h>
#endif
#ifdef __linux /* Linux specific policy and affinity management */
@@ -1726,9 +1728,17 @@ static char *load_config(const char *arg, void *unused)
static void load_default_config(void)
{
char buf[PATH_MAX];
+
+#if defined(unix)
strcpy(buf, getenv("HOME"));
if (*buf)
strcat(buf, "/");
+ else
+ strcpy(buf, "");
+ strcat(buf, ".cgminer/");
+#else
+ strcpy(buf, "");
+#endif
strcat(buf, def_conf);
if (!access(buf, R_OK))
load_config(buf, NULL);
@@ -3387,16 +3397,35 @@ retry:
opt_fail_pause = selected;
goto retry;
} else if (!strncasecmp(&input, "w", 1)) {
- char filename[PATH_MAX], prompt[PATH_MAX+50];
+ FILE *fcfg;
+ char *str, filename[PATH_MAX], prompt[PATH_MAX + 50];
+
+#if defined(unix)
strcpy(filename, getenv("HOME"));
if (*filename)
strcat(filename, "/");
+ else
+ strcpy(filename, "");
+ strcat(filename, ".cgminer/");
+ mkdir(filename, 0777);
+#else
+ strcpy(filename, "");
+#endif
strcat(filename, def_conf);
sprintf(prompt, "Config filename to write (Enter for default) [%s]", filename);
- char *str = curses_input(prompt);
- if (strcmp(str, "-1"))
+ str = curses_input(prompt);
+ if (strcmp(str, "-1")) {
+ struct stat statbuf;
+
strcpy(filename, str);
- FILE *fcfg = fopen(filename, "w");
+ if (!stat(filename, &statbuf)) {
+ wlogprint("File exists, overwrite?\n");
+ input = getch();
+ if (strncasecmp(&input, "y", 1))
+ goto retry;
+ }
+ }
+ fcfg = fopen(filename, "w");
if (!fcfg) {
wlogprint("Cannot open or create file\n");
goto retry;