-/*
+/*
* fcgi_stdio.c --
*
* FastCGI-stdio compatibility package
*/
#ifndef lint
-static const char rcsid[] = "$Id: fcgi_stdio.c,v 1.4 1999/01/30 22:24:09 roberts Exp $";
+static const char rcsid[] = "$Id: fcgi_stdio.c,v 1.8 1999/07/28 00:24:15 roberts Exp $";
#endif /* not lint */
+#include "fcgi_config.h"
+
#ifdef _WIN32
#define DLLAPI __declspec(dllexport)
+#include <windows.h>
#endif
-#define NO_FCGI_DEFINES
-#include "fcgi_stdio.h"
-#undef NO_FCGI_DEFINES
+#include <errno.h> /* for errno */
+#include <stdarg.h> /* for va_arg */
+#include <stdlib.h> /* for malloc */
+#include <string.h> /* for strerror */
-#ifdef _WIN32
-#include <windows.h>
-#endif
-#include <errno.h>
- /* for errno */
-#include <stdarg.h>
- /* for va_arg */
-#include <stdlib.h>
- /* for malloc */
-#include <string.h>
- /* for strerror */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#define NO_FCGI_DEFINES
+#include "fcgi_stdio.h"
+#undef NO_FCGI_DEFINES
+
#include "fcgiapp.h"
#include "fcgios.h"
+#ifndef _WIN32
+
+extern char **environ;
+
+/* These definitions should be supplied by stdio.h but for some
+ * reason they get lost on certain platforms. */
+#ifndef fileno
+extern int fileno(FILE *stream);
+#endif
+
+extern FILE *fdopen(int fildes, const char *type);
+extern FILE *popen(const char *command, const char *type);
+extern int pclose(FILE *stream);
+
+#else /* _WIN32 */
+
+#define popen _popen
+
+#endif /* _WIN32 */
+
#ifndef FALSE
#define FALSE (0)
#endif
+
#ifndef TRUE
#define TRUE (1)
#endif
-#ifdef _WIN32
FCGI_FILE _fcgi_sF[3];
-#else
-FCGI_FILE _fcgi_sF[3] = {{stdin, NULL}, {stdout, NULL}, {stderr, NULL}};
-#endif
-#ifdef _WIN32
-#define popen _popen
-#endif
\f
/*
*----------------------------------------------------------------------
*/
static int acceptCalled = FALSE;
static int isCGI = FALSE;
-#ifndef _WIN32
-extern char **environ;
-#endif
int FCGI_Accept(void)
{
*/
isCGI = FCGX_IsCGI();
acceptCalled = TRUE;
+ atexit(&FCGI_Finish);
} else if(isCGI) {
/*
* Not first call to FCGI_Accept and running as CGI means
*
* FCGI_StartFilterData --
*
- *
+ *
* The current request is for the filter role, and stdin is
- * positioned at EOF of FCGI_STDIN. The call repositions
+ * positioned at EOF of FCGI_STDIN. The call repositions
* stdin to the start of FCGI_DATA.
* If the preconditions are not met (e.g. FCGI_STDIN has not
* been read to EOF), the call sets the stream error code to
* FCGX_CALL_SEQ_ERROR.
*
* Results:
- * 0 for a normal return, < 0 for error
+ * 0 for a normal return, < 0 for error
*
*----------------------------------------------------------------------
*/
* otherwise the new FCGI_FILE *.
*
*----------------------------------------------------------------------
- */
+ */
static FCGI_FILE *FCGI_OpenFromFILE(FILE *stream)
{
FCGI_FILE *fp;
if(stream == NULL)
return NULL;
- fp = malloc(sizeof(FCGI_FILE));
+ fp = (FCGI_FILE *)malloc(sizeof(FCGI_FILE));
if(fp == NULL)
return NULL;
fp->stdio_stream = stream;
else {
OS_SetErrno(ESPIPE);
return -1;
- }
+ }
}
void FCGI_rewind(FCGI_FILE *fp)
else {
OS_SetErrno(ESPIPE);
return -1;
- }
+ }
}
int FCGI_fsetpos(FCGI_FILE *fp, const fpos_t *pos)
else {
OS_SetErrno(ESPIPE);
return -1;
- }
+ }
}
#endif
\f
int c;
for (s = str; ((c = FCGI_getchar()) != '\n');) {
if(c == EOF) {
- if(s == str)
+ if(s == str)
return NULL;
else
break;
int FCGI_fputc(int c, FCGI_FILE *fp)
{
- if(fp->stdio_stream)
+ if(fp->stdio_stream)
return fputc(c, fp->stdio_stream);
else if(fp->fcgx_stream)
return FCGX_PutChar(c, fp->fcgx_stream);
{
if(fp->stdio_stream)
return vfprintf(fp->stdio_stream, format, ap);
- else if(fp->fcgx_stream)
+ else if(fp->fcgx_stream)
return FCGX_VFPrintF(fp->fcgx_stream, format, ap);
return EOF;
}
{
if(FCGI_stdout->stdio_stream)
return vfprintf(FCGI_stdout->stdio_stream, format, ap);
- else if(FCGI_stdout->fcgx_stream)
+ else if(FCGI_stdout->fcgx_stream)
return FCGX_VFPrintF(FCGI_stdout->fcgx_stream, format, ap);
return EOF;
}
*----------------------------------------------------------------------
*/
-/*
- * These definitions should be supplied by stdio.h but for some
- * reason they get lost on certain platforms.
- */
-/*
- * XXX: Need to find the right way to handle this for NT
- */
-#ifndef _WIN32
-#ifndef fileno
-extern int fileno(FILE *stream);
-#endif
-extern FILE *fdopen(int fildes, const char *type);
-extern FILE *popen(const char *command, const char *type);
-extern int pclose(FILE *stream);
-#endif
-
int FCGI_fileno(FCGI_FILE *fp)
{
if(fp->stdio_stream)