2744ee988d37282f3ce12311fdf68caa61b23a9a
[mesa.git] / src / util / imports.c
1 /**
2 * \file imports.c
3 * Standard C library function wrappers.
4 *
5 * Imports are services which the device driver or window system or
6 * operating system provides to the core renderer. The core renderer (Mesa)
7 * will call these functions in order to do memory allocation, simple I/O,
8 * etc.
9 *
10 * Some drivers will want to override/replace this file with something
11 * specialized, but that'll be rare.
12 *
13 * Eventually, I want to move roll the glheader.h file into this.
14 *
15 * \todo Functions still needed:
16 * - scanf
17 * - qsort
18 * - rand and RAND_MAX
19 */
20
21 /*
22 * Mesa 3-D graphics library
23 *
24 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
25 *
26 * Permission is hereby granted, free of charge, to any person obtaining a
27 * copy of this software and associated documentation files (the "Software"),
28 * to deal in the Software without restriction, including without limitation
29 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
30 * and/or sell copies of the Software, and to permit persons to whom the
31 * Software is furnished to do so, subject to the following conditions:
32 *
33 * The above copyright notice and this permission notice shall be included
34 * in all copies or substantial portions of the Software.
35 *
36 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
37 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
40 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
41 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
42 * OTHER DEALINGS IN THE SOFTWARE.
43 */
44
45 #include <stdio.h>
46 #include <stdarg.h>
47 #include "c99_math.h"
48 #include "imports.h"
49
50 #ifdef _GNU_SOURCE
51 #include <locale.h>
52 #ifdef __APPLE__
53 #include <xlocale.h>
54 #endif
55 #endif
56
57
58 #ifdef _WIN32
59 #define vsnprintf _vsnprintf
60 #elif defined(__IBMC__) || defined(__IBMCPP__)
61 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
62 #endif
63
64
65 /** Needed due to #ifdef's, above. */
66 int
67 _mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args)
68 {
69 return vsnprintf( str, size, fmt, args);
70 }
71
72 /** Wrapper around vsnprintf() */
73 int
74 _mesa_snprintf( char *str, size_t size, const char *fmt, ... )
75 {
76 int r;
77 va_list args;
78 va_start( args, fmt );
79 r = vsnprintf( str, size, fmt, args );
80 va_end( args );
81 return r;
82 }
83
84