summaryrefslogtreecommitdiffhomepage
path: root/mixlib/mix_io.h
blob: 61d35da905540a1e1f69de820f9c899dfa314d94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* -*-c-*- ------------------ mix_io.h :
 * Declarations for mix_iochannel_t and mix_file_t
 * ------------------------------------------------------------------
 * Copyright (C) 2000, 2004 Free Software Foundation, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */


#ifndef MIX_IOCHANNEL_H
#define MIX_IOCHANNEL_H

#include <stdio.h>
#include "mix_types.h"

/* mix_iochannel_t: an object for input/output of mix types */
typedef struct mix_iochannel_t mix_iochannel_t;

/* Cast to mix_iochannel_t */
#define MIX_IOCHANNEL(file)  (mix_iochannel_t *)(file)

/* I/O channels can be created in different modes: */
typedef enum {
  mix_io_READ,			/* read existing file */
  mix_io_WRITE,			/* write new file */
  mix_io_RDWRT,			/* read/write existing from beginning */
  mix_io_APPEND,		/* append to existing or new file */
  mix_io_RAPPEND		/* read from beginning, append to end */
} mix_fmode_t;

/* Create from a file handle */
extern mix_iochannel_t *
mix_io_new (FILE *file);

/* Delete */
extern void
mix_io_delete (mix_iochannel_t *ch);

/* Convert to a FILE * */
extern FILE *
mix_io_to_FILE (mix_iochannel_t *ioc);

/* Read/write from/to an iochannel */
extern gboolean
mix_io_eof (mix_iochannel_t *ioc);

extern gboolean
mix_io_is_ready (mix_iochannel_t *ioc);

extern gboolean
mix_io_write_byte (mix_iochannel_t *ioc, mix_byte_t b);

extern gboolean
mix_io_write_byte_array (mix_iochannel_t *ioc, const mix_byte_t *b, size_t s);


extern mix_byte_t
mix_io_read_byte (mix_iochannel_t *ioc);

extern gboolean
mix_io_read_byte_array (mix_iochannel_t *ioc, mix_byte_t *b, size_t s);


extern gboolean
mix_io_write_word (mix_iochannel_t *ioc, mix_word_t w);


extern gboolean
mix_io_write_word_array (mix_iochannel_t *ioc, const mix_word_t *w, size_t s);

extern mix_word_t
mix_io_read_word (mix_iochannel_t *ioc);

extern gboolean
mix_io_read_word_array (mix_iochannel_t *ioc, mix_word_t *w, size_t s);

extern gboolean
mix_io_write_short (mix_iochannel_t *ioc, mix_short_t w);


extern gboolean
mix_io_write_short_array (mix_iochannel_t *ioc, const mix_short_t *w, size_t s);

extern mix_short_t
mix_io_read_short (mix_iochannel_t *ioc);

extern gboolean
mix_io_read_short_array (mix_iochannel_t *ioc, mix_short_t *w, size_t s);

extern gboolean
mix_io_write_char (mix_iochannel_t *ioc, mix_char_t c);

extern mix_char_t
mix_io_read_char (mix_iochannel_t *ioc);

extern gboolean
mix_io_write_word_array_as_char (mix_iochannel_t *ioc,
                                 const mix_word_t *w, size_t s);

extern gboolean
mix_io_read_word_array_as_char (mix_iochannel_t *ioc,
				mix_word_t *w, size_t s);


#endif /* MIX_IOCHANNEL_H */