* global.c (global_alloc): Make it static.
[official-gcc.git] / libgfortran / intrinsics / symlnk.c
blob2e77863598623ca3f4932f3c889c342acd8e937e
1 /* Implementation of the SYMLNK intrinsic.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING. If not,
28 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA. */
31 #include "config.h"
32 #include "libgfortran.h"
34 #include <errno.h>
36 #include "../io/io.h"
38 #ifdef HAVE_STRING_H
39 #include <string.h>
40 #endif
41 #ifdef HAVE_UNISTD_H
42 #include <unistd.h>
43 #endif
45 /* SUBROUTINE SYMLNK(PATH1, PATH2, STATUS)
46 CHARACTER(len=*), INTENT(IN) :: PATH1, PATH2
47 INTEGER, INTENT(OUT), OPTIONAL :: STATUS */
49 #ifdef HAVE_SYMLINK
50 extern void symlnk_i4_sub (char *, char *, GFC_INTEGER_4 *, gfc_charlen_type,
51 gfc_charlen_type);
52 iexport_proto(symlnk_i4_sub);
54 void
55 symlnk_i4_sub (char *path1, char *path2, GFC_INTEGER_4 *status,
56 gfc_charlen_type path1_len, gfc_charlen_type path2_len)
58 int val;
59 char *str1, *str2;
61 /* Trim trailing spaces from paths. */
62 while (path1_len > 0 && path1[path1_len - 1] == ' ')
63 path1_len--;
64 while (path2_len > 0 && path2[path2_len - 1] == ' ')
65 path2_len--;
67 /* Make a null terminated copy of the strings. */
68 str1 = gfc_alloca (path1_len + 1);
69 memcpy (str1, path1, path1_len);
70 str1[path1_len] = '\0';
72 str2 = gfc_alloca (path2_len + 1);
73 memcpy (str2, path2, path2_len);
74 str2[path2_len] = '\0';
76 val = symlink (str1, str2);
78 if (status != NULL)
79 *status = (val == 0) ? 0 : errno;
81 iexport(symlnk_i4_sub);
83 extern void symlnk_i8_sub (char *, char *, GFC_INTEGER_8 *, gfc_charlen_type,
84 gfc_charlen_type);
85 iexport_proto(symlnk_i8_sub);
87 void
88 symlnk_i8_sub (char *path1, char *path2, GFC_INTEGER_8 *status,
89 gfc_charlen_type path1_len, gfc_charlen_type path2_len)
91 int val;
92 char *str1, *str2;
94 /* Trim trailing spaces from paths. */
95 while (path1_len > 0 && path1[path1_len - 1] == ' ')
96 path1_len--;
97 while (path2_len > 0 && path2[path2_len - 1] == ' ')
98 path2_len--;
100 /* Make a null terminated copy of the strings. */
101 str1 = gfc_alloca (path1_len + 1);
102 memcpy (str1, path1, path1_len);
103 str1[path1_len] = '\0';
105 str2 = gfc_alloca (path2_len + 1);
106 memcpy (str2, path2, path2_len);
107 str2[path2_len] = '\0';
109 val = symlink (str1, str2);
111 if (status != NULL)
112 *status = (val == 0) ? 0 : errno;
114 iexport(symlnk_i8_sub);
116 extern GFC_INTEGER_4 symlnk_i4 (char *, char *, gfc_charlen_type,
117 gfc_charlen_type);
118 export_proto(symlnk_i4);
120 GFC_INTEGER_4
121 symlnk_i4 (char *path1, char *path2, gfc_charlen_type path1_len,
122 gfc_charlen_type path2_len)
124 GFC_INTEGER_4 val;
125 symlnk_i4_sub (path1, path2, &val, path1_len, path2_len);
126 return val;
129 extern GFC_INTEGER_8 symlnk_i8 (char *, char *, gfc_charlen_type,
130 gfc_charlen_type);
131 export_proto(symlnk_i8);
133 GFC_INTEGER_8
134 symlnk_i8 (char *path1, char *path2, gfc_charlen_type path1_len,
135 gfc_charlen_type path2_len)
137 GFC_INTEGER_8 val;
138 symlnk_i8_sub (path1, path2, &val, path1_len, path2_len);
139 return val;
141 #endif