rename this file so it is visible by metacpan et al
[catagits/fcgi2.git] / libfcgi / fcgi_stdio.c
index a4f395a..47dcc48 100644 (file)
@@ -6,45 +6,45 @@
  *
  * Copyright (c) 1996 Open Market, Inc.
  *
- * See the file "LICENSE.TERMS" for information on usage and redistribution
+ * See the file "LICENSE" for information on usage and redistribution
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: fcgi_stdio.c,v 1.9 2000/10/30 22:52:24 robs Exp $";
+static const char rcsid[] = "$Id: fcgi_stdio.c,v 1.14 2001/09/01 01:09:30 robs Exp $";
 #endif /* not lint */
 
-#include "fcgi_config.h"
-
-#ifdef _WIN32
-#define DLLAPI  __declspec(dllexport)
-#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 */
 
+#include "fcgi_config.h"
+
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#define NO_FCGI_DEFINES
-#include "fcgi_stdio.h"
-#undef NO_FCGI_DEFINES
+#ifdef _WIN32
+#define DLLAPI  __declspec(dllexport)
+#endif
 
 #include "fcgiapp.h"
 #include "fcgios.h"
+#include "fcgimisc.h"
+
+#define NO_FCGI_DEFINES
+#include "fcgi_stdio.h"
+#undef NO_FCGI_DEFINES
 
 #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
+#ifdef HAVE_FILENO_PROTO
+#include <stdio.h>
+#else
 extern int fileno(FILE *stream);
 #endif
 
@@ -59,17 +59,9 @@ extern int pclose(FILE *stream);
 
 #endif /* _WIN32 */
 
