system.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Implementation of the SYSTEM intrinsic.
  2. Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. Contributed by Tobias Schlüter.
  4. This file is part of the GNU Fortran runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. Libgfortran is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. 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. extern void system_sub (const char *fcmd, GFC_INTEGER_4 * status,
  22. gfc_charlen_type cmd_len);
  23. iexport_proto(system_sub);
  24. void
  25. system_sub (const char *fcmd, GFC_INTEGER_4 *status, gfc_charlen_type cmd_len)
  26. {
  27. char *cmd = fc_strdup (fcmd, cmd_len);
  28. int stat;
  29. /* Flush all I/O units before executing the command. */
  30. flush_all_units();
  31. stat = system (cmd);
  32. free (cmd);
  33. if (status)
  34. *status = stat;
  35. }
  36. iexport(system_sub);
  37. extern GFC_INTEGER_4 PREFIX(system) (const char *, gfc_charlen_type);
  38. export_proto_np(PREFIX(system));
  39. GFC_INTEGER_4
  40. PREFIX(system) (const char *fcmd, gfc_charlen_type cmd_len)
  41. {
  42. GFC_INTEGER_4 stat;
  43. system_sub (fcmd, &stat, cmd_len);
  44. return stat;
  45. }