1 /***************************************************************************
2  *  Copyright (C) 2015-2020 by Mihai Moldovan <ionic@ionic.de>             *
3  *                                                                         *
4  *  This program is free software; you can redistribute it and/or modify   *
5  *  it under the terms of the GNU General Public License as published by   *
6  *  the Free Software Foundation; either version 2 of the License, or      *
7  *  (at your option) any later version.                                    *
8  *                                                                         *
9  *  This program is distributed in the hope that it will be useful,        *
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
12  *  GNU General Public License for more details.                           *
13  *                                                                         *
14  *  You should have received a copy of the GNU General Public License      *
15  *  along with this program; if not, write to the                          *
16  *  Free Software Foundation, Inc.,                                        *
17  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
18  ***************************************************************************/
19 
20 #include "compat.h"
21 
22 #ifdef Q_OS_DARWIN
23 /*
24  * strndup() is not available on 10.6 and below, define a compat version here.
25  * Shameless copy from libiberty.
26  */
27 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
28 #include <stddef.h>
29 #include <string.h>
30 #include <stdlib.h>
31 
strndup(const char * s,size_t n)32 char *strndup (const char *s, size_t n) {
33   char *result;
34   size_t len = strlen (s);
35 
36   if (n < len) {
37     len = n;
38   }
39 
40   result = (char *) malloc (len + 1);
41   if (!result) {
42     return (0);
43   }
44 
45   result[len] = '\0';
46   return ((char *) memcpy (result, s, len));
47 }
48 #endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
49 #endif /* defined (Q_OS_DARWIN) */
50