umask.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Implementation of the UMASK 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. #ifdef HAVE_SYS_STAT_H
  23. #include <sys/stat.h>
  24. #endif
  25. #ifdef HAVE_UNISTD_H
  26. #include <unistd.h>
  27. #endif
  28. /* SUBROUTINE UMASK(MASK, OLD)
  29. INTEGER, INTENT(IN) :: MASK
  30. INTEGER, INTENT(OUT), OPTIONAL :: OLD */
  31. extern void umask_i4_sub (GFC_INTEGER_4 *, GFC_INTEGER_4 *);
  32. iexport_proto(umask_i4_sub);
  33. void
  34. umask_i4_sub (GFC_INTEGER_4 *mask, GFC_INTEGER_4 *old)
  35. {
  36. mode_t val = umask((mode_t) *mask);
  37. if (old != NULL)
  38. *old = (GFC_INTEGER_4) val;
  39. }
  40. iexport(umask_i4_sub);
  41. extern void umask_i8_sub (GFC_INTEGER_8 *, GFC_INTEGER_8 *);
  42. iexport_proto(umask_i8_sub);
  43. void
  44. umask_i8_sub (GFC_INTEGER_8 *mask, GFC_INTEGER_8 *old)
  45. {
  46. mode_t val = umask((mode_t) *mask);
  47. if (old != NULL)
  48. *old = (GFC_INTEGER_8) val;
  49. }
  50. iexport(umask_i8_sub);
  51. /* INTEGER FUNCTION UMASK(MASK)
  52. INTEGER, INTENT(IN) :: MASK */
  53. extern GFC_INTEGER_4 umask_i4 (GFC_INTEGER_4 *);
  54. export_proto(umask_i4);
  55. GFC_INTEGER_4
  56. umask_i4 (GFC_INTEGER_4 *mask)
  57. {
  58. GFC_INTEGER_4 old;
  59. umask_i4_sub (mask, &old);
  60. return old;
  61. }
  62. extern GFC_INTEGER_8 umask_i8 (GFC_INTEGER_8 *);
  63. export_proto(umask_i8);
  64. GFC_INTEGER_8
  65. umask_i8 (GFC_INTEGER_8 *mask)
  66. {
  67. GFC_INTEGER_8 old;
  68. umask_i8_sub (mask, &old);
  69. return old;
  70. }