8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 22:03:03 +01:00

Fix premature EOF while reading a script file when using the SHELL command inside it, found by Paul Reeves. Trying to find a compromise between MS requirements for system() call and its bad side effects on our isql.

This commit is contained in:
robocop 2005-09-03 05:54:27 +00:00
parent f58ecb7e68
commit d7f1979164

View File

@ -3429,26 +3429,31 @@ static processing_state escape(const TEXT* cmd)
#ifdef WIN_NT
// MSDN says: You must explicitly flush (using fflush or _flushall)
// or close any stream before calling system.
_flushall();
// CVC: But that function defeats our possible several input streams opened.
//_flushall();
// Save Ofp position in case it's being used as input. See EDIT command.
fpos_t OfpPos = 0;
fgetpos(Ofp, &OfpPos);
fflush(NULL); // Flush only output buffers.
const char* emptyCmd = "%ComSpec%";
#else
const char* emptyCmd = "$SHELL";
#endif
// If no command given just spawn a shell
if (!*shellcmd)
shellcmd = emptyCmd;
int rc = system(shellcmd);
if (!*shellcmd) {
#ifdef WIN_NT
if (system("%ComSpec%"))
return FAIL;
#else
if (system("$SHELL"))
return FAIL;
// If we are reading from the temp file, restore the read position because
// it's opened in r+ mode in this case, that's R/W.
if (Ifp.indev_fpointer == Ofp)
fsetpos(Ofp, &OfpPos);
#endif
}
else {
if (system(shellcmd))
return FAIL;
}
return (SKIP);
return rc ? FAIL : SKIP;
}