unlink.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Implementation of the UNLINK intrinsic.
  2. Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. Contributed by Steven G. Kargl <kargls@comcast.net>.
  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 UNLINK(NAME, STATUS)
  26. CHARACTER(LEN= ), INTENT(IN) :: NAME
  27. INTEGER, INTENT(OUT), OPTIONAL :: STATUS) */
  28. extern void unlink_i4_sub (char *name, GFC_INTEGER_4 *status,
  29. gfc_charlen_type name_len);
  30. iexport_proto(unlink_i4_sub);
  31. void
  32. unlink_i4_sub (char *name, GFC_INTEGER_4 *status, gfc_charlen_type name_len)
  33. {
  34. char *str;
  35. GFC_INTEGER_4 stat;
  36. /* Make a null terminated copy of the string. */
  37. str = fc_strdup (name, name_len);
  38. stat = unlink (str);
  39. free (str);
  40. if (status != NULL)
  41. *status = (stat == 0) ? stat : errno;
  42. }
  43. iexport(unlink_i4_sub);
  44. extern void unlink_i8_sub (char *name, GFC_INTEGER_8 *status,
  45. gfc_charlen_type name_len);
  46. export_proto(unlink_i8_sub);
  47. void
  48. unlink_i8_sub (char *name, GFC_INTEGER_8 *status, gfc_charlen_type name_len)
  49. {
  50. GFC_INTEGER_4 status4;
  51. unlink_i4_sub (name, &status4, name_len);
  52. if (status)
  53. *status = status4;
  54. }
  55. /* INTEGER FUNCTION UNLINK(NAME)
  56. CHARACTER(LEN= ), INTENT(IN) :: NAME */
  57. extern GFC_INTEGER_4 PREFIX(unlink) (char *, gfc_charlen_type);
  58. export_proto_np(PREFIX(unlink));
  59. GFC_INTEGER_4
  60. PREFIX(unlink) (char *name, gfc_charlen_type name_len)
  61. {
  62. GFC_INTEGER_4 status;
  63. unlink_i4_sub (name, &status, name_len);
  64. return status;
  65. }