+
+#define is_safe_file(p) 1
+
+FILE *ask_and_safe_open(const char* filename)
+{
+ FILE *r;
+ char *directory;
+ char *fn;
+ int len;
+
+ if(!isatty(0))
+ {
+ /* Argh, they are running us from a script or something. Write
+ the files to the current directory and let them burn in hell
+ for ever. */
+ directory = "."; /* get_current_directory */
+ }
+ else
+ {
+ directory = ".";
+ }
+
+ len = strlen(filename) + strlen(directory) + 2; /* 1 for the / */
+ fn = xmalloc(len);
+ snprintf(fn, len, "%s/%s", directory, filename);
+
+ if(!is_safe_file(fn))
+ {
+ fprintf(stderr, _("The file `%s' (or any of the leading directories) has unsafe permissions.\n"
+ "I will not create or overwrite this file.\n"),
+ fn);
+ return NULL;
+ }
+
+ if((r = fopen(fn, "w")) == NULL)
+ {
+ fprintf(stderr, _("Error opening file `%s': %m"),
+ fn);
+ }
+
+ free(fn);
+
+ return r;
+}