1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Netscape Portable Runtime (NSPR).
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998-2000
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
** w16callb.c -- Implement Win16 Callback functions
41
** Functions here are to replace functions normally in
42
** LIBC which are not implemented in MSVC's LIBC.
43
** Some clients of NSPR expect to statically link
44
** to NSPR and get these functions.
46
** Some are implemented as callbacks to the .EXE
47
** some are implemented directly in this module.
55
** _pr_callback_funcs -- This is where clients register the
56
** callback function structure.
58
struct PRMethodCallbackStr * _pr_callback_funcs;
61
** PR_MDInitWin16() -- Register the PRMethodCallback table pointer
64
void PR_MDRegisterCallbacks(struct PRMethodCallbackStr *f)
66
_pr_callback_funcs = f;
70
** NSPR re-implenentations of various C runtime functions:
74
** PR_MD_printf() -- exported as printf()
77
int PR_MD_printf(const char *fmt, ...)
86
PR_vsnprintf(buffer, sizeof(buffer), fmt, args);
88
if (_pr_callback_funcs != NULL && _pr_callback_funcs->auxOutput != NULL) {
89
(* _pr_callback_funcs->auxOutput)(buffer);
91
OutputDebugString(buffer);
101
** PR_MD_sscanf() -- exported as sscanf()
104
int PR_MD_sscanf(const char *buf, const char *fmt, ...)
109
va_start(arglist, fmt);
110
retval = vsscanf((const unsigned char *)buf, (const unsigned char *)fmt, arglist);
116
** PR_MD_strftime() -- exported as strftime
119
size_t PR_MD_strftime(char *s, size_t len, const char *fmt, const struct tm *p)
121
if( _pr_callback_funcs ) {
122
return (*_pr_callback_funcs->strftime)(s, len, fmt, p);
131
** PR_MD_malloc() -- exported as malloc()
134
void *PR_MD_malloc( size_t size )
136
if( _pr_callback_funcs ) {
137
return (*_pr_callback_funcs->malloc)( size );
139
return GlobalAllocPtr(GPTR, (DWORD)size);
144
** PR_MD_calloc() -- exported as calloc()
147
void *PR_MD_calloc( size_t n, size_t size )
152
if( _pr_callback_funcs ) {
153
return (*_pr_callback_funcs->calloc)( n, size );
156
p = GlobalAllocPtr(GPTR, (DWORD)sz );
157
memset( p, 0x00, sz );
163
** PR_MD_realloc() -- exported as realloc()
166
void *PR_MD_realloc( void* old_blk, size_t size )
168
if( _pr_callback_funcs ) {
169
return (*_pr_callback_funcs->realloc)( old_blk, size );
171
return GlobalReAllocPtr( old_blk, (DWORD)size, GPTR);
176
** PR_MD_free() -- exported as free()
179
void PR_MD_free( void *ptr )
181
if( _pr_callback_funcs ) {
182
(*_pr_callback_funcs->free)( ptr );
185
GlobalFreePtr( ptr );
191
** PR_MD_getenv() -- exported as getenv()
194
char *PR_MD_getenv( const char *name )
196
if( _pr_callback_funcs ) {
197
return (*_pr_callback_funcs->getenv)( name );
205
** PR_MD_perror() -- exported as perror()
207
** well, not really (lth. 12/5/97).
208
** XXX hold this thought.
211
void PR_MD_perror( const char *prefix )
217
** PR_MD_putenv() -- exported as putenv()
220
int PR_MD_putenv(const char *assoc)
222
if( _pr_callback_funcs ) {
223
return (*_pr_callback_funcs->putenv)(assoc);
231
** PR_MD_fprintf() -- exported as fprintf()
234
int PR_MD_fprintf(FILE *fPtr, const char *fmt, ...)
240
PR_vsnprintf(buffer, sizeof(buffer), fmt, args);
244
if (_pr_callback_funcs != NULL && _pr_callback_funcs->auxOutput != NULL)
246
(* _pr_callback_funcs->auxOutput)(buffer);
250
OutputDebugString(buffer);
255
fwrite(buffer, 1, strlen(buffer), fPtr); /* XXX Is this a sec. hole? */