Changeset: 3d70937457e4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3d70937457e4
Modified Files:
clients/mapiclient/mclient.c
Branch: Apr2019
Log Message:
If first non-option arg can be opened but is not a file, treat it as database
name.
This extends the case where the arg cannot be opened and is then
treated as database name.
diffs (40 lines):
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -27,6 +27,7 @@
#ifdef HAVE_STRINGS_H
#include <strings.h> /* strcasecmp */
#endif
+#include <sys/stat.h>
#ifdef HAVE_LIBREADLINE
#include <readline/readline.h>
@@ -3242,6 +3243,18 @@ usage(const char *prog, int xit)
/* hardwired defaults, only used if monet environment cannot be found */
#define defaultPort 50000
+static inline bool
+isfile(FILE *fp)
+{
+ struct stat stb;
+ if (fstat(fileno(fp), &stb) < 0 ||
+ (stb.st_mode & S_IFMT) != S_IFREG) {
+ fclose(fp);
+ return false;
+ }
+ return true;
+}
+
int
main(int argc, char **argv)
{
@@ -3560,7 +3573,8 @@ main(int argc, char **argv)
has_fileargs = optind != argc;
if (dbname == NULL && has_fileargs &&
- (fp = fopen(argv[optind], "r")) == NULL) {
+ ((fp = fopen(argv[optind], "r")) == NULL || !isfile(fp))) {
+ fp = NULL;
dbname = strdup(argv[optind]);
optind++;
has_fileargs = optind != argc;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list