Block selection of a directory when file is needed
authorH.G. Muller <h.g.muller@hccnet.nl>
Wed, 13 Apr 2011 11:14:00 +0000 (13:14 +0200)
committerH.G. Muller <h.g.muller@hccnet.nl>
Thu, 14 Apr 2011 19:30:19 +0000 (21:30 +0200)
When we are not browsing merely to obtain a name to put in a text edit,
but really must return an open file pointer, selection of a directory
(ending in '/') can no longer be OK'ed in the file browser. (XBoard
tends to segfault when offered garbage for game or position file...)

filebrowser/selfile.c

index d3f02f3..f59e159 100644 (file)
@@ -855,8 +855,8 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed,
                                SFprepareToReturn();
                                return stderr;
                        }
                                SFprepareToReturn();
                                return stderr;
                        }
-                       if (fp = SFopenFile(*name_return, mode,
-                                           prompt, failed)) {
+                       if ((*name_return)[strlen(*name_return)-1] != '/' &&         // [HGM] refuse directories
+                           (fp = SFopenFile(*name_return, mode, prompt, failed))) {
                                SFprepareToReturn();
                                return fp;
                        }
                                SFprepareToReturn();
                                return fp;
                        }