You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by cm...@collab.net on 2001/01/27 07:25:25 UTC

[patch] new function apr_open_stdout()

* apr_file_io.h: Prototype for new function apr_open_stdout() added.

* unix/open.c: Added function apr_open_stdout(), shamelessly copy-n-
               pasted-n-tweaked from apr_open_stderr().

* win32/open.c: Modified apr_open_stderr() to call apr_put_os_file()
                like all the other OSes do.  Also added new function
                apr_open_stdout(), shamelessly copy-n-pasted-n-tweaked
                from the freshly modified apr_open_stderr().

* os2/open.c: Added function apr_open_stdout(), shamelessly copy-n-
              pasted-n-tweaked from apr_open_stderr().  The tiny little
              catch is that the "tweak" stage of this procedure is
              100% guesswork -- OS/2 GURUS:  Please validate that stdout
              is file descriptor 1.


Index: apr/file_io/os2/open.c
===================================================================
RCS file: /home/cvspublic/apr/file_io/os2/open.c,v
retrieving revision 1.36
diff -u -r1.36 open.c
--- apr/file_io/os2/open.c      2001/01/26 09:05:44     1.36
+++ apr/file_io/os2/open.c      2001/01/27 05:57:09
@@ -251,4 +251,14 @@
     return apr_put_os_file(thefile, &fd, cont);
 }
 
+
+
+apr_status_t apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
+{
+    int fd = 1; /* Is this correct? */
+
+    return apr_put_os_file(thefile, &fd, cont);
+}
+
+
 APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
Index: apr/file_io/unix/open.c
===================================================================
RCS file: /home/cvspublic/apr/file_io/unix/open.c,v
retrieving revision 1.69
diff -u -r1.69 open.c
--- apr/file_io/unix/open.c     2001/01/26 09:05:48     1.69
+++ apr/file_io/unix/open.c     2001/01/27 05:57:09
@@ -254,4 +254,11 @@
     return apr_put_os_file(thefile, &fd, cont);
 }
 
+apr_status_t apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
+{
+    int fd = STDOUT_FILENO;
+
+    return apr_put_os_file(thefile, &fd, cont);
+}
+
 APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
Index: apr/file_io/win32/open.c
===================================================================
RCS file: /home/cvspublic/apr/file_io/win32/open.c,v
retrieving revision 1.67
diff -u -r1.67 open.c
--- apr/file_io/win32/open.c    2001/01/26 09:05:55     1.67
+++ apr/file_io/win32/open.c    2001/01/27 05:57:11
@@ -417,23 +417,24 @@
 
 APR_DECLARE(apr_status_t) apr_open_stderr(apr_file_t **thefile, apr_pool_t *cont)
 {
-    /* ### should this be rebuilt in terms of apr_put_os_file()?? their
-       ### initializations are slightly different (maybe one or both are
-       ### not init'ing properly?)
-    */
+    apr_os_file_t file_handle;
 
-    (*thefile) = apr_pcalloc(cont, sizeof(apr_file_t));
-    if ((*thefile) == NULL) {
-        return APR_ENOMEM;
-    }
-    (*thefile)->filehand = GetStdHandle(STD_ERROR_HANDLE);
-    if ((*thefile)->filehand == INVALID_HANDLE_VALUE)
+    file_handle = GetStdHandle(STD_ERROR_HANDLE);
+    if (file_handle == INVALID_HANDLE_VALUE)
         return apr_get_os_error();
-    (*thefile)->cntxt = cont;
-    (*thefile)->fname = "\0"; // What was this??? : "STD_ERROR_HANDLE"; */
-    (*thefile)->eof_hit = 0;
 
-    return APR_SUCCESS;
+    return apr_put_os_file(thefile, &file_handle, cont);
+}
+
+APR_DECLARE(apr_status_t) apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
+{
+    apr_os_file_t file_handle;
+
+    file_handle = GetStdHandle(STD_OUTPUT_HANDLE);
+    if (file_handle == INVALID_HANDLE_VALUE)
+        return apr_get_os_error();
+
+    return apr_put_os_file(thefile, &file_handle, cont);
 }
 
 APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
Index: apr/include/apr_file_io.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_file_io.h,v
retrieving revision 1.92
diff -u -r1.92 apr_file_io.h
--- apr/include/apr_file_io.h   2001/01/24 08:26:19     1.92
+++ apr/include/apr_file_io.h   2001/01/27 05:57:15
@@ -200,6 +200,15 @@
                                           apr_pool_t *cont);
 
 /**
+ * open standard output as an apr file pointer.
+ * @param thefile The apr file to use as stdout.
+ * @param cont The pool to allocate the file out of.
+ * @deffunc apr_status_t apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
+ */
+APR_DECLARE(apr_status_t) apr_open_stdout(apr_file_t **thefile,
+                                          apr_pool_t *cont);
+
+/**
  * Read data from the specified file.
  * @param thefile The file descriptor to read from.
  * @param buf The buffer to store the data to.

Re: [patch] new function apr_open_stdout()

Posted by rb...@covalent.net.
Good looking patch.  I'm not going to commit it tonight, but if nobody
gets to it before tomorrow, I'll do it then.

Thanks a lot, and keep up the good work.  :-)

Ryan

On 27 Jan 2001 cmpilato@collab.net wrote:

> * apr_file_io.h: Prototype for new function apr_open_stdout() added.
> 
> * unix/open.c: Added function apr_open_stdout(), shamelessly copy-n-
>                pasted-n-tweaked from apr_open_stderr().
> 
> * win32/open.c: Modified apr_open_stderr() to call apr_put_os_file()
>                 like all the other OSes do.  Also added new function
>                 apr_open_stdout(), shamelessly copy-n-pasted-n-tweaked
>                 from the freshly modified apr_open_stderr().
> 
> * os2/open.c: Added function apr_open_stdout(), shamelessly copy-n-
>               pasted-n-tweaked from apr_open_stderr().  The tiny little
>               catch is that the "tweak" stage of this procedure is
>               100% guesswork -- OS/2 GURUS:  Please validate that stdout
>               is file descriptor 1.
> 
> 
> Index: apr/file_io/os2/open.c
> ===================================================================
> RCS file: /home/cvspublic/apr/file_io/os2/open.c,v
> retrieving revision 1.36
> diff -u -r1.36 open.c
> --- apr/file_io/os2/open.c      2001/01/26 09:05:44     1.36
> +++ apr/file_io/os2/open.c      2001/01/27 05:57:09
> @@ -251,4 +251,14 @@
>      return apr_put_os_file(thefile, &fd, cont);
>  }
>  
> +
> +
> +apr_status_t apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
> +{
> +    int fd = 1; /* Is this correct? */
> +
> +    return apr_put_os_file(thefile, &fd, cont);
> +}
> +
> +
>  APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
> Index: apr/file_io/unix/open.c
> ===================================================================
> RCS file: /home/cvspublic/apr/file_io/unix/open.c,v
> retrieving revision 1.69
> diff -u -r1.69 open.c
> --- apr/file_io/unix/open.c     2001/01/26 09:05:48     1.69
> +++ apr/file_io/unix/open.c     2001/01/27 05:57:09
> @@ -254,4 +254,11 @@
>      return apr_put_os_file(thefile, &fd, cont);
>  }
>  
> +apr_status_t apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
> +{
> +    int fd = STDOUT_FILENO;
> +
> +    return apr_put_os_file(thefile, &fd, cont);
> +}
> +
>  APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
> Index: apr/file_io/win32/open.c
> ===================================================================
> RCS file: /home/cvspublic/apr/file_io/win32/open.c,v
> retrieving revision 1.67
> diff -u -r1.67 open.c
> --- apr/file_io/win32/open.c    2001/01/26 09:05:55     1.67
> +++ apr/file_io/win32/open.c    2001/01/27 05:57:11
> @@ -417,23 +417,24 @@
>  
>  APR_DECLARE(apr_status_t) apr_open_stderr(apr_file_t **thefile, apr_pool_t *cont)
>  {
> -    /* ### should this be rebuilt in terms of apr_put_os_file()?? their
> -       ### initializations are slightly different (maybe one or both are
> -       ### not init'ing properly?)
> -    */
> +    apr_os_file_t file_handle;
>  
> -    (*thefile) = apr_pcalloc(cont, sizeof(apr_file_t));
> -    if ((*thefile) == NULL) {
> -        return APR_ENOMEM;
> -    }
> -    (*thefile)->filehand = GetStdHandle(STD_ERROR_HANDLE);
> -    if ((*thefile)->filehand == INVALID_HANDLE_VALUE)
> +    file_handle = GetStdHandle(STD_ERROR_HANDLE);
> +    if (file_handle == INVALID_HANDLE_VALUE)
>          return apr_get_os_error();
> -    (*thefile)->cntxt = cont;
> -    (*thefile)->fname = "\0"; // What was this??? : "STD_ERROR_HANDLE"; */
> -    (*thefile)->eof_hit = 0;
>  
> -    return APR_SUCCESS;
> +    return apr_put_os_file(thefile, &file_handle, cont);
> +}
> +
> +APR_DECLARE(apr_status_t) apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
> +{
> +    apr_os_file_t file_handle;
> +
> +    file_handle = GetStdHandle(STD_OUTPUT_HANDLE);
> +    if (file_handle == INVALID_HANDLE_VALUE)
> +        return apr_get_os_error();
> +
> +    return apr_put_os_file(thefile, &file_handle, cont);
>  }
>  
>  APR_POOL_IMPLEMENT_ACCESSOR_X(file, cntxt);
> Index: apr/include/apr_file_io.h
> ===================================================================
> RCS file: /home/cvspublic/apr/include/apr_file_io.h,v
> retrieving revision 1.92
> diff -u -r1.92 apr_file_io.h
> --- apr/include/apr_file_io.h   2001/01/24 08:26:19     1.92
> +++ apr/include/apr_file_io.h   2001/01/27 05:57:15
> @@ -200,6 +200,15 @@
>                                            apr_pool_t *cont);
>  
>  /**
> + * open standard output as an apr file pointer.
> + * @param thefile The apr file to use as stdout.
> + * @param cont The pool to allocate the file out of.
> + * @deffunc apr_status_t apr_open_stdout(apr_file_t **thefile, apr_pool_t *cont)
> + */
> +APR_DECLARE(apr_status_t) apr_open_stdout(apr_file_t **thefile,
> +                                          apr_pool_t *cont);
> +
> +/**
>   * Read data from the specified file.
>   * @param thefile The file descriptor to read from.
>   * @param buf The buffer to store the data to.
> 
> 


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------