Parcourir la source

srp_load: Can get input file name

Serj Kalichev il y a 11 mois
Parent
commit
04764da97f
1 fichiers modifiés avec 12 ajouts et 1 suppressions
  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;