1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 * The contents of this file are subject to the Mozilla Public
4 * License Version 1.1 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of
6 * the License at http://www.mozilla.org/MPL/
8 * Software distributed under the License is distributed on an "AS
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the License for the specific language governing
11 * rights and limitations under the License.
13 * The Original Code is the Netscape Portable Runtime (NSPR).
15 * The Initial Developer of the Original Code is Netscape
16 * Communications Corporation. Portions created by Netscape are
17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All
22 * Alternatively, the contents of this file may be used under the
23 * terms of the GNU General Public License Version 2 or later (the
24 * "GPL"), in which case the provisions of the GPL are applicable
25 * instead of those above. If you wish to allow use of your
26 * version of this file only under the terms of the GPL and not to
27 * allow others to use your version of this file under the MPL,
28 * indicate your decision by deleting the provisions above and
29 * replace them with the notice and other provisions required by
30 * the GPL. If you do not delete the provisions above, a recipient
31 * may use your version of this file under either the MPL or the
39 ** Condition use of this header on platform.
41 #if (defined(XP_PC) && !defined(_WIN32) && !defined(XP_OS2) && defined(MOZILLA_CLIENT)) || defined(WIN16)
46 ** Win16 stdio special case.
47 ** To get stdio to work for Win16, all calls to printf() and related
48 ** things must be called from the environment of the .EXE; calls to
49 ** printf() from the .DLL send output to the bit-bucket.
51 ** To make sure that PR_fprintf(), and related functions, work correctly,
52 ** the actual stream I/O to stdout, stderr, stdin must be done in the
53 ** .EXE. To do this, a hack is placed in _MD_Write() such that the
54 ** fd for stdio handles results in a call to the .EXE.
56 ** file w16stdio.c contains the functions that get called from NSPR
57 ** to do the actual I/O. w16stdio.o must be statically linked with
58 ** any application needing stdio for Win16.
60 ** The address of these functions must be made available to the .DLL
61 ** so he can call back to the .EXE. To do this, function
62 ** PR_MD_RegisterW16StdioCallbacks() is called from the .EXE.
63 ** The arguments are the functions defined in w16stdio.c
64 ** At runtime, MD_Write() calls the registered functions, if any
67 ** prinit.h contains a macro PR_STDIO_INIT() that calls the registration
68 ** function for Win16; For other platforms, the macro is a No-Op.
70 ** Note that stdio is not operational at all on Win16 GUI applications.
71 ** This special case exists to provide stdio capability from the NSPR
72 ** .DLL for command line applications only. NSPR's test cases are
73 ** almost exclusively command line applications.
75 ** See also: w16io.c, w16stdio.c
77 typedef PRInt32 (PR_CALLBACK
*PRStdinRead
)( void *buf
, PRInt32 amount
);
78 typedef PRInt32 (PR_CALLBACK
*PRStdoutWrite
)( void *buf
, PRInt32 amount
);
79 typedef PRInt32 (PR_CALLBACK
*PRStderrWrite
)( void *buf
, PRInt32 amount
);
82 PR_MD_RegisterW16StdioCallbacks(
83 PRStdinRead inReadf
, /* i: function pointer for stdin read */
84 PRStdoutWrite outWritef
, /* i: function pointer for stdout write */
85 PRStderrWrite errWritef
/* i: function pointer for stderr write */
89 _PL_W16StdioWrite( void *buf
, PRInt32 amount
);
92 _PL_W16StdioRead( void *buf
, PRInt32 amount
);
94 #define PR_STDIO_INIT() PR_MD_RegisterW16StdioCallbacks( \
95 _PL_W16StdioRead, _PL_W16StdioWrite, _PL_W16StdioWrite ); \
102 struct PRMethodCallbackStr
{
103 int (PR_CALLBACK
*auxOutput
)(const char *outputString
);
104 size_t (PR_CALLBACK
*strftime
)(char *s
, size_t len
, const char *fmt
, const struct tm
*p
);
105 void * (PR_CALLBACK
*malloc
)( size_t size
);
106 void * (PR_CALLBACK
*calloc
)(size_t n
, size_t size
);
107 void * (PR_CALLBACK
*realloc
)( void* old_blk
, size_t size
);
108 void (PR_CALLBACK
*free
)( void *ptr
);
109 void * (PR_CALLBACK
*getenv
)( const char *name
);
110 int (PR_CALLBACK
*putenv
)( const char *assoc
);
111 /* void * (PR_CALLBACK *perror)( const char *prefix ); */
114 NSPR_API(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr
*);
116 int PR_CALLBACK
_PL_W16CallBackPuts( const char *outputString
);
117 size_t PR_CALLBACK
_PL_W16CallBackStrftime(
121 const struct tm
*p
);
122 void * PR_CALLBACK
_PL_W16CallBackMalloc( size_t size
);
123 void * PR_CALLBACK
_PL_W16CallBackCalloc( size_t n
, size_t size
);
124 void * PR_CALLBACK
_PL_W16CallBackRealloc(
127 void PR_CALLBACK
_PL_W16CallBackFree( void *ptr
);
128 void * PR_CALLBACK
_PL_W16CallBackGetenv( const char *name
);
129 int PR_CALLBACK
_PL_W16CallBackPutenv( const char *assoc
);
134 ** These functions are provided as static link points.
135 ** This is to satisfy the quick port of Gromit to NSPR 2.0
136 ** ... Don't do this! ... alas, It may never go away.
139 NSPR_API(int) PR_MD_printf(const char *, ...);
140 NSPR_API(void) PR_MD_exit(int);
141 NSPR_API(size_t) PR_MD_strftime(char *, size_t, const char *, const struct tm
*);
142 NSPR_API(int) PR_MD_sscanf(const char *, const char *, ...);
143 NSPR_API(void*) PR_MD_malloc( size_t size
);
144 NSPR_API(void*) PR_MD_calloc( size_t n
, size_t size
);
145 NSPR_API(void*) PR_MD_realloc( void* old_blk
, size_t size
);
146 NSPR_API(void) PR_MD_free( void *ptr
);
147 NSPR_API(char*) PR_MD_getenv( const char *name
);
148 NSPR_API(int) PR_MD_putenv( const char *assoc
);
149 NSPR_API(int) PR_MD_fprintf(FILE *fPtr
, const char *fmt
, ...);
151 #define PR_INIT_CALLBACKS() \
153 static struct PRMethodCallbackStr cbf = { \
154 _PL_W16CallBackPuts, \
155 _PL_W16CallBackStrftime, \
156 _PL_W16CallBackMalloc, \
157 _PL_W16CallBackCalloc, \
158 _PL_W16CallBackRealloc, \
159 _PL_W16CallBackFree, \
160 _PL_W16CallBackGetenv, \
161 _PL_W16CallBackPutenv, \
163 PR_MDRegisterCallbacks( &cbf ); \
168 ** Get the exception context for Win16 MFC applications threads
170 NSPR_API(void *) PR_W16GetExceptionContext(void);
172 ** Set the exception context for Win16 MFC applications threads
174 NSPR_API(void) PR_W16SetExceptionContext(void *context
);
179 ** For platforms other than Win16, define
180 ** PR_STDIO_INIT() as a No-Op.
182 #define PR_STDIO_INIT()
183 #endif /* WIN16 || MOZILLA_CLIENT */
185 #endif /* prwin16_h___ */