symlnk.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Implementation of the SYMLNK 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. #ifdef HAVE_UNISTD_H
  23. #include <unistd.h>
  24. #endif
  25. /* SUBROUTINE SYMLNK(PATH1, PATH2, STATUS)
  26. CHARACTER(len=*), INTENT(IN) :: PATH1, PATH2
  27. INTEGER, INTENT(OUT), OPTIONAL :: STATUS */
  28. #ifdef HAVE_SYMLINK
  29. static int
  30. symlnk_internal (char *path1, char *path2, gfc_charlen_type path1_len,
  31. gfc_charlen_type path2_len)
  32. {
  33. char *str1 = fc_strdup (path1, path1_len);
  34. char *str2 = fc_strdup (path2, path2_len);
  35. int val = symlink (str1, str2);
  36. free (str1);
  37. free (str2);
  38. return ((val == 0) ? 0 : errno);
  39. }
  40. extern void symlnk_i4_sub (char *, char *, GFC_INTEGER_4 *, gfc_charlen_type,
  41. gfc_charlen_type);
  42. iexport_proto(symlnk_i4_sub);
  43. void
  44. symlnk_i4_sub (char *path1, char *path2, GFC_INTEGER_4 *status,
  45. gfc_charlen_type path1_len, gfc_charlen_type path2_len)
  46. {
  47. int val = symlnk_internal (path1, path2, path1_len, path2_len);
  48. if (status != NULL)
  49. *status = val;
  50. }
  51. iexport(symlnk_i4_sub);
  52. extern void symlnk_i8_sub (char *, char *, GFC_INTEGER_8 *, gfc_charlen_type,
  53. gfc_charlen_type);
  54. iexport_proto(symlnk_i8_sub);
  55. void
  56. symlnk_i8_sub (char *path1, char *path2, GFC_INTEGER_8 *status,
  57. gfc_charlen_type path1_len, gfc_charlen_type path2_len)
  58. {
  59. int val = symlnk_internal (path1, path2, path1_len, path2_len);
  60. if (status != NULL)
  61. *status = val;
  62. }
  63. iexport(symlnk_i8_sub);
  64. extern GFC_INTEGER_4 symlnk_i4 (char *, char *, gfc_charlen_type,
  65. gfc_charlen_type);
  66. export_proto(symlnk_i4);
  67. GFC_INTEGER_4
  68. symlnk_i4 (char *path1, char *path2, gfc_charlen_type path1_len,
  69. gfc_charlen_type path2_len)
  70. {
  71. return symlnk_internal (path1, path2, path1_len, path2_len);
  72. }
  73. extern GFC_INTEGER_8 symlnk_i8 (char *, char *, gfc_charlen_type,
  74. gfc_charlen_type);
  75. export_proto(symlnk_i8);
  76. GFC_INTEGER_8
  77. symlnk_i8 (char *path1, char *path2, gfc_charlen_type path1_len,
  78. gfc_charlen_type path2_len)
  79. {
  80. return symlnk_internal (path1, path2, path1_len, path2_len);
  81. }
  82. #endif