-#ifndef FALSE
-#define FALSE (0)
-#endif
-
-#ifndef TRUE
-#define TRUE  (1)
-#endif
-
 FCGI_FILE _fcgi_sF[3];
 
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -159,7 +151,7 @@ int FCGI_Accept(void)
     }
     return 0;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -196,7 +188,7 @@ void FCGI_Finish(void)
     FCGI_stderr->fcgx_stream = NULL;
     environ = NULL;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -215,7 +207,6 @@ void FCGI_Finish(void)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_StartFilterData(void)
 {
     if(FCGI_stdin->stdio_stream) {
@@ -224,7 +215,7 @@ int FCGI_StartFilterData(void)
         return FCGX_StartFilterData(FCGI_stdin->fcgx_stream);
     }
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -239,14 +230,13 @@ int FCGI_StartFilterData(void)
  *
  *----------------------------------------------------------------------
  */
-
 void FCGI_SetExitStatus(int status)
 {
     if(FCGI_stdin->fcgx_stream) {
         FCGX_SetExitStatus(status, FCGI_stdin->fcgx_stream);
     }
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -256,7 +246,6 @@ void FCGI_SetExitStatus(int status)
  *
  *----------------------------------------------------------------------
  */
-
 void FCGI_perror(const char *str)
 {
     FCGI_fputs(str, FCGI_stderr);
@@ -264,7 +253,7 @@ void FCGI_perror(const char *str)
     FCGI_fputs(strerror(OS_Errno), FCGI_stderr);
     return;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -278,7 +267,6 @@ void FCGI_perror(const char *str)
  *
  *----------------------------------------------------------------------
  */
-
 static FCGI_FILE *FCGI_OpenFromFILE(FILE *stream)
 {
     FCGI_FILE *fp;
@@ -295,7 +283,7 @@ static FCGI_FILE *FCGI_OpenFromFILE(FILE *stream)
 
     return fp;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -305,7 +293,6 @@ static FCGI_FILE *FCGI_OpenFromFILE(FILE *stream)
  *
  *----------------------------------------------------------------------
  */
-
 FCGI_FILE *FCGI_fopen(const char *path, const char *mode)
 {
     FILE * file = fopen(path, mode);
@@ -364,7 +351,7 @@ FCGI_FILE *FCGI_freopen(const char *path, const char *mode,
     }
     return NULL;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -388,7 +375,7 @@ void FCGI_setbuf(FCGI_FILE *fp, char *buf)
     if(fp->stdio_stream)
         setbuf(fp->stdio_stream, buf);
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -398,7 +385,6 @@ void FCGI_setbuf(FCGI_FILE *fp, char *buf)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_fseek(FCGI_FILE *fp, long offset, int whence)
 {
     if(fp->stdio_stream)
@@ -448,7 +434,7 @@ int FCGI_fsetpos(FCGI_FILE *fp, const fpos_t *pos)
     }
 }
 #endif
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -461,7 +447,6 @@ int FCGI_fsetpos(FCGI_FILE *fp, const fpos_t *pos)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_fgetc(FCGI_FILE *fp)
 {
     if(fp->stdio_stream)
@@ -484,7 +469,7 @@ int FCGI_ungetc(int c, FCGI_FILE *fp)
         return FCGX_UnGetChar(c, fp->fcgx_stream);
     return EOF;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -494,7 +479,6 @@ int FCGI_ungetc(int c, FCGI_FILE *fp)
  *
  *----------------------------------------------------------------------
  */
-
 char *FCGI_fgets(char *str, int size, FCGI_FILE *fp)
 {
     if(fp->stdio_stream)
@@ -505,15 +489,16 @@ char *FCGI_fgets(char *str, int size, FCGI_FILE *fp)
 }
 
 /*
- * There is no standard equivalent of gets that takes an explicit
- * FILE * argument, so the following "wrapper" implements
- * gets for both FILE * and FCGX_Stream * in terms of FCGI_getchar.
+ * The gets() function reads characters from the standard input stream
+ * into the array pointed to by str until a newline character is read
+ * or an end-of-file condition is encountered.  The newline character
+ * is discarded and the string is terminated with a null character. 
  */
-
 char *FCGI_gets(char *str)
 {
     char *s;
     int c;
+
     for (s = str; ((c = FCGI_getchar()) != '\n');) {
         if(c == EOF) {
             if(s == str)
@@ -521,17 +506,15 @@ char *FCGI_gets(char *str)
             else
                 break;
         } else
-            *s++ = c;
+            *s++ = (char) c;
     }
     *s = 0;
     return str;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
- * --
- *
  *       Wrappers for functions defined in H&S Section 15.8
  *
  *       XXX: missing: fscanf, scanf
@@ -539,7 +522,6 @@ char *FCGI_gets(char *str)
  *----------------------------------------------------------------------
  */
 
-\f
 /*
  *----------------------------------------------------------------------
  *
@@ -552,7 +534,6 @@ char *FCGI_gets(char *str)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_fputc(int c, FCGI_FILE *fp)
 {
     if(fp->stdio_stream)
@@ -566,7 +547,7 @@ int FCGI_putchar(int c)
 {
     return FCGI_fputc(c, FCGI_stdout);
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -576,7 +557,6 @@ int FCGI_putchar(int c)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_fputs(const char *str, FCGI_FILE *fp)
 {
     if(fp->stdio_stream)
@@ -604,7 +584,7 @@ int FCGI_puts(const char *str)
     }
     return EOF;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -614,7 +594,6 @@ int FCGI_puts(const char *str)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_fprintf(FCGI_FILE *fp, const char *format, ...)
 {
     va_list ap;
@@ -637,7 +616,7 @@ int FCGI_printf(const char *format, ...)
     va_end(ap);
     return n;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -647,7 +626,6 @@ int FCGI_printf(const char *format, ...)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_vfprintf(FCGI_FILE *fp, const char *format, va_list ap)
 {
     if(fp->stdio_stream)
@@ -665,7 +643,7 @@ int FCGI_vprintf(const char *format, va_list ap)
         return FCGX_VFPrintF(FCGI_stdout->fcgx_stream, format, ap);
     return EOF;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -675,7 +653,6 @@ int FCGI_vprintf(const char *format, va_list ap)
  *
  *----------------------------------------------------------------------
  */
-
 size_t FCGI_fread(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp)
 {
     int n;
@@ -705,7 +682,7 @@ size_t FCGI_fwrite(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp)
     }
     return (size_t)EOF;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -745,7 +722,7 @@ void FCGI_clearerr(FCGI_FILE *fp)
     }
     return;
 }
-\f
+
 /*
  *----------------------------------------------------------------------
  *
@@ -766,7 +743,6 @@ FCGI_FILE *FCGI_tmpfile(void)
     return fcgi_file;
 }
 
-\f
 /*
  *----------------------------------------------------------------------
  *
@@ -776,7 +752,6 @@ FCGI_FILE *FCGI_tmpfile(void)
  *
  *----------------------------------------------------------------------
  */
-
 int FCGI_fileno(FCGI_FILE *fp)
 {
     if(fp->stdio_stream)
@@ -824,7 +799,3 @@ int FCGI_pclose(FCGI_FILE *fp)
     }
     return n;
 }
-
-/*
- *----------------------------------------------------------------------
- */