2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / libgfortran / intrinsics / string_intrinsics.c
blobf6d9663f0baa3d489b7a69b63f442b4c284e5906
1 /* String intrinsics helper functions.
2 Copyright 2008 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 2 of the License, or (at your option) any later version.
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file. (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
20 Libgfortran is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public
26 License along with libgfortran; see the file COPYING. If not,
27 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA. */
31 /* Unlike what the name of this file suggests, we don't actually
32 implement the Fortran intrinsics here. At least, not with the
33 names they have in the standard. The functions here provide all
34 the support we need for the standard string intrinsics, and the
35 compiler translates the actual intrinsics calls to calls to
36 functions in this file. */
38 #include "libgfortran.h"
40 #include <stdlib.h>
41 #include <string.h>
44 /* Helper function to set parts of wide strings to a constant (usually
45 spaces). */
47 static gfc_char4_t *
48 memset_char4 (gfc_char4_t *b, gfc_char4_t c, size_t len)
50 size_t i;
52 for (i = 0; i < len; i++)
53 b[i] = c;
55 return b;
59 /* All other functions are defined using a few generic macros in
60 string_intrinsics_inc.c, so we avoid code duplication between the
61 various character type kinds. */
63 #undef CHARTYPE
64 #define CHARTYPE char
65 #undef UCHARTYPE
66 #define UCHARTYPE unsigned char
67 #undef SUFFIX
68 #define SUFFIX(x) x
69 #undef MEMSET
70 #define MEMSET memset
72 #include "string_intrinsics_inc.c"
75 #undef CHARTYPE
76 #define CHARTYPE gfc_char4_t
77 #undef UCHARTYPE
78 #define UCHARTYPE gfc_char4_t
79 #undef SUFFIX
80 #define SUFFIX(x) x ## _char4
81 #undef MEMSET
82 #define MEMSET memset_char4
84 #include "string_intrinsics_inc.c"