瀏覽代碼

srp_load: Can get input file name

Serj Kalichev 5 月之前
父節點
當前提交
04764da97f
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      bin/srp_load.c

+ 12 - 1
bin/srp_load.c

@@ -46,6 +46,7 @@ int main(int argc, char **argv)
 	int ret = -1;
 	pline_opts_t opts;
 	cmd_opts_t *cmd_opts = NULL;
+	int fd = STDIN_FILENO;
 
 	cmd_opts = cmd_opts_init();
 	if (cmd_opts_parse(argc, argv, cmd_opts) < 0) {
@@ -53,11 +54,21 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
+	if (cmd_opts->file) {
+		fd = open(cmd_opts->file, O_RDONLY, 0);
+		if (fd < 0) {
+			fprintf(stderr, "Error: Can't open \"%s\"\n", cmd_opts->file);
+			goto out;
+		}
+	}
+
 	pline_opts_init(&opts);
-	ret = srp_mass_set(STDIN_FILENO, cmd_opts->datastore, &opts,
+	ret = srp_mass_set(fd, cmd_opts->datastore, &opts,
 		cmd_opts->user, cmd_opts->stop_on_error);
 
 out:
+	if (cmd_opts->file)
+		close(fd);
 	cmd_opts_free(cmd_opts);
 
 	return ret;