files.scm 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ;;; files.scm --- The R6RS file system library
  2. ;; Copyright (C) 2010 Free Software Foundation, Inc.
  3. ;;
  4. ;; This library is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public
  6. ;; License as published by the Free Software Foundation; either
  7. ;; version 3 of the License, or (at your option) any later version.
  8. ;;
  9. ;; This library 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 GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this library; if not, write to the Free Software
  16. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (library (rnrs files (6))
  18. (export file-exists?
  19. delete-file
  20. &i/o make-i/o-error i/o-error?
  21. &i/o-read make-i/o-read-error i/o-read-error?
  22. &i/o-write make-i/o-write-error i/o-write-error?
  23. &i/o-invalid-position
  24. make-i/o-invalid-position-error
  25. i/o-invalid-position-error?
  26. i/o-error-position
  27. &i/o-filename
  28. make-i/o-filename-error
  29. i/o-filename-error?
  30. i/o-error-filename
  31. &i/o-file-protection
  32. make-i/o-file-protection-error
  33. i/o-file-protection-error?
  34. &i/o-file-is-read-only
  35. make-i/o-file-is-read-only-error
  36. i/o-file-is-read-only-error?
  37. &i/o-file-already-exists
  38. make-i/o-file-already-exists-error
  39. i/o-file-already-exists-error?
  40. &i/o-file-does-not-exist
  41. make-i/o-file-does-not-exist-error
  42. i/o-file-does-not-exist-error?
  43. &i/o-port
  44. make-i/o-port-error
  45. i/o-port-error?
  46. i/o-error-port)
  47. (import (rename (only (guile) file-exists? delete-file catch @@)
  48. (delete-file delete-file-internal))
  49. (rnrs base (6))
  50. (rnrs conditions (6))
  51. (rnrs exceptions (6)))
  52. (define (delete-file filename)
  53. (catch #t
  54. (lambda () (delete-file-internal filename))
  55. (lambda (key . args) (raise (make-i/o-filename-error filename)))))
  56. ;; Condition types that are used by (rnrs files), (rnrs io ports), and
  57. ;; (rnrs io simple). These are defined here so as to be easily shareable by
  58. ;; these three libraries.
  59. (define-condition-type &i/o &error make-i/o-error i/o-error?)
  60. (define-condition-type &i/o-read &i/o make-i/o-read-error i/o-read-error?)
  61. (define-condition-type &i/o-write &i/o make-i/o-write-error i/o-write-error?)
  62. (define-condition-type &i/o-invalid-position
  63. &i/o make-i/o-invalid-position-error i/o-invalid-position-error?
  64. (position i/o-error-position))
  65. (define-condition-type &i/o-filename
  66. &i/o make-i/o-filename-error i/o-filename-error?
  67. (filename i/o-error-filename))
  68. (define-condition-type &i/o-file-protection
  69. &i/o-filename make-i/o-file-protection-error i/o-file-protection-error?)
  70. (define-condition-type &i/o-file-is-read-only
  71. &i/o-file-protection make-i/o-file-is-read-only-error
  72. i/o-file-is-read-only-error?)
  73. (define-condition-type &i/o-file-already-exists
  74. &i/o-filename make-i/o-file-already-exists-error
  75. i/o-file-already-exists-error?)
  76. (define-condition-type &i/o-file-does-not-exist
  77. &i/o-filename make-i/o-file-does-not-exist-error
  78. i/o-file-does-not-exist-error?)
  79. (define-condition-type &i/o-port &i/o make-i/o-port-error i/o-port-error?
  80. (port i/o-error-port))
  81. )