system.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Implementation of the SYSTEM intrinsic.
  2. Copyright (C) 2004-2015 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. #include <string.h>
  22. #include <stdlib.h>
  23. extern void system_sub (const char *fcmd, GFC_INTEGER_4 * status,
  24. gfc_charlen_type cmd_len);
  25. iexport_proto(system_sub);
  26. void
  27. system_sub (const char *fcmd, GFC_INTEGER_4 *status, gfc_charlen_type cmd_len)
  28. {
  29. char *cmd = fc_strdup (fcmd, cmd_len);
  30. int stat;
  31. /* Flush all I/O units before executing the command. */
  32. flush_all_units();
  33. stat = system (cmd);
  34. free (cmd);
  35. if (status)
  36. *status = stat;
  37. }
  38. iexport(system_sub);
  39. extern GFC_INTEGER_4 PREFIX(system) (const char *, gfc_charlen_type);
  40. export_proto_np(PREFIX(system));
  41. GFC_INTEGER_4
  42. PREFIX(system) (const char *fcmd, gfc_charlen_type cmd_len)
  43. {
  44. GFC_INTEGER_4 stat;
  45. system_sub (fcmd, &stat, cmd_len);
  46. return stat;
  47. }