rename.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Implementation of the RENAME intrinsic.
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
  4. This file is part of the GNU Fortran runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #include <errno.h>
  22. static int
  23. rename_internal (char *path1, char *path2, gfc_charlen_type path1_len,
  24. gfc_charlen_type path2_len)
  25. {
  26. char *str1 = fc_strdup (path1, path1_len);
  27. char *str2 = fc_strdup (path2, path2_len);
  28. int val = rename (str1, str2);
  29. free (str1);
  30. free (str2);
  31. return ((val == 0) ? 0 : errno);
  32. }
  33. /* SUBROUTINE RENAME(PATH1, PATH2, STATUS)
  34. CHARACTER(len=*), INTENT(IN) :: PATH1, PATH2
  35. INTEGER, INTENT(OUT), OPTIONAL :: STATUS */
  36. extern void rename_i4_sub (char *, char *, GFC_INTEGER_4 *, gfc_charlen_type,
  37. gfc_charlen_type);
  38. iexport_proto(rename_i4_sub);
  39. void
  40. rename_i4_sub (char *path1, char *path2, GFC_INTEGER_4 *status,
  41. gfc_charlen_type path1_len, gfc_charlen_type path2_len)
  42. {
  43. int val = rename_internal (path1, path2, path1_len, path2_len);
  44. if (status != NULL)
  45. *status = val;
  46. }
  47. iexport(rename_i4_sub);
  48. extern void rename_i8_sub (char *, char *, GFC_INTEGER_8 *, gfc_charlen_type,
  49. gfc_charlen_type);
  50. iexport_proto(rename_i8_sub);
  51. void
  52. rename_i8_sub (char *path1, char *path2, GFC_INTEGER_8 *status,
  53. gfc_charlen_type path1_len, gfc_charlen_type path2_len)
  54. {
  55. int val = rename_internal (path1, path2, path1_len, path2_len);
  56. if (status != NULL)
  57. *status = val;
  58. }
  59. iexport(rename_i8_sub);
  60. extern GFC_INTEGER_4 rename_i4 (char *, char *, gfc_charlen_type,
  61. gfc_charlen_type);
  62. export_proto(rename_i4);
  63. GFC_INTEGER_4
  64. rename_i4 (char *path1, char *path2, gfc_charlen_type path1_len,
  65. gfc_charlen_type path2_len)
  66. {
  67. return rename_internal (path1, path2, path1_len, path2_len);
  68. }
  69. extern GFC_INTEGER_8 rename_i8 (char *, char *, gfc_charlen_type,
  70. gfc_charlen_type);
  71. export_proto(rename_i8);
  72. GFC_INTEGER_8
  73. rename_i8 (char *path1, char *path2, gfc_charlen_type path1_len,
  74. gfc_charlen_type path2_len)
  75. {
  76. return rename_internal (path1, path2, path1_len, path2_len);
  77. }