Allow 'create <filename>'.

This commit is contained in:
Lukas Ertl 2004-08-04 00:23:00 +00:00
parent b11ef345eb
commit 5c1accc9ab

View File

@ -155,32 +155,41 @@ gvinum_create(int argc, char **argv)
char original[BUFSIZ], tmpfile[20], *token[GV_MAXARGS]; char original[BUFSIZ], tmpfile[20], *token[GV_MAXARGS];
char plex[GV_MAXPLEXNAME], volume[GV_MAXVOLNAME]; char plex[GV_MAXPLEXNAME], volume[GV_MAXVOLNAME];
snprintf(tmpfile, sizeof(tmpfile), "/tmp/gvinum.XXXXXX"); if (argc == 2) {
if ((tmp = fopen(argv[1], "r")) == NULL) {
if ((fd = mkstemp(tmpfile)) == -1) { warn("can't open '%s' for reading", argv[1]);
warn("temporary file not accessible"); return;
return; }
} } else {
if ((tmp = fdopen(fd, "w")) == NULL) { snprintf(tmpfile, sizeof(tmpfile), "/tmp/gvinum.XXXXXX");
warn("can't open '%s' for writing", tmpfile);
return; if ((fd = mkstemp(tmpfile)) == -1) {
} warn("temporary file not accessible");
printconfig(tmp, "# "); return;
fclose(tmp); }
if ((tmp = fdopen(fd, "w")) == NULL) {
ed = getenv("EDITOR"); warn("can't open '%s' for writing", tmpfile);
if (ed == NULL) return;
ed = _PATH_VI; }
printconfig(tmp, "# ");
snprintf(commandline, sizeof(commandline), "%s %s", ed, tmpfile); fclose(tmp);
status = system(commandline);
if (status != 0) { ed = getenv("EDITOR");
warn("couldn't exec %s; status: %d", ed, status); if (ed == NULL)
return; ed = _PATH_VI;
}
snprintf(commandline, sizeof(commandline), "%s %s", ed,
if ((tmp = fopen(tmpfile, "r")) == NULL) { tmpfile);
warn("can't open '%s' for reading", tmpfile); status = system(commandline);
if (status != 0) {
warn("couldn't exec %s; status: %d", ed, status);
return;
}
if ((tmp = fopen(tmpfile, "r")) == NULL) {
warn("can't open '%s' for reading", tmpfile);
return;
}
} }
req = gctl_get_handle(); req = gctl_get_handle();