comparison src/platform.c @ 45:d85542c96791

Clean up the build some more, move platform specifics again.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Aug 2013 00:23:45 +0300
parents 785057719d9b
children
comparison
equal deleted inserted replaced
44:f0073a47c31d 45:d85542c96791
1 /* ============================================================================
2 * Freetype GL - A C OpenGL Freetype engine
3 * Platform: Any
4 * WWW: http://code.google.com/p/freetype-gl/
5 * ----------------------------------------------------------------------------
6 * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21 * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * The views and conclusions contained in the software and documentation are
30 * those of the authors and should not be interpreted as representing official
31 * policies, either expressed or implied, of Nicolas P. Rougier.
32 * ============================================================================
33 */
34 #include <string.h>
35 #include "platform.h" 1 #include "platform.h"
36 2
3
37 #if defined(_WIN32) || defined(_WIN64) 4 #if defined(_WIN32) || defined(_WIN64)
38
39 #include <math.h> 5 #include <math.h>
40 6
41 double round (float v) 7 double round(float v)
42 { 8 {
43 return floor(v+0.5f); 9 return floor(v + 0.5f);
44 } 10 }
45 11
46 // strndup() is not available on Windows 12 #endif
47 char *strndup( const char *s1, size_t n)
48 {
49 char *copy= (char*)malloc( n+1 );
50 memcpy( copy, s1, n );
51 copy[n] = 0;
52 return copy;
53 };
54 #endif
55 13
56 14
57 // strndup() was only added in OSX lion 15 #if defined(__APPLE__) || defined(_WIN32) || defined(_WIN64)
58 #if defined(__APPLE__) 16
59 char *strndup( const char *s1, size_t n) 17 char * strndup(const char *s, size_t n)
60 { 18 {
61 char *copy = calloc( n+1, sizeof(char) ); 19 char *result = malloc(n + 1);
62 memcpy( copy, s1, n ); 20 if (result == NULL)
63 return copy; 21 return NULL;
64 }; 22
23 memcpy(result, s, n);
24 result[n] = 0;
25 return result;
26 }
27
65 #endif 28 #endif