link.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Implementation of the LINK 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 LINK(PATH1, PATH2, STATUS)
  28. CHARACTER(len=*), INTENT(IN) :: PATH1, PATH2
  29. INTEGER, INTENT(OUT), OPTIONAL :: STATUS */
  30. #ifdef HAVE_LINK
  31. static int
  32. link_internal (char *path1, char *path2, gfc_charlen_type path1_len,
  33. gfc_charlen_type path2_len)
  34. {
  35. int val;
  36. char *str1, *str2;
  37. /* Make a null terminated copy of the strings. */
  38. str1 = fc_strdup (path1, path1_len);
  39. str2 = fc_strdup (path2, path2_len);
  40. val = link (str1, str2);
  41. free (str1);
  42. free (str2);
  43. return ((val == 0) ? 0 : errno);
  44. }
  45. extern void link_i4_sub (char *, char *, GFC_INTEGER_4 *, gfc_charlen_type,
  46. gfc_charlen_type);
  47. iexport_proto(link_i4_sub);
  48. void
  49. link_i4_sub (char *path1, char *path2, GFC_INTEGER_4 *status,
  50. gfc_charlen_type path1_len, gfc_charlen_type path2_len)
  51. {
  52. int val = link_internal (path1, path2, path1_len, path2_len);
  53. if (status != NULL)
  54. *status = val;
  55. }
  56. iexport(link_i4_sub);
  57. extern void link_i8_sub (char *, char *, GFC_INTEGER_8 *, gfc_charlen_type,
  58. gfc_charlen_type);
  59. iexport_proto(link_i8_sub);
  60. void
  61. link_i8_sub (char *path1, char *path2, GFC_INTEGER_8 *status,
  62. gfc_charlen_type path1_len, gfc_charlen_type path2_len)
  63. {
  64. int val = link_internal (path1, path2, path1_len, path2_len);
  65. if (status != NULL)
  66. *status = val;
  67. }
  68. iexport(link_i8_sub);
  69. extern GFC_INTEGER_4 link_i4 (char *, char *, gfc_charlen_type,
  70. gfc_charlen_type);
  71. export_proto(link_i4);
  72. GFC_INTEGER_4
  73. link_i4 (char *path1, char *path2, gfc_charlen_type path1_len,
  74. gfc_charlen_type path2_len)
  75. {
  76. return link_internal (path1, path2, path1_len, path2_len);
  77. }
  78. extern GFC_INTEGER_8 link_i8 (char *, char *, gfc_charlen_type,
  79. gfc_charlen_type);
  80. export_proto(link_i8);
  81. GFC_INTEGER_8
  82. link_i8 (char *path1, char *path2, gfc_charlen_type path1_len,
  83. gfc_charlen_type path2_len)
  84. {
  85. return link_internal (path1, path2, path1_len, path2_len);
  86. }
  87. #endif