fports.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* classes: h_files */
  2. #ifndef SCM_FPORTS_H
  3. #define SCM_FPORTS_H
  4. /* Copyright (C) 1995-2001, 2006, 2008, 2009, 2011, 2012,
  5. * 2017 Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. #include "libguile/__scm.h"
  23. #include "libguile/ports.h"
  24. /* struct allocated for each buffered FPORT. */
  25. typedef struct scm_t_fport {
  26. /* The file descriptor. */
  27. int fdes;
  28. /* Revealed count; 0 indicates not revealed, > 1 revealed. */
  29. unsigned int revealed;
  30. /* Set of scm_fport_option flags. */
  31. unsigned options;
  32. } scm_t_fport;
  33. SCM_API scm_t_port_type *scm_file_port_type;
  34. #define SCM_FSTREAM(x) ((scm_t_fport *) SCM_STREAM (x))
  35. #define SCM_FPORT_FDES(x) (SCM_FSTREAM (x)->fdes)
  36. #define SCM_FPORTP(x) \
  37. (SCM_PORTP (x) && SCM_PORT_TYPE (x) == scm_file_port_type)
  38. #define SCM_OPFPORTP(x) (SCM_FPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_OPN))
  39. #define SCM_OPINFPORTP(x) (SCM_OPFPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_RDNG))
  40. #define SCM_OPOUTFPORTP(x) (SCM_OPFPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_WRTNG))
  41. SCM_API void scm_evict_ports (int fd);
  42. SCM_INTERNAL int scm_i_mode_to_open_flags (SCM mode, int *is_binary,
  43. const char *FUNC_NAME);
  44. SCM_API SCM scm_open_file_with_encoding (SCM filename, SCM modes,
  45. SCM guess_encoding, SCM encoding);
  46. SCM_API SCM scm_open_file (SCM filename, SCM modes);
  47. SCM_API SCM scm_fdes_to_port (int fdes, char *mode, SCM name);
  48. SCM_API SCM scm_file_port_p (SCM obj);
  49. /* Revealed counts. */
  50. SCM_API int scm_revealed_count (SCM port);
  51. SCM_API SCM scm_port_revealed (SCM port);
  52. SCM_API SCM scm_set_port_revealed_x (SCM port, SCM rcount);
  53. SCM_API SCM scm_adjust_port_revealed_x (SCM port, SCM addend);
  54. SCM_INTERNAL void scm_init_fports_keywords (void);
  55. SCM_INTERNAL void scm_init_fports (void);
  56. /* internal functions */
  57. #ifdef BUILDING_LIBGUILE
  58. enum scm_fport_option
  59. {
  60. /* FD's that aren't created by Guile probably need to be checked for
  61. validity. We also check that the open mode is valid. */
  62. SCM_FPORT_OPTION_VERIFY = 1U<<0,
  63. /* We know some ports aren't seekable and can elide a syscall in
  64. that case. */
  65. SCM_FPORT_OPTION_NOT_SEEKABLE = 1U<<1
  66. };
  67. SCM_INTERNAL SCM scm_i_fdes_to_port (int fdes, long mode_bits, SCM name,
  68. unsigned options);
  69. #endif /* BUILDING_LIBGUILE */
  70. #endif /* SCM_FPORTS_H */
  71. /*
  72. Local Variables:
  73. c-file-style: "gnu"
  74. End:
  75. */