symlnk.c 3.1 KB

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