home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / src / md / windows / w16stdio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.4 KB  |  151 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20. ** w16stdio.c -- Callback functions for Win16 stdio read/write.
  21. **
  22. **
  23. */
  24. #include "primpl.h"
  25.  
  26. /*
  27. ** _PL_MDStdioWrite() -- Win16 hackery to get console output
  28. **
  29. ** Returns: number of bytes written.
  30. **
  31. */
  32. PRInt32
  33. _PL_W16StdioWrite( void *buf, PRInt32 amount )
  34. {
  35.     int   rc;
  36.     
  37.     rc = fputs( buf, stdout );
  38.     if ( rc == EOF )
  39.     {
  40.         // something about errno
  41.         return(PR_FAILURE);
  42.     }
  43.     return( strlen(buf));
  44. } /* end _PL_fputs() */
  45.  
  46. /*
  47. ** _PL_W16StdioRead() -- Win16 hackery to get console input
  48. **
  49. */
  50. PRInt32
  51. _PL_W16StdioRead( void *buf, PRInt32 amount )
  52. {
  53.     char *bp;
  54.  
  55.     bp = fgets( buf, (int) amount, stdin );
  56.     if ( bp == NULL )
  57.     {
  58.         // something about errno
  59.         return(PR_FAILURE);
  60.     }
  61.     
  62.     return( strlen(buf));
  63. } /* end _PL_fgets() */
  64. /* --- end w16stdio.c --- */
  65.  
  66. /*
  67. ** Wrappers, linked into the client, that call
  68. ** functions in LibC
  69. **
  70. */
  71.  
  72. /*
  73. ** _PL_W16CallBackPuts() -- Wrapper for puts()
  74. **
  75. */
  76. int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString )
  77. {
  78.     return( puts( outputString ));
  79. } /* end _PL_W16CallBackPuts()  */    
  80.  
  81. /*
  82. ** _PL_W16CallBackStrftime() -- Wrapper for strftime()
  83. **
  84. */
  85. size_t PR_CALLBACK _PL_W16CallBackStrftime( 
  86.     char *s, 
  87.     size_t len, 
  88.     const char *fmt,
  89.     const struct tm *p )
  90. {
  91.     return( strftime( s, len, fmt, p ));
  92. } /* end _PL_W16CallBackStrftime()  */    
  93.  
  94. /*
  95. ** _PL_W16CallBackMalloc() -- Wrapper for malloc()
  96. **
  97. */
  98. void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size )
  99. {
  100.     return( malloc( size ));
  101. } /* end _PL_W16CallBackMalloc()  */    
  102.  
  103. /*
  104. ** _PL_W16CallBackCalloc() -- Wrapper for calloc()
  105. **
  106. */
  107. void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size )
  108. {
  109.     return( calloc( n, size ));
  110. } /* end _PL_W16CallBackCalloc()  */    
  111.  
  112. /*
  113. ** _PL_W16CallBackRealloc() -- Wrapper for realloc()
  114. **
  115. */
  116. void * PR_CALLBACK _PL_W16CallBackRealloc( 
  117.     void *old_blk, 
  118.     size_t size )
  119. {
  120.     return( realloc( old_blk, size ));
  121. } /* end _PL_W16CallBackRealloc()  */
  122.  
  123. /*
  124. ** _PL_W16CallBackFree() -- Wrapper for free()
  125. **
  126. */
  127. void PR_CALLBACK _PL_W16CallBackFree( void *ptr )
  128. {
  129.     free( ptr );
  130.     return;
  131. } /* end _PL_W16CallBackFree()  */
  132.  
  133. /*
  134. ** _PL_W16CallBackGetenv() -- Wrapper for getenv()
  135. **
  136. */
  137. void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name )
  138. {
  139.     return( getenv( name ));
  140. } /* end _PL_W16CallBackGetenv  */
  141.  
  142.  
  143. /*
  144. ** _PL_W16CallBackPutenv() -- Wrapper for putenv()
  145. **
  146. */
  147. int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc )
  148. {
  149.     return( putenv( assoc ));
  150. } /* end _PL_W16CallBackGetenv  */
  151.