~ubuntu-branches/ubuntu/precise/nspr/precise-proposed

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/md/windows/w16callb.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-08-10 11:34:26 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090810113426-3uv4diflrkcbdimm
Tags: 4.8-0ubuntu1
* New upstream release: 4.8 (LP: #387812)
* adjust patches to changed upstreanm codebase
  - update debian/patches/99_configure.patch
* update shlibs symbols to include new API elements
  - update debian/libnspr4-0d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
 
 *
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/
9
 
 *
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
13
 
 * License.
14
 
 *
15
 
 * The Original Code is the Netscape Portable Runtime (NSPR).
16
 
 *
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.
21
 
 *
22
 
 * Contributor(s):
23
 
 *
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.
35
 
 *
36
 
 * ***** END LICENSE BLOCK ***** */
37
 
 
38
 
/*
39
 
** w16callb.c -- Implement Win16 Callback functions
40
 
**
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.
45
 
**
46
 
** Some are implemented as callbacks to the .EXE
47
 
** some are implemented directly in this module.
48
 
**
49
 
*/
50
 
 
51
 
#include "primpl.h"
52
 
#include "windowsx.h"
53
 
 
54
 
/*
55
 
** _pr_callback_funcs -- This is where clients register the 
56
 
** callback function structure.
57
 
*/
58
 
struct PRMethodCallbackStr * _pr_callback_funcs;
59
 
 
60
 
/*
61
 
** PR_MDInitWin16() -- Register the PRMethodCallback table pointer
62
 
** 
63
 
*/
64
 
void PR_MDRegisterCallbacks(struct PRMethodCallbackStr *f)
65
 
{
66
 
    _pr_callback_funcs = f;
67
 
}
68
 
 
69
 
/*
70
 
** NSPR re-implenentations of various C runtime functions:
71
 
*/
72
 
 
73
 
/*
74
 
** PR_MD_printf() -- exported as printf()
75
 
**
76
 
*/
77
 
int  PR_MD_printf(const char *fmt, ...)
78
 
{
79
 
    char buffer[1024];
80
 
    int ret = 0;
81
 
    va_list args;
82
 
 
83
 
    va_start(args, fmt);
84
 
 
85
 
#ifdef DEBUG
86
 
    PR_vsnprintf(buffer, sizeof(buffer), fmt, args);
87
 
    {   
88
 
        if (_pr_callback_funcs != NULL && _pr_callback_funcs->auxOutput != NULL) {
89
 
            (* _pr_callback_funcs->auxOutput)(buffer);
90
 
        } else {
91
 
            OutputDebugString(buffer);
92
 
        }
93
 
    }
94
 
#endif
95
 
 
96
 
    va_end(args);
97
 
    return ret;
98
 
}
99
 
 
100
 
/*
101
 
** PR_MD_sscanf() -- exported as sscanf()
102
 
**
103
 
*/
104
 
int  PR_MD_sscanf(const char *buf, const char *fmt, ...)
105
 
{
106
 
        int             retval;
107
 
        va_list arglist;
108
 
 
109
 
        va_start(arglist, fmt);
110
 
        retval = vsscanf((const unsigned char *)buf, (const unsigned char *)fmt, arglist);
111
 
        va_end(arglist);
112
 
        return retval;
113
 
}
114
 
 
115
 
/*
116
 
** PR_MD_strftime() -- exported as strftime
117
 
**
118
 
*/
119
 
size_t PR_MD_strftime(char *s, size_t len, const char *fmt, const struct tm *p) 
120
 
{
121
 
    if( _pr_callback_funcs ) {
122
 
        return (*_pr_callback_funcs->strftime)(s, len, fmt, p);
123
 
    } else {
124
 
        PR_ASSERT(0);
125
 
        return 0;
126
 
    }
127
 
}
128
 
 
129
 
 
130
 
/*
131
 
** PR_MD_malloc() -- exported as malloc()
132
 
**
133
 
*/
134
 
void *PR_MD_malloc( size_t size )
135
 
{
136
 
    if( _pr_callback_funcs ) {
137
 
        return (*_pr_callback_funcs->malloc)( size );
138
 
    } else {
139
 
        return GlobalAllocPtr(GPTR, (DWORD)size);
140
 
    }
141
 
} /* end malloc() */
142
 
 
143
 
/*
144
 
** PR_MD_calloc() -- exported as calloc()
145
 
**
146
 
*/
147
 
void *PR_MD_calloc( size_t n, size_t size )
148
 
{
149
 
    void *p;
150
 
    size_t sz;
151
 
    
152
 
    if( _pr_callback_funcs ) {
153
 
        return (*_pr_callback_funcs->calloc)( n, size );
154
 
    } else {
155
 
        sz = n * size;
156
 
        p = GlobalAllocPtr(GPTR, (DWORD)sz );
157
 
        memset( p, 0x00, sz );
158
 
        return p;
159
 
    }
160
 
} /* end calloc() */
161
 
 
162
 
/*
163
 
** PR_MD_realloc() -- exported as realloc()
164
 
**
165
 
*/
166
 
void *PR_MD_realloc( void* old_blk, size_t size )
167
 
{
168
 
    if( _pr_callback_funcs ) {
169
 
        return (*_pr_callback_funcs->realloc)( old_blk, size );
170
 
    } else {
171
 
        return GlobalReAllocPtr( old_blk, (DWORD)size, GPTR);
172
 
    }
173
 
} /* end realloc */
174
 
 
175
 
/*
176
 
** PR_MD_free() -- exported as free()
177
 
**
178
 
*/
179
 
void PR_MD_free( void *ptr )
180
 
{
181
 
    if( _pr_callback_funcs ) {
182
 
        (*_pr_callback_funcs->free)( ptr );
183
 
        return;
184
 
    } else {
185
 
        GlobalFreePtr( ptr );
186
 
        return;
187
 
    }
188
 
} /* end free() */
189
 
 
190
 
/*
191
 
** PR_MD_getenv() -- exported as getenv()
192
 
**
193
 
*/
194
 
char *PR_MD_getenv( const char *name )
195
 
{
196
 
    if( _pr_callback_funcs ) {
197
 
        return (*_pr_callback_funcs->getenv)( name );
198
 
    } else {
199
 
        return 0;
200
 
    }
201
 
} /* end getenv() */
202
 
 
203
 
 
204
 
/*
205
 
** PR_MD_perror() -- exported as perror()
206
 
**
207
 
** well, not really (lth. 12/5/97).
208
 
** XXX hold this thought.
209
 
**
210
 
*/
211
 
void PR_MD_perror( const char *prefix )
212
 
{
213
 
    return;
214
 
} /* end perror() */
215
 
 
216
 
/*
217
 
** PR_MD_putenv() -- exported as putenv()
218
 
**
219
 
*/
220
 
int  PR_MD_putenv(const char *assoc)
221
 
{
222
 
    if( _pr_callback_funcs ) {
223
 
        return (*_pr_callback_funcs->putenv)(assoc);
224
 
    } else {
225
 
        PR_ASSERT(0);
226
 
        return NULL;
227
 
    }
228
 
}
229
 
 
230
 
/*
231
 
** PR_MD_fprintf() -- exported as fprintf()
232
 
**
233
 
*/
234
 
int  PR_MD_fprintf(FILE *fPtr, const char *fmt, ...)
235
 
{
236
 
    char buffer[1024];
237
 
    va_list args;
238
 
 
239
 
    va_start(args, fmt);
240
 
    PR_vsnprintf(buffer, sizeof(buffer), fmt, args);
241
 
 
242
 
    if (fPtr == NULL) 
243
 
    {
244
 
        if (_pr_callback_funcs != NULL && _pr_callback_funcs->auxOutput != NULL) 
245
 
        {
246
 
            (* _pr_callback_funcs->auxOutput)(buffer);
247
 
        } 
248
 
        else 
249
 
        {
250
 
            OutputDebugString(buffer);
251
 
        }
252
 
    } 
253
 
    else 
254
 
    {
255
 
        fwrite(buffer, 1, strlen(buffer), fPtr); /* XXX Is this a sec. hole? */
256
 
    }
257
 
 
258
 
    va_end(args);
259
 
    return 0;
260
 
}
261
 
 
262
 
/* end w16callb.c */