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
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. */
32 #include "libgfortran.h"
45 /* SUBROUTINE SYMLNK(PATH1, PATH2, STATUS)
46 CHARACTER(len=*), INTENT(IN) :: PATH1, PATH2
47 INTEGER, INTENT(OUT), OPTIONAL :: STATUS */
50 extern void symlnk_i4_sub (char *, char *, GFC_INTEGER_4
*, gfc_charlen_type
,
52 iexport_proto(symlnk_i4_sub
);
55 symlnk_i4_sub (char *path1
, char *path2
, GFC_INTEGER_4
*status
,
56 gfc_charlen_type path1_len
, gfc_charlen_type path2_len
)
61 /* Trim trailing spaces from paths. */
62 while (path1_len
> 0 && path1
[path1_len
- 1] == ' ')
64 while (path2_len
> 0 && path2
[path2_len
- 1] == ' ')
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
);
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
,
85 iexport_proto(symlnk_i8_sub
);
88 symlnk_i8_sub (char *path1
, char *path2
, GFC_INTEGER_8
*status
,
89 gfc_charlen_type path1_len
, gfc_charlen_type path2_len
)
94 /* Trim trailing spaces from paths. */
95 while (path1_len
> 0 && path1
[path1_len
- 1] == ' ')
97 while (path2_len
> 0 && path2
[path2_len
- 1] == ' ')
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
);
112 *status
= (val
== 0) ? 0 : errno
;
114 iexport(symlnk_i8_sub
);
116 extern GFC_INTEGER_4
symlnk_i4 (char *, char *, gfc_charlen_type
,
118 export_proto(symlnk_i4
);
121 symlnk_i4 (char *path1
, char *path2
, gfc_charlen_type path1_len
,
122 gfc_charlen_type path2_len
)
125 symlnk_i4_sub (path1
, path2
, &val
, path1_len
, path2_len
);
129 extern GFC_INTEGER_8
symlnk_i8 (char *, char *, gfc_charlen_type
,
131 export_proto(symlnk_i8
);
134 symlnk_i8 (char *path1
, char *path2
, gfc_charlen_type path1_len
,
135 gfc_charlen_type path2_len
)
138 symlnk_i8_sub (path1
, path2
, &val
, path1_len
, path2_len
);