Back to index

lightning-sunbird  0.9+nobinonly
w16stdio.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037  
00038 /*
00039 ** w16stdio.c -- Callback functions for Win16 stdio read/write.
00040 **
00041 **
00042 */
00043 #include "primpl.h"
00044 
00045 /*
00046 ** _PL_MDStdioWrite() -- Win16 hackery to get console output
00047 **
00048 ** Returns: number of bytes written.
00049 **
00050 */
00051 PRInt32
00052 _PL_W16StdioWrite( void *buf, PRInt32 amount )
00053 {
00054     int   rc;
00055     
00056     rc = fputs( buf, stdout );
00057     if ( rc == EOF )
00058     {
00059         // something about errno
00060         return(PR_FAILURE);
00061     }
00062     return( strlen(buf));
00063 } /* end _PL_fputs() */
00064 
00065 /*
00066 ** _PL_W16StdioRead() -- Win16 hackery to get console input
00067 **
00068 */
00069 PRInt32
00070 _PL_W16StdioRead( void *buf, PRInt32 amount )
00071 {
00072     char *bp;
00073 
00074     bp = fgets( buf, (int) amount, stdin );
00075     if ( bp == NULL )
00076     {
00077         // something about errno
00078         return(PR_FAILURE);
00079     }
00080     
00081     return( strlen(buf));
00082 } /* end _PL_fgets() */
00083 /* --- end w16stdio.c --- */
00084 
00085 /*
00086 ** Wrappers, linked into the client, that call
00087 ** functions in LibC
00088 **
00089 */
00090 
00091 /*
00092 ** _PL_W16CallBackPuts() -- Wrapper for puts()
00093 **
00094 */
00095 int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString )
00096 {
00097     return( puts( outputString ));
00098 } /* end _PL_W16CallBackPuts()  */    
00099 
00100 /*
00101 ** _PL_W16CallBackStrftime() -- Wrapper for strftime()
00102 **
00103 */
00104 size_t PR_CALLBACK _PL_W16CallBackStrftime( 
00105     char *s, 
00106     size_t len, 
00107     const char *fmt,
00108     const struct tm *p )
00109 {
00110     return( strftime( s, len, fmt, p ));
00111 } /* end _PL_W16CallBackStrftime()  */    
00112 
00113 /*
00114 ** _PL_W16CallBackMalloc() -- Wrapper for malloc()
00115 **
00116 */
00117 void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size )
00118 {
00119     return( malloc( size ));
00120 } /* end _PL_W16CallBackMalloc()  */    
00121 
00122 /*
00123 ** _PL_W16CallBackCalloc() -- Wrapper for calloc()
00124 **
00125 */
00126 void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size )
00127 {
00128     return( calloc( n, size ));
00129 } /* end _PL_W16CallBackCalloc()  */    
00130 
00131 /*
00132 ** _PL_W16CallBackRealloc() -- Wrapper for realloc()
00133 **
00134 */
00135 void * PR_CALLBACK _PL_W16CallBackRealloc( 
00136     void *old_blk, 
00137     size_t size )
00138 {
00139     return( realloc( old_blk, size ));
00140 } /* end _PL_W16CallBackRealloc()  */
00141 
00142 /*
00143 ** _PL_W16CallBackFree() -- Wrapper for free()
00144 **
00145 */
00146 void PR_CALLBACK _PL_W16CallBackFree( void *ptr )
00147 {
00148     free( ptr );
00149     return;
00150 } /* end _PL_W16CallBackFree()  */
00151 
00152 /*
00153 ** _PL_W16CallBackGetenv() -- Wrapper for getenv()
00154 **
00155 */
00156 void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name )
00157 {
00158     return( getenv( name ));
00159 } /* end _PL_W16CallBackGetenv  */
00160 
00161 
00162 /*
00163 ** _PL_W16CallBackPutenv() -- Wrapper for putenv()
00164 **
00165 */
00166 int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc )
00167 {
00168     return( putenv( assoc ));
00169 } /* end _PL_W16CallBackGetenv  */