unlink.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Implementation of the UNLINK intrinsic.
  2. Copyright (C) 2004-2015 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 <stdlib.h>
  22. #include <string.h>
  23. #include <errno.h>
  24. #ifdef HAVE_UNISTD_H
  25. #include <unistd.h>
  26. #endif
  27. /* SUBROUTINE UNLINK(NAME, STATUS)
  28. CHARACTER(LEN= ), INTENT(IN) :: NAME
  29. INTEGER, INTENT(OUT), OPTIONAL :: STATUS) */
  30. extern void unlink_i4_sub (char *name, GFC_INTEGER_4 *status,
  31. gfc_charlen_type name_len);
  32. iexport_proto(unlink_i4_sub);
  33. void
  34. unlink_i4_sub (char *name, GFC_INTEGER_4 *status, gfc_charlen_type name_len)
  35. {
  36. char *str;
  37. GFC_INTEGER_4 stat;
  38. /* Make a null terminated copy of the string. */
  39. str = fc_strdup (name, name_len);
  40. stat = unlink (str);
  41. free (str);
  42. if (status != NULL)
  43. *status = (stat == 0) ? stat : errno;
  44. }
  45. iexport(unlink_i4_sub);
  46. extern void unlink_i8_sub (char *name, GFC_INTEGER_8 *status,
  47. gfc_charlen_type name_len);
  48. export_proto(unlink_i8_sub);
  49. void
  50. unlink_i8_sub (char *name, GFC_INTEGER_8 *status, gfc_charlen_type name_len)
  51. {
  52. GFC_INTEGER_4 status4;
  53. unlink_i4_sub (name, &status4, name_len);
  54. if (status)
  55. *status = status4;
  56. }
  57. /* INTEGER FUNCTION UNLINK(NAME)
  58. CHARACTER(LEN= ), INTENT(IN) :: NAME */
  59. extern GFC_INTEGER_4 PREFIX(unlink) (char *, gfc_charlen_type);
  60. export_proto_np(PREFIX(unlink));
  61. GFC_INTEGER_4
  62. PREFIX(unlink) (char *name, gfc_charlen_type name_len)
  63. {
  64. GFC_INTEGER_4 status;
  65. unlink_i4_sub (name, &status, name_len);
  66. return status;
  67. }