8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 04: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 #ifdef WIN_NT
// MSDN says: You must explicitly flush (using fflush or _flushall) // MSDN says: You must explicitly flush (using fflush or _flushall)
// or close any stream before calling system. // 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 #endif
// If no command given just spawn a shell // If no command given just spawn a shell
if (!*shellcmd)
shellcmd = emptyCmd;
int rc = system(shellcmd);
if (!*shellcmd) {
#ifdef WIN_NT #ifdef WIN_NT
if (system("%ComSpec%")) // If we are reading from the temp file, restore the read position because
return FAIL; // it's opened in r+ mode in this case, that's R/W.
#else if (Ifp.indev_fpointer == Ofp)
if (system("$SHELL")) fsetpos(Ofp, &OfpPos);
return FAIL;
#endif #endif
}
else {
if (system(shellcmd))
return FAIL;
}
return (SKIP); return rc ? FAIL : SKIP;
} }