re PR driver/57651 (gcc-ar and gcc-nm don't find the lto plugin)
[official-gcc.git] / libgfortran / intrinsics / string_intrinsics.c
blob2fa788dba2f1c67da2cdf7ba9d838d0a3fd41d21
1 /* String intrinsics helper functions.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc.
4 This file is part of the GNU Fortran runtime library (libgfortran).
6 Libgfortran is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version.
11 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
26 /* Unlike what the name of this file suggests, we don't actually
27 implement the Fortran intrinsics here. At least, not with the
28 names they have in the standard. The functions here provide all
29 the support we need for the standard string intrinsics, and the
30 compiler translates the actual intrinsics calls to calls to
31 functions in this file. */
33 #include "libgfortran.h"
35 #include <stdlib.h>
36 #include <string.h>
37 #include <assert.h>
40 /* Helper function to set parts of wide strings to a constant (usually
41 spaces). */
43 static gfc_char4_t *
44 memset_char4 (gfc_char4_t *b, gfc_char4_t c, size_t len)
46 size_t i;
48 for (i = 0; i < len; i++)
49 b[i] = c;
51 return b;
54 /* Compare wide character types, which are handled internally as
55 unsigned 4-byte integers. */
56 int
57 memcmp_char4 (const void *a, const void *b, size_t len)
59 const GFC_UINTEGER_4 *pa = a;
60 const GFC_UINTEGER_4 *pb = b;
61 while (len-- > 0)
63 if (*pa != *pb)
64 return *pa < *pb ? -1 : 1;
65 pa ++;
66 pb ++;
68 return 0;
72 /* All other functions are defined using a few generic macros in
73 string_intrinsics_inc.c, so we avoid code duplication between the
74 various character type kinds. */
76 #undef CHARTYPE
77 #define CHARTYPE char
78 #undef UCHARTYPE
79 #define UCHARTYPE unsigned char
80 #undef SUFFIX
81 #define SUFFIX(x) x
82 #undef MEMSET
83 #define MEMSET memset
84 #undef MEMCMP
85 #define MEMCMP memcmp
87 #include "string_intrinsics_inc.c"
90 #undef CHARTYPE
91 #define CHARTYPE gfc_char4_t
92 #undef UCHARTYPE
93 #define UCHARTYPE gfc_char4_t
94 #undef SUFFIX
95 #define SUFFIX(x) x ## _char4
96 #undef MEMSET
97 #define MEMSET memset_char4
98 #undef MEMCMP
99 #define MEMCMP memcmp_char4
101 #include "string_intrinsics_inc.c"