1 /* Implementation of the CHMOD intrinsic.
2 Copyright (C) 2006, 2007 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. */
31 #include "libgfortran.h"
39 #ifdef HAVE_SYS_WAIT_H
43 /* INTEGER FUNCTION ACCESS(NAME, MODE)
44 CHARACTER(len=*), INTENT(IN) :: NAME, MODE */
46 #if defined(HAVE_FORK) && defined(HAVE_EXECL) && defined(HAVE_WAIT)
48 extern int chmod_func (char *, char *, gfc_charlen_type
, gfc_charlen_type
);
49 export_proto(chmod_func
);
52 chmod_func (char *name
, char *mode
, gfc_charlen_type name_len
,
53 gfc_charlen_type mode_len
)
59 /* Trim trailing spaces. */
60 while (name_len
> 0 && name
[name_len
- 1] == ' ')
62 while (mode_len
> 0 && mode
[mode_len
- 1] == ' ')
65 /* Make a null terminated copy of the strings. */
66 file
= gfc_alloca (name_len
+ 1);
67 memcpy (file
, name
, name_len
);
68 file
[name_len
] = '\0';
70 m
= gfc_alloca (mode_len
+ 1);
71 memcpy (m
, mode
, mode_len
);
74 /* Execute /bin/chmod. */
75 if ((pid
= fork()) < 0)
80 execl ("/bin/chmod", "chmod", m
, file
, (char *) NULL
);
86 if (WIFEXITED(status
))
87 return WEXITSTATUS(status
);
94 extern void chmod_i4_sub (char *, char *, GFC_INTEGER_4
*,
95 gfc_charlen_type
, gfc_charlen_type
);
96 export_proto(chmod_i4_sub
);
99 chmod_i4_sub (char *name
, char *mode
, GFC_INTEGER_4
* status
,
100 gfc_charlen_type name_len
, gfc_charlen_type mode_len
)
104 val
= chmod_func (name
, mode
, name_len
, mode_len
);
110 extern void chmod_i8_sub (char *, char *, GFC_INTEGER_8
*,
111 gfc_charlen_type
, gfc_charlen_type
);
112 export_proto(chmod_i8_sub
);
115 chmod_i8_sub (char *name
, char *mode
, GFC_INTEGER_8
* status
,
116 gfc_charlen_type name_len
, gfc_charlen_type mode_len
)
120 val
= chmod_func (name
, mode
, name_len
, mode_len
);