glib2 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/ChangeLog +3023 -0
  2. data/README +28 -0
  3. data/Rakefile +87 -0
  4. data/extconf.rb +61 -0
  5. data/sample/bookmarkfile.rb +66 -0
  6. data/sample/completion.rb +45 -0
  7. data/sample/idle.rb +41 -0
  8. data/sample/iochannel.rb +44 -0
  9. data/sample/keyfile.rb +62 -0
  10. data/sample/shell.rb +36 -0
  11. data/sample/spawn.rb +25 -0
  12. data/sample/timeout.rb +28 -0
  13. data/sample/timeout2.rb +35 -0
  14. data/sample/timer.rb +40 -0
  15. data/sample/type-register.rb +103 -0
  16. data/sample/type-register2.rb +104 -0
  17. data/sample/utils.rb +54 -0
  18. data/src/glib-enum-types.c +1032 -0
  19. data/src/glib-enum-types.h +140 -0
  20. data/src/lib/glib-mkenums.rb +199 -0
  21. data/src/lib/glib2.rb +220 -0
  22. data/src/lib/mkmf-gnome2.rb +390 -0
  23. data/src/lib/pkg-config.rb +137 -0
  24. data/src/rbgcompat.h +30 -0
  25. data/src/rbglib.c +320 -0
  26. data/src/rbglib.h +96 -0
  27. data/src/rbglib_bookmarkfile.c +595 -0
  28. data/src/rbglib_completion.c +192 -0
  29. data/src/rbglib_convert.c +195 -0
  30. data/src/rbglib_error.c +95 -0
  31. data/src/rbglib_fileutils.c +83 -0
  32. data/src/rbglib_i18n.c +44 -0
  33. data/src/rbglib_int64.c +157 -0
  34. data/src/rbglib_iochannel.c +883 -0
  35. data/src/rbglib_keyfile.c +846 -0
  36. data/src/rbglib_maincontext.c +917 -0
  37. data/src/rbglib_mainloop.c +87 -0
  38. data/src/rbglib_messages.c +150 -0
  39. data/src/rbglib_pollfd.c +111 -0
  40. data/src/rbglib_shell.c +68 -0
  41. data/src/rbglib_source.c +190 -0
  42. data/src/rbglib_spawn.c +345 -0
  43. data/src/rbglib_threads.c +51 -0
  44. data/src/rbglib_timer.c +127 -0
  45. data/src/rbglib_unicode.c +611 -0
  46. data/src/rbglib_utils.c +386 -0
  47. data/src/rbglib_win32.c +136 -0
  48. data/src/rbgobj_boxed.c +251 -0
  49. data/src/rbgobj_closure.c +337 -0
  50. data/src/rbgobj_convert.c +167 -0
  51. data/src/rbgobj_enums.c +961 -0
  52. data/src/rbgobj_fundamental.c +30 -0
  53. data/src/rbgobj_object.c +892 -0
  54. data/src/rbgobj_param.c +390 -0
  55. data/src/rbgobj_paramspecs.c +305 -0
  56. data/src/rbgobj_signal.c +963 -0
  57. data/src/rbgobj_strv.c +61 -0
  58. data/src/rbgobj_type.c +851 -0
  59. data/src/rbgobj_typeinstance.c +121 -0
  60. data/src/rbgobj_typeinterface.c +148 -0
  61. data/src/rbgobj_typemodule.c +66 -0
  62. data/src/rbgobj_typeplugin.c +49 -0
  63. data/src/rbgobj_value.c +313 -0
  64. data/src/rbgobj_valuearray.c +59 -0
  65. data/src/rbgobj_valuetypes.c +298 -0
  66. data/src/rbgobject.c +406 -0
  67. data/src/rbgobject.h +265 -0
  68. data/src/rbgprivate.h +88 -0
  69. data/src/rbgutil.c +222 -0
  70. data/src/rbgutil.h +82 -0
  71. data/src/rbgutil_callback.c +231 -0
  72. data/test/glib-test-init.rb +6 -0
  73. data/test/glib-test-utils.rb +12 -0
  74. data/test/run-test.rb +25 -0
  75. data/test/test_enum.rb +99 -0
  76. data/test/test_file_utils.rb +15 -0
  77. data/test/test_glib2.rb +120 -0
  78. data/test/test_iochannel.rb +275 -0
  79. data/test/test_key_file.rb +38 -0
  80. data/test/test_mkenums.rb +25 -0
  81. data/test/test_signal.rb +20 -0
  82. data/test/test_timeout.rb +28 -0
  83. data/test/test_unicode.rb +369 -0
  84. data/test/test_utils.rb +37 -0
  85. data/test/test_win32.rb +13 -0
  86. metadata +165 -0
@@ -0,0 +1,83 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbglib_fileutils.c -
5
+
6
+ $Author: mutoh $
7
+ $Date: 2004/09/17 15:09:07 $
8
+
9
+ Copyright (C) 2004 Masao Mutoh
10
+
11
+ **********************************************************************/
12
+
13
+ #include "rbgprivate.h"
14
+ #include "rbglib.h"
15
+
16
+ /* Use Ruby standard libraries.
17
+ enum GFileTest;
18
+ GFileError g_file_error_from_errno (gint err_no);
19
+ gboolean g_file_get_contents (const gchar *filename,
20
+ gchar **contents,
21
+ gsize *length,
22
+ GError **error);
23
+ gboolean g_file_test (const gchar *filename,
24
+ GFileTest test);
25
+ gint g_mkstemp (gchar *tmpl);
26
+ gint g_file_open_tmp (const gchar *tmpl,
27
+ gchar **name_used,
28
+ GError **error);
29
+ gchar* g_file_read_link (const gchar *filename,
30
+ GError **error);
31
+
32
+ struct GDir;
33
+ GDir* g_dir_open (const gchar *path,
34
+ guint flags,
35
+ GError **error);
36
+ G_CONST_RETURN gchar* g_dir_read_name (GDir *dir);
37
+ void g_dir_rewind (GDir *dir);
38
+ void g_dir_close (GDir *dir);
39
+ */
40
+
41
+ #if GLIB_CHECK_VERSION(2, 16, 0)
42
+ static VALUE
43
+ rbglib_m_format_size_for_display(VALUE self, VALUE size)
44
+ {
45
+ return CSTR2RVAL_FREE(g_format_size_for_display(NUM2INT(size)));
46
+ }
47
+ #endif
48
+
49
+ void
50
+ Init_glib_fileutils()
51
+ {
52
+ VALUE cFileError = G_DEF_ERROR2(G_FILE_ERROR, "FileError", mGLib, rb_eIOError);
53
+
54
+ rb_define_const(cFileError, "EXIST", INT2NUM(G_FILE_ERROR_EXIST));
55
+ rb_define_const(cFileError, "ISDIR", INT2NUM(G_FILE_ERROR_ISDIR));
56
+ rb_define_const(cFileError, "ACCES", INT2NUM(G_FILE_ERROR_ACCES));
57
+ rb_define_const(cFileError, "NAMETOOLONG", INT2NUM(G_FILE_ERROR_NAMETOOLONG));
58
+ rb_define_const(cFileError, "NOENT", INT2NUM(G_FILE_ERROR_NOENT));
59
+ rb_define_const(cFileError, "NOTDIR", INT2NUM(G_FILE_ERROR_NOTDIR));
60
+ rb_define_const(cFileError, "NXIO", INT2NUM(G_FILE_ERROR_NXIO));
61
+ rb_define_const(cFileError, "NODEV", INT2NUM(G_FILE_ERROR_NODEV));
62
+ rb_define_const(cFileError, "ROFS", INT2NUM(G_FILE_ERROR_ROFS));
63
+ rb_define_const(cFileError, "TXTBSY", INT2NUM(G_FILE_ERROR_TXTBSY));
64
+ rb_define_const(cFileError, "FAULT", INT2NUM(G_FILE_ERROR_FAULT));
65
+ rb_define_const(cFileError, "LOOP", INT2NUM(G_FILE_ERROR_LOOP));
66
+ rb_define_const(cFileError, "NOSPC", INT2NUM(G_FILE_ERROR_NOSPC));
67
+ rb_define_const(cFileError, "NOMEM", INT2NUM(G_FILE_ERROR_NOMEM));
68
+ rb_define_const(cFileError, "MFILE", INT2NUM(G_FILE_ERROR_MFILE));
69
+ rb_define_const(cFileError, "NFILE", INT2NUM(G_FILE_ERROR_NFILE));
70
+ rb_define_const(cFileError, "BADF", INT2NUM(G_FILE_ERROR_BADF));
71
+ rb_define_const(cFileError, "INVAL", INT2NUM(G_FILE_ERROR_INVAL));
72
+ rb_define_const(cFileError, "PIPE", INT2NUM(G_FILE_ERROR_PIPE));
73
+ rb_define_const(cFileError, "AGAIN", INT2NUM(G_FILE_ERROR_AGAIN));
74
+ rb_define_const(cFileError, "INTR", INT2NUM(G_FILE_ERROR_INTR));
75
+ rb_define_const(cFileError, "IO", INT2NUM(G_FILE_ERROR_IO));
76
+ rb_define_const(cFileError, "PERM", INT2NUM(G_FILE_ERROR_PERM));
77
+ rb_define_const(cFileError, "FAILED", INT2NUM(G_FILE_ERROR_FAILED));
78
+
79
+ #if GLIB_CHECK_VERSION(2, 16, 0)
80
+ rb_define_module_function(mGLib, "format_size_for_display",
81
+ rbglib_m_format_size_for_display, 1);
82
+ #endif
83
+ }
data/src/rbglib_i18n.c ADDED
@@ -0,0 +1,44 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbglib_i18n.c -
5
+
6
+ $Author: ktou $
7
+ $Date: 2006/02/08 14:54:51 $
8
+
9
+ Copyright (C) 2006 Kouhei Sutou
10
+
11
+ **********************************************************************/
12
+
13
+ #include "rbgprivate.h"
14
+ #include "rbglib.h"
15
+ #undef _
16
+ #include <glib/gi18n.h>
17
+
18
+ #if GLIB_CHECK_VERSION(2,6,0)
19
+ static VALUE
20
+ rbglib_m_language_names(self)
21
+ VALUE self;
22
+ {
23
+ const gchar * const *languages;
24
+ const gchar *language;
25
+ VALUE rb_languages = rb_ary_new();
26
+
27
+ languages = g_get_language_names();
28
+ for (language = *languages; *languages; language = *(++languages)) {
29
+ rb_ary_push(rb_languages, CSTR2RVAL(language));
30
+ }
31
+
32
+ return rb_languages;
33
+ }
34
+ #endif
35
+
36
+ void
37
+ Init_glib_i18n()
38
+ {
39
+ /* glib/gi18n.h */
40
+ #if GLIB_CHECK_VERSION(2,6,0)
41
+ rb_define_module_function(mGLib, "language_names",
42
+ rbglib_m_language_names, 0);
43
+ #endif
44
+ }
@@ -0,0 +1,157 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ utils_int64.c -
5
+
6
+ $Author: isambart $
7
+ $Date: 2007/08/14 10:35:04 $
8
+
9
+ Copyright (C) 2003 Masahiro Sakai
10
+ Copyright (C) 2002 Masahiro Sakai
11
+ Kenichi Komiya
12
+
13
+ **********************************************************************/
14
+
15
+ #include <glib/gtypes.h>
16
+ #include "rbglib.h"
17
+
18
+ static ID id_and;
19
+ static ID id_rshift;
20
+ static ID id_lshift;
21
+ static ID id_lt;
22
+ static ID id_plus;
23
+ static ID id_uminus;
24
+ static ID id_abs;
25
+ static VALUE max_PRUint32;
26
+
27
+ typedef guint64 PRUint64;
28
+ typedef gint64 PRInt64;
29
+
30
+ #define LL_ZERO G_GINT64_CONSTANT(0)
31
+ #define LL_UI2L(lhs,rhs) ((lhs)=(rhs))
32
+ #define LL_L2UI(lhs,rhs) ((lhs)=(guint32)(rhs))
33
+ #define LL_SHL(lhs,v1,v2) ((lhs)=(v1)<<(v2))
34
+ #define LL_SHR(lhs,v1,v2) ((lhs)=(v1)>>(v2))
35
+ #define LL_ADD(lhs,v1,v2) ((lhs)=(v1)+(v2))
36
+ #define LL_NEG(lhs,rhs) ((lhs)=-(rhs))
37
+ #define LL_CMP(v1,op,v2) ((v1) op (v2))
38
+
39
+ /**********************************************************************/
40
+ /*
41
+ following is ripped from rbXPCOM-0.0.3
42
+ http://www.ruby-lang.org/en/raa-list.rhtml?name=rbXPCOM
43
+ Copyright (C) 2001 Kenichi Komiya <kom@mail1.accsnet.ne.jp>
44
+ */
45
+
46
+ static PRUint64
47
+ RubyTo64BitInt(VALUE aRuby)
48
+ {
49
+ VALUE bitMask = max_PRUint32;
50
+ VALUE lo = rb_funcall(aRuby, id_and, 1, bitMask);
51
+ VALUE hi = rb_funcall(aRuby, id_rshift, 1, INT2FIX(32));
52
+ PRUint64 result, hi64, lo64;
53
+ LL_UI2L(hi64, NUM2UINT(hi));
54
+ LL_UI2L(lo64, NUM2UINT(lo));
55
+ LL_SHL(result, hi64, 32);
56
+ LL_ADD(result, result, lo64);
57
+ return result;
58
+ }
59
+
60
+
61
+ static inline PRUint64
62
+ RubyToPRUint64(VALUE aRuby)
63
+ {
64
+ return RubyTo64BitInt(aRuby);
65
+ }
66
+
67
+
68
+ static PRInt64
69
+ RubyToPRInt64(VALUE aRuby)
70
+ {
71
+ if(RVAL2CBOOL(rb_funcall(aRuby, id_lt, 1, INT2FIX(0))))
72
+ {
73
+ VALUE absRuby = rb_funcall(aRuby, id_abs, 0);
74
+ PRInt64 result;
75
+ LL_NEG(result, RubyTo64BitInt(absRuby));
76
+ return result;
77
+ } else
78
+ return (PRInt64)RubyTo64BitInt(aRuby);
79
+
80
+ }
81
+
82
+ static VALUE
83
+ RubyFrom64BitInt(PRUint64 aNative)
84
+ {
85
+ PRUint64 lo64, hi64;
86
+ LL_L2UI(lo64, aNative);
87
+ LL_SHR(hi64, aNative, 32);
88
+ {
89
+ VALUE lo = UINT2NUM(lo64);
90
+ VALUE hi = UINT2NUM(hi64);
91
+ VALUE hiRuby = rb_funcall(hi, id_lshift, 1, INT2FIX(32));
92
+ return rb_funcall(hiRuby, id_plus, 1, lo);
93
+ }
94
+ }
95
+
96
+ static inline VALUE
97
+ PRUint64ToRuby(PRUint64 aNative)
98
+ {
99
+ return RubyFrom64BitInt(aNative);
100
+ }
101
+
102
+ static VALUE
103
+ PRInt64ToRuby(PRInt64 aNative)
104
+ {
105
+ if(LL_CMP(aNative, <, LL_ZERO))
106
+ {
107
+ PRUint64 abs64;
108
+ LL_NEG(abs64, aNative);
109
+ return rb_funcall(RubyFrom64BitInt(abs64), id_uminus, 0);
110
+ }
111
+ else
112
+ return RubyFrom64BitInt((PRUint64)aNative);
113
+ }
114
+
115
+ /* end of ripping */
116
+ /**********************************************************************/
117
+
118
+ VALUE
119
+ rbglib_int64_to_num(guint64 val)
120
+ {
121
+ return PRInt64ToRuby(val);
122
+ }
123
+
124
+ VALUE
125
+ rbglib_uint64_to_num(guint64 val)
126
+ {
127
+ return PRUint64ToRuby(val);
128
+ }
129
+
130
+ gint64
131
+ rbglib_num_to_int64(VALUE val)
132
+ {
133
+ return RubyToPRInt64(val);
134
+ }
135
+
136
+ guint64
137
+ rbglib_num_to_uint64(VALUE val)
138
+ {
139
+ return RubyToPRUint64(val);
140
+ }
141
+
142
+ /**********************************************************************/
143
+
144
+ void
145
+ Init_glib_int64()
146
+ {
147
+ id_and = rb_intern("&");
148
+ id_rshift = rb_intern(">>");
149
+ id_lshift = rb_intern("<<");
150
+ id_lt = rb_intern("<");
151
+ id_plus = rb_intern("+");
152
+ id_uminus = rb_intern("-@");
153
+ id_abs = rb_intern("abs");
154
+
155
+ rb_global_variable(&max_PRUint32);
156
+ max_PRUint32 = UINT2NUM(0xffffffffL);
157
+ }
@@ -0,0 +1,883 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbglib_iochannel.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:28 $
8
+
9
+ Copyright (C) 2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgprivate.h"
13
+
14
+ static ID id_call;
15
+
16
+ #define _SELF(s) ((GIOChannel*)RVAL2BOXED(s, G_TYPE_IO_CHANNEL))
17
+
18
+ static void
19
+ ioc_error(status, err)
20
+ GIOStatus status;
21
+ GError* err;
22
+ {
23
+ if (err != NULL) RAISE_GERROR(err);
24
+
25
+ if (status == G_IO_STATUS_EOF){
26
+ rb_raise(rb_eEOFError, "End of file reached");
27
+ } else if (status == G_IO_STATUS_AGAIN){
28
+ rb_raise(rb_eRuntimeError, "G_IO_STATUS_AGAIN");
29
+ } else if (status == G_IO_STATUS_NORMAL){
30
+ /* Do nothing */
31
+ } else {
32
+ rb_raise(rb_eRuntimeError, "An error occured. status = %d\n", status);
33
+ }
34
+ }
35
+
36
+ static VALUE
37
+ ioc_initialize(argc, argv, self)
38
+ gint argc;
39
+ VALUE* argv;
40
+ VALUE self;
41
+ {
42
+ VALUE arg1, arg2;
43
+
44
+ GIOChannel* io = NULL;
45
+ rb_secure(4);
46
+ rb_scan_args(argc, argv, "11", &arg1, &arg2);
47
+
48
+ if (TYPE(arg1) != T_STRING){
49
+ #ifdef G_OS_UNIX
50
+ if (TYPE(arg1) == T_FIXNUM){
51
+ io = g_io_channel_unix_new(NUM2INT(arg1));
52
+ } else {
53
+ io = g_io_channel_unix_new(NUM2INT(rb_funcall(arg1, rb_intern("to_i"), 0)));
54
+ }
55
+ #else
56
+ rb_raise(rb_eRuntimeError, "GLib::IOChannel.new(fd) is supported on UNIX environment only");
57
+ #endif
58
+ } else {
59
+ GError* err = NULL;
60
+ io = g_io_channel_new_file(RVAL2CSTR(arg1),
61
+ NIL_P(arg2) ? "r" : RVAL2CSTR(arg2), &err);
62
+
63
+ if (err != NULL) RAISE_GERROR(err);
64
+ }
65
+
66
+ G_INITIALIZE(self, io);
67
+
68
+ return Qnil;
69
+ }
70
+
71
+ static VALUE
72
+ ioc_close(self)
73
+ VALUE self;
74
+ {
75
+ GError* err = NULL;
76
+ GIOStatus status = g_io_channel_shutdown(_SELF(self), TRUE, &err);
77
+
78
+ ioc_error(status, err);
79
+ return self;
80
+ }
81
+
82
+ static VALUE
83
+ ioc_s_open(argc, argv, self)
84
+ gint argc;
85
+ VALUE* argv;
86
+ VALUE self;
87
+ {
88
+ VALUE arg1, arg2;
89
+ VALUE rio;
90
+ GIOChannel* io = NULL;
91
+
92
+ rb_scan_args(argc, argv, "11", &arg1, &arg2);
93
+
94
+ if (TYPE(arg1) == T_FIXNUM){
95
+ #ifdef G_OS_UNIX
96
+ io = g_io_channel_unix_new(NUM2INT(arg1));
97
+ #else
98
+ rb_raise(rb_eRuntimeError, "GLib::IOChannel.new(fd) is supported on UNIX environment only");
99
+ #endif
100
+ } else {
101
+ GError* err = NULL;
102
+ io = g_io_channel_new_file(RVAL2CSTR(arg1),
103
+ NIL_P(arg2) ? "r" : RVAL2CSTR(arg2), &err);
104
+
105
+ if (err != NULL) RAISE_GERROR(err);
106
+ }
107
+
108
+ rio = BOXED2RVAL(io, G_TYPE_IO_CHANNEL);
109
+
110
+ if (rb_block_given_p()) {
111
+ return rb_ensure(rb_yield, rio, ioc_close, rio);
112
+ }
113
+ return rio;
114
+ }
115
+
116
+ static VALUE
117
+ ioc_get_fd(self)
118
+ VALUE self;
119
+ {
120
+ #ifdef G_OS_UNIX
121
+ return INT2NUM(g_io_channel_unix_get_fd(_SELF(self)));
122
+ #else
123
+ rb_warn("GLib::IOChannel#fd is supported on UNIX environment only.");
124
+ return Qnil;
125
+ #endif
126
+ }
127
+
128
+ /* Don't need this
129
+ void g_io_channel_init (GIOChannel *channel);
130
+ */
131
+
132
+
133
+ static VALUE
134
+ ioc_read_chars(argc, argv, self)
135
+ gint argc;
136
+ VALUE* argv;
137
+ VALUE self;
138
+ {
139
+ VALUE count, ret;
140
+ gchar* buf;
141
+ gsize bytes_read;
142
+ GError* err = NULL;
143
+ GIOStatus status;
144
+
145
+ rb_scan_args(argc, argv, "01", &count);
146
+
147
+ if (NIL_P(count)){
148
+ gsize length;
149
+ status = g_io_channel_read_to_end(_SELF(self), &buf,
150
+ &length, &err);
151
+
152
+ if (status == G_IO_STATUS_EOF){
153
+ ret = CSTR2RVAL("");
154
+ } else {
155
+ ioc_error(status, err);
156
+ }
157
+ ret = buf ? rb_str_new(buf, length) : CSTR2RVAL("");
158
+ g_free(buf);
159
+ } else {
160
+ buf = ALLOCA_N(gchar, count);
161
+ memset(buf, '\0', count);
162
+
163
+ status = g_io_channel_read_chars(_SELF(self), buf, NUM2UINT(count),
164
+ &bytes_read, &err);
165
+ if (status == G_IO_STATUS_EOF){
166
+ ret = CSTR2RVAL("");
167
+ } else {
168
+ ioc_error(status, err);
169
+ }
170
+ ret = buf ? CSTR2RVAL(buf) : CSTR2RVAL("");
171
+ }
172
+ return ret;
173
+ }
174
+
175
+ static VALUE
176
+ ioc_read_unichar(self)
177
+ VALUE self;
178
+ {
179
+ gunichar thechar;
180
+ GError* err = NULL;
181
+ GIOStatus status = g_io_channel_read_unichar(_SELF(self), &thechar, &err);
182
+
183
+ ioc_error(status, err);
184
+
185
+ return UINT2NUM(thechar);
186
+ }
187
+
188
+ static VALUE
189
+ ioc_getuc(self)
190
+ VALUE self;
191
+ {
192
+ gunichar thechar;
193
+ GError* err = NULL;
194
+ VALUE ret;
195
+ GIOStatus status = g_io_channel_read_unichar(_SELF(self), &thechar, &err);
196
+
197
+ if (status == G_IO_STATUS_EOF){
198
+ ret = Qnil;
199
+ } else {
200
+ ioc_error(status, err);
201
+ ret = UINT2NUM(thechar);
202
+ }
203
+
204
+ return ret;
205
+ }
206
+
207
+ static VALUE
208
+ ioc_each_char(self)
209
+ VALUE self;
210
+ {
211
+ if (!rb_block_given_p()) {
212
+ rb_raise(rb_eArgError, "called without a block");
213
+ }
214
+
215
+ while (TRUE){
216
+ gunichar thechar;
217
+ GError* err = NULL;
218
+ GIOStatus status = g_io_channel_read_unichar(_SELF(self), &thechar, &err);
219
+ if (status == G_IO_STATUS_EOF){
220
+ break;
221
+ } else {
222
+ ioc_error(status, err);
223
+ rb_yield(UINT2NUM(thechar));
224
+ }
225
+ }
226
+ return self;
227
+ }
228
+
229
+ static VALUE
230
+ ioc_read_line(argc, argv, self)
231
+ gint argc;
232
+ VALUE* argv;
233
+ VALUE self;
234
+ {
235
+ gchar* str;
236
+ VALUE line_term, ret;
237
+ GIOStatus status;
238
+ GError* err = NULL;
239
+
240
+ const gchar* old_line_term = NULL;
241
+ gint old_line_term_len;
242
+
243
+ rb_scan_args(argc, argv, "01", &line_term);
244
+
245
+ if (! NIL_P(line_term)){
246
+ StringValue(line_term);
247
+ old_line_term = g_io_channel_get_line_term(_SELF(self), &old_line_term_len);
248
+
249
+ g_io_channel_set_line_term(_SELF(self), RVAL2CSTR(line_term),
250
+ RSTRING_LEN(line_term));
251
+ }
252
+
253
+ status = g_io_channel_read_line(_SELF(self), &str, NULL, NULL, &err);
254
+
255
+ if (! NIL_P(line_term)){
256
+ g_io_channel_set_line_term(_SELF(self), old_line_term, old_line_term_len);
257
+ }
258
+
259
+ ioc_error(status, err);
260
+
261
+ ret = str ? CSTR2RVAL(str) : CSTR2RVAL("");
262
+ g_free(str);
263
+
264
+ return ret;
265
+ }
266
+
267
+ static VALUE
268
+ ioc_gets(argc, argv, self)
269
+ gint argc;
270
+ VALUE* argv;
271
+ VALUE self;
272
+ {
273
+ gchar* str;
274
+ VALUE line_term, ret;
275
+ GIOStatus status;
276
+ GError* err = NULL;
277
+
278
+ const gchar* old_line_term = NULL;
279
+ gint old_line_term_len;
280
+
281
+ rb_scan_args(argc, argv, "01", &line_term);
282
+
283
+ if (! NIL_P(line_term)){
284
+ StringValue(line_term);
285
+
286
+ old_line_term = g_io_channel_get_line_term(_SELF(self), &old_line_term_len);
287
+ g_io_channel_set_line_term(_SELF(self), RVAL2CSTR(line_term),
288
+ RSTRING_LEN(line_term));
289
+ }
290
+
291
+ status = g_io_channel_read_line(_SELF(self), &str, NULL, NULL, &err);
292
+
293
+ if (! NIL_P(line_term)){
294
+ g_io_channel_set_line_term(_SELF(self), old_line_term, old_line_term_len);
295
+ }
296
+
297
+ if (status == G_IO_STATUS_EOF){
298
+ ret = Qnil;
299
+ } else {
300
+ ioc_error(status, err);
301
+ ret = str ? CSTR2RVAL(str) : CSTR2RVAL("");
302
+ }
303
+ g_free(str);
304
+
305
+ return ret;
306
+ }
307
+
308
+ /* Internal use only */
309
+ static VALUE
310
+ ioc_set_line_term(args)
311
+ VALUE args;
312
+ {
313
+ VALUE self = RARRAY_PTR(args)[0];
314
+ VALUE doit = RARRAY_PTR(args)[1];
315
+ VALUE line_term = RARRAY_PTR(args)[2];
316
+
317
+ if (doit == Qtrue){
318
+ StringValue(line_term);
319
+ g_io_channel_set_line_term(_SELF(self), RVAL2CSTR(line_term),
320
+ RSTRING_LEN(line_term));
321
+ }
322
+ return self;
323
+ }
324
+
325
+ static VALUE
326
+ ioc_each_line(argc, argv, self)
327
+ gint argc;
328
+ VALUE* argv;
329
+ VALUE self;
330
+ {
331
+ gchar* str;
332
+ VALUE line_term;
333
+ GIOStatus status;
334
+ GError* err = NULL;
335
+
336
+ const gchar* old_line_term = NULL;
337
+ gint old_line_term_len;
338
+
339
+ if (!rb_block_given_p()) {
340
+ rb_raise(rb_eArgError, "called without a block");
341
+ }
342
+
343
+ rb_scan_args(argc, argv, "01", &line_term);
344
+
345
+ if (! NIL_P(line_term)){
346
+ StringValue(line_term);
347
+
348
+ old_line_term = g_io_channel_get_line_term(_SELF(self), &old_line_term_len);
349
+ g_io_channel_set_line_term(_SELF(self), RVAL2CSTR(line_term),
350
+ RSTRING_LEN(line_term));
351
+ }
352
+
353
+ while (TRUE){
354
+ status = g_io_channel_read_line(_SELF(self), &str, NULL, NULL, &err);
355
+ if (status == G_IO_STATUS_EOF){
356
+ break;
357
+ } else {
358
+ VALUE rstr;
359
+ ioc_error(status, err);
360
+ rstr = str ? CSTR2RVAL(str) : CSTR2RVAL("");
361
+ g_free(str);
362
+ rb_ensure(rb_yield, rstr, ioc_set_line_term,
363
+ rb_ary_new3(3, self,
364
+ NIL_P(line_term) ? Qfalse : Qtrue,
365
+ old_line_term ? rb_str_new(old_line_term, old_line_term_len) : Qnil));
366
+ }
367
+ }
368
+ return self;
369
+ }
370
+
371
+
372
+ /* Don't need this.
373
+ GIOStatus g_io_channel_read_line_string (GIOChannel *channel,
374
+ GString *buffer,
375
+ gsize *terminator_pos,
376
+ GError **error);
377
+ */
378
+
379
+ /* Use GLib::IOChannel#read instead.
380
+ static VALUE
381
+ ioc_read_to_end(self)
382
+ VALUE self;
383
+ {
384
+ gchar* str;
385
+ gsize length;
386
+ VALUE ret;
387
+ GError* err = NULL;
388
+
389
+ GIOStatus status = g_io_channel_read_to_end(_SELF(self), &str,
390
+ &length, &err);
391
+
392
+ ioc_error(status, err);
393
+
394
+ ret = str ? rb_str_new(str, length) : CSTR2RVAL("");
395
+ g_free(str);
396
+
397
+ return ret;
398
+ }
399
+ */
400
+
401
+ static VALUE
402
+ ioc_write_chars(self, buf)
403
+ VALUE self, buf;
404
+ {
405
+ gssize count;
406
+ gsize bytes_written;
407
+ GIOStatus status;
408
+ GError* err = NULL;
409
+
410
+ rb_secure(4);
411
+ buf = rb_obj_as_string(buf);
412
+
413
+ StringValue(buf);
414
+
415
+ count = RSTRING_LEN(buf);
416
+
417
+ status = g_io_channel_write_chars(_SELF(self), RVAL2CSTR(buf), count, &bytes_written, &err);
418
+
419
+ ioc_error(status, err);
420
+ return self;
421
+ }
422
+
423
+ static ID id_unpack;
424
+
425
+ static VALUE
426
+ ioc_write_unichar(self, thechar)
427
+ VALUE self, thechar;
428
+ {
429
+ GError* err = NULL;
430
+ GIOStatus status;
431
+ gunichar unichar;
432
+
433
+ rb_secure(4);
434
+ if (TYPE(thechar) == T_FIXNUM) {
435
+ unichar = NUM2UINT(thechar);
436
+ } else {
437
+ VALUE ary = rb_funcall(thechar, id_unpack, 1, CSTR2RVAL("U"));
438
+ unichar = NUM2UINT(RARRAY_PTR(ary)[0]);
439
+ }
440
+
441
+ status = g_io_channel_write_unichar(_SELF(self), unichar, &err);
442
+
443
+ ioc_error(status, err);
444
+
445
+ return self;
446
+ }
447
+
448
+ static VALUE
449
+ ioc_flush(self)
450
+ VALUE self;
451
+ {
452
+ GError* err = NULL;
453
+ GIOStatus status = g_io_channel_flush(_SELF(self), &err);
454
+ ioc_error(status, err);
455
+ return self;
456
+ }
457
+
458
+ static VALUE
459
+ ioc_seek(argc, argv, self)
460
+ gint argc;
461
+ VALUE* argv;
462
+ VALUE self;
463
+ {
464
+ VALUE ofs, type;
465
+ GIOStatus status;
466
+ GError* err = NULL;
467
+ GSeekType gtype = G_SEEK_SET;
468
+
469
+ rb_scan_args(argc, argv, "11", &ofs, &type);
470
+
471
+ if (!NIL_P(type))
472
+ gtype = NUM2INT(type);
473
+
474
+ status = g_io_channel_seek_position(_SELF(self), NUM2INT(ofs),
475
+ gtype, &err);
476
+ ioc_error(status, err);
477
+ return self;
478
+ }
479
+
480
+ static VALUE
481
+ ioc_seek_pos(self, pos)
482
+ VALUE self, pos;
483
+ {
484
+ GError* err = NULL;
485
+ GIOStatus status = g_io_channel_seek_position(_SELF(self), NUM2INT(pos),
486
+ G_SEEK_SET, &err);
487
+ ioc_error(status, err);
488
+ return self;
489
+ }
490
+
491
+ static VALUE
492
+ ioc_shutdown(argc, argv, self)
493
+ gint argc;
494
+ VALUE* argv;
495
+ VALUE self;
496
+ {
497
+ VALUE flush;
498
+ GError* err = NULL;
499
+ gboolean gflush = TRUE;
500
+ GIOStatus status;
501
+
502
+ rb_scan_args(argc, argv, "01", &flush);
503
+
504
+ if (!NIL_P(flush)){
505
+ gflush = RVAL2CBOOL(flush);
506
+ }
507
+
508
+ status = g_io_channel_shutdown(_SELF(self), gflush, &err);
509
+ ioc_error(status, err);
510
+
511
+ return self;
512
+ }
513
+
514
+ static VALUE
515
+ ioc_create_watch(self, condition)
516
+ VALUE self, condition;
517
+ {
518
+ return BOXED2RVAL(g_io_create_watch(_SELF(self), NUM2INT(condition)),
519
+ G_TYPE_SOURCE);
520
+ }
521
+
522
+ static gboolean
523
+ io_func(source, condition, func)
524
+ GIOChannel* source;
525
+ GIOCondition condition;
526
+ gpointer func;
527
+ {
528
+ return RVAL2CBOOL(rb_funcall((VALUE)func, id_call, 2,
529
+ BOXED2RVAL(source, G_TYPE_IO_CHANNEL),
530
+ INT2NUM(condition)));
531
+ }
532
+
533
+ static VALUE
534
+ ioc_add_watch(self, condition)
535
+ VALUE self, condition;
536
+ {
537
+ VALUE func = rb_block_proc();
538
+ G_RELATIVE(self, func);
539
+ return UINT2NUM(g_io_add_watch(_SELF(self), NUM2INT(condition),
540
+ (GIOFunc)io_func, (gpointer)func));
541
+ }
542
+
543
+ /* Don't need this
544
+ guint g_io_add_watch_full (GIOChannel *channel,
545
+ gint priority,
546
+ GIOCondition condition,
547
+ GIOFunc func,
548
+ gpointer user_data,
549
+ GDestroyNotify notify);
550
+ */
551
+
552
+ static VALUE
553
+ ioc_get_buffer_size(self)
554
+ VALUE self;
555
+ {
556
+ return UINT2NUM(g_io_channel_get_buffer_size(_SELF(self)));
557
+ }
558
+
559
+ static VALUE
560
+ ioc_set_buffer_size(self, buffer_size)
561
+ VALUE self, buffer_size;
562
+ {
563
+ g_io_channel_set_buffer_size(_SELF(self), NUM2UINT(buffer_size));
564
+ return self;
565
+ }
566
+
567
+ static VALUE
568
+ ioc_get_buffer_condition(self)
569
+ VALUE self;
570
+ {
571
+ return INT2NUM(g_io_channel_get_buffer_condition(_SELF(self)));
572
+ }
573
+
574
+ static VALUE
575
+ ioc_get_flags(self)
576
+ VALUE self;
577
+ {
578
+ return INT2NUM(g_io_channel_get_flags(_SELF(self)));
579
+ }
580
+
581
+ static VALUE
582
+ ioc_set_flags(self, flags)
583
+ VALUE self, flags;
584
+ {
585
+ GError* err = NULL;
586
+ GIOStatus status = g_io_channel_set_flags(_SELF(self),
587
+ NUM2INT(flags), &err);
588
+ ioc_error(status, err);
589
+ return self;
590
+ }
591
+
592
+ /* Use them with GLib::IOChannel#gets, #readline, #readlines
593
+ static VALUE
594
+ ioc_get_line_term(self)
595
+ VALUE self;
596
+ {
597
+ gint length;
598
+ const gchar* ret = g_io_channel_get_line_term(_SELF(self), &length);
599
+ if (ret) {
600
+ if (length < 0) {
601
+ return CSTR2RVAL(ret);
602
+ } else {
603
+ return rb_str_new(ret, length);
604
+ }
605
+ }
606
+ return Qnil;
607
+ }
608
+
609
+ static VALUE
610
+ ioc_set_line_term(self, line_term)
611
+ VALUE self, line_term;
612
+ {
613
+ StringValue(line_term);
614
+ g_io_channel_set_line_term(_SELF(self), RVAL2CSTR(line_term),
615
+ RSTRING_LEN(line_term));
616
+ return self;
617
+ }
618
+ */
619
+
620
+ static VALUE
621
+ ioc_get_buffered(self)
622
+ VALUE self;
623
+ {
624
+ return CBOOL2RVAL(g_io_channel_get_buffered(_SELF(self)));
625
+ }
626
+
627
+ static VALUE
628
+ ioc_set_buffered(self, buffered)
629
+ VALUE self, buffered;
630
+ {
631
+ g_io_channel_set_buffered(_SELF(self), RVAL2CBOOL(buffered));
632
+ return self;
633
+ }
634
+
635
+ static VALUE
636
+ ioc_get_encoding(self)
637
+ VALUE self;
638
+ {
639
+ return CSTR2RVAL(g_io_channel_get_encoding(_SELF(self)));
640
+ }
641
+
642
+ static VALUE
643
+ ioc_set_encoding(self, encoding)
644
+ VALUE self, encoding;
645
+ {
646
+ GError* err = NULL;
647
+ GIOStatus status = g_io_channel_set_encoding(_SELF(self),
648
+ encoding ? RVAL2CSTR(encoding) : NULL, &err);
649
+ ioc_error(status, err);
650
+ return self;
651
+ }
652
+
653
+ /* Don't we need them ?
654
+ gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
655
+ void g_io_channel_set_close_on_unref (GIOChannel *channel,
656
+ gboolean do_close);
657
+ */
658
+
659
+ /* Deprecated
660
+ GIOError g_io_channel_read (GIOChannel *channel,
661
+ gchar *buf,
662
+ gsize count,
663
+ gsize *bytes_read);
664
+ enum GIOError;
665
+ GIOError g_io_channel_write (GIOChannel *channel,
666
+ const gchar *buf,
667
+ gsize count,
668
+ gsize *bytes_written);
669
+ GIOError g_io_channel_seek (GIOChannel *channel,
670
+ gint64 offset,
671
+ GSeekType type);
672
+ void g_io_channel_close (GIOChannel *channel);
673
+ */
674
+
675
+ static VALUE
676
+ ioc_error_s_from_errno(self, errno_)
677
+ VALUE self, errno_;
678
+ {
679
+ return INT2NUM(g_io_channel_error_from_errno(NUM2INT(errno_)));
680
+ }
681
+
682
+ /*
683
+ * Stolen some convenient methods from io.c
684
+ */
685
+ static VALUE
686
+ ioc_printf(argc, argv, self)
687
+ int argc;
688
+ VALUE* argv;
689
+ VALUE self;
690
+ {
691
+ ioc_write_chars(self, rb_f_sprintf(argc, argv));
692
+ return Qnil;
693
+ }
694
+
695
+ static VALUE ioc_puts(int argc, VALUE* argv, VALUE self);
696
+
697
+ static VALUE
698
+ ioc_puts_ary(ary, out, recur)
699
+ VALUE ary, out;
700
+ {
701
+ VALUE tmp;
702
+ long i;
703
+
704
+ for (i=0; i<RARRAY_LEN(ary); i++) {
705
+ tmp = RARRAY_PTR(ary)[i];
706
+ if (recur) {
707
+ tmp = rb_str_new2("[...]");
708
+ }
709
+ rb_io_puts(1, &tmp, out);
710
+ }
711
+ return Qnil;
712
+ }
713
+
714
+ static VALUE
715
+ ioc_puts(argc, argv, self)
716
+ int argc;
717
+ VALUE *argv;
718
+ VALUE self;
719
+ {
720
+ int i;
721
+ VALUE line;
722
+
723
+ /* if no argument given, print newline. */
724
+ if (argc == 0) {
725
+ ioc_write_chars(self, rb_default_rs);
726
+ return Qnil;
727
+ }
728
+ for (i=0; i<argc; i++) {
729
+ if (NIL_P(argv[i])) {
730
+ line = rb_str_new2("nil");
731
+ }
732
+ else {
733
+ #if HAVE_RB_CHECK_ARRAY_TYPE
734
+ line = rb_check_array_type(argv[i]);
735
+ #else
736
+ line = rb_check_convert_type(argv[i], T_ARRAY, "Array", "to_ary");
737
+ #endif
738
+ if (!NIL_P(line)) {
739
+ #if HAVE_RB_EXEC_RECURSIVE
740
+ rb_exec_recursive(ioc_puts_ary, line, self);
741
+ #else
742
+ rb_protect_inspect(ioc_puts_ary, line, self);
743
+ #endif
744
+ continue;
745
+ }
746
+ line = rb_obj_as_string(argv[i]);
747
+ }
748
+ ioc_write_chars(self, line);
749
+ if (RSTRING_LEN(line) == 0 ||
750
+ RSTRING_PTR(line)[RSTRING_LEN(line)-1] != '\n') {
751
+ ioc_write_chars(self, rb_default_rs);
752
+ }
753
+ }
754
+
755
+ return Qnil;
756
+ }
757
+
758
+ static VALUE
759
+ ioc_print(argc, argv, out)
760
+ int argc;
761
+ VALUE *argv;
762
+ VALUE out;
763
+ {
764
+ int i;
765
+ VALUE line;
766
+
767
+ /* if no argument given, print `$_' */
768
+ if (argc == 0) {
769
+ argc = 1;
770
+ line = rb_lastline_get();
771
+ argv = &line;
772
+ }
773
+ for (i=0; i<argc; i++) {
774
+ if (!NIL_P(rb_output_fs) && i>0) {
775
+ ioc_write_chars(out, rb_output_fs);
776
+ }
777
+ switch (TYPE(argv[i])) {
778
+ case T_NIL:
779
+ ioc_write_chars(out, rb_str_new2("nil"));
780
+ break;
781
+ default:
782
+ ioc_write_chars(out, argv[i]);
783
+ break;
784
+ }
785
+ }
786
+ if (!NIL_P(rb_output_rs)) {
787
+ ioc_write_chars(out, rb_output_rs);
788
+ }
789
+
790
+ return Qnil;
791
+ }
792
+
793
+
794
+ void
795
+ Init_glib_io_channel()
796
+ {
797
+ VALUE io = G_DEF_CLASS(G_TYPE_IO_CHANNEL, "IOChannel", mGLib);
798
+ VALUE ioc_error = G_DEF_ERROR2(G_IO_CHANNEL_ERROR, "IOChannelError", mGLib, rb_eIOError);
799
+
800
+ rb_include_module(io, rb_mEnumerable);
801
+
802
+ id_call = rb_intern("call");
803
+ id_unpack = rb_intern("unpack");
804
+
805
+
806
+ rb_define_method(io, "initialize", ioc_initialize, -1);
807
+ rb_define_singleton_method(io, "open", ioc_s_open, -1);
808
+ rb_define_method(io, "fileno", ioc_get_fd, 0); /* ref: IO#fileno */
809
+ rb_define_alias(io, "to_i", "fileno"); /* ref: IO#to_i */
810
+ rb_define_method(io, "read", ioc_read_chars, -1); /* ref: IO#read(count = nil) */
811
+ rb_define_method(io, "readchar", ioc_read_unichar, 0); /* ref: IO#readchar but this return an UTF-8 char */
812
+ rb_define_method(io, "getc", ioc_getuc, 0); /* ref: IO#getc but this return an UTF-8 char */
813
+ rb_define_method(io, "readline", ioc_read_line, -1); /* ref: IO#readline(rs = nil) */
814
+ rb_define_method(io, "gets", ioc_gets, -1); /* ref: IO#gets(rs = nil) */
815
+ rb_define_method(io, "each", ioc_each_line, -1); /* ref: IO#each(rs = nil){|line|...} */
816
+ rb_define_alias(io, "each_line", "each"); /* ref: IO#each_line(rs = nil){|line|...} */
817
+ rb_define_method(io, "each_char", ioc_each_char, 0); /* ref: IO#each_byte{|line|...} */
818
+ rb_define_method(io, "write", ioc_write_chars, 1); /* ref: IO#write(str) */
819
+ rb_define_method(io, "printf", ioc_printf, -1); /* ref: IO#printf(...) */
820
+ rb_define_method(io, "print", ioc_print, -1); /* ref: IO#print(...) */
821
+ rb_define_method(io, "puts", ioc_puts, -1); /* ref: IO#puts(...) */
822
+ rb_define_method(io, "putc", ioc_write_unichar, 1); /* ref: IO#putc(ch) but this accept an UTF-8 code */
823
+ rb_define_method(io, "flush", ioc_flush, 0); /* ref: IO#flush */
824
+ rb_define_method(io, "seek", ioc_seek, -1); /* ref: IO#seek */
825
+ rb_define_method(io, "set_pos", ioc_seek_pos, 1); /* ref: IO#pos= */
826
+ rb_define_method(io, "close", ioc_shutdown, -1); /* ref: IO#close */
827
+ rb_define_method(io, "create_watch", ioc_create_watch, 1);
828
+ rb_define_method(io, "add_watch", ioc_add_watch, 1);
829
+ rb_define_method(io, "buffer_size", ioc_get_buffer_size, 0);
830
+ rb_define_method(io, "set_buffer_size", ioc_set_buffer_size, 1);
831
+ rb_define_method(io, "buffer_condition", ioc_get_buffer_condition, 0);
832
+ rb_define_method(io, "flags", ioc_get_flags, 0);
833
+ rb_define_method(io, "set_flags", ioc_set_flags, 1);
834
+ rb_define_method(io, "buffered", ioc_get_buffered, 0);
835
+ rb_define_method(io, "set_buffered", ioc_set_buffered, 1);
836
+ rb_define_method(io, "encoding", ioc_get_encoding, 0);
837
+ rb_define_method(io, "set_encoding", ioc_set_encoding, 1);
838
+
839
+ G_DEF_SETTERS(io);
840
+
841
+ /* GSeekType */
842
+ rb_define_const(io, "SEEK_CUR", INT2NUM(G_SEEK_CUR));
843
+ rb_define_const(io, "SEEK_SET", INT2NUM(G_SEEK_SET));
844
+ rb_define_const(io, "SEEK_END", INT2NUM(G_SEEK_END));
845
+
846
+ /* GIOStatus */
847
+ rb_define_const(io, "STATUS_ERROR", INT2NUM(G_IO_STATUS_ERROR));
848
+ rb_define_const(io, "STATUS_NORMAL", INT2NUM(G_IO_STATUS_NORMAL));
849
+ rb_define_const(io, "STATUS_EOF", INT2NUM(G_IO_STATUS_EOF));
850
+ rb_define_const(io, "STATUS_AGAIN", INT2NUM(G_IO_STATUS_AGAIN));
851
+
852
+ /* GIOCondition */
853
+ rb_define_const(io, "IN", INT2NUM(G_IO_IN));
854
+ rb_define_const(io, "OUT", INT2NUM(G_IO_OUT));
855
+ rb_define_const(io, "PRI", INT2NUM(G_IO_PRI));
856
+ rb_define_const(io, "ERR", INT2NUM(G_IO_ERR));
857
+ rb_define_const(io, "HUP", INT2NUM(G_IO_HUP));
858
+ rb_define_const(io, "NVAL", INT2NUM(G_IO_NVAL));
859
+
860
+ /* GIOFlags */
861
+ rb_define_const(io, "FLAG_APPEND", INT2NUM(G_IO_FLAG_APPEND));
862
+ rb_define_const(io, "FLAG_NONBLOCK", INT2NUM(G_IO_FLAG_NONBLOCK));
863
+ rb_define_const(io, "FLAG_READABLE", INT2NUM(G_IO_FLAG_IS_READABLE));
864
+ rb_define_const(io, "FLAG_WRITEABLE", INT2NUM(G_IO_FLAG_IS_WRITEABLE));
865
+ rb_define_const(io, "FLAG_IS_SEEKABLE", INT2NUM(G_IO_FLAG_IS_SEEKABLE));
866
+ rb_define_const(io, "FLAG_MASK", INT2NUM(G_IO_FLAG_MASK));
867
+ rb_define_const(io, "FLAG_GET_MASK", INT2NUM(G_IO_FLAG_GET_MASK));
868
+ rb_define_const(io, "FLAG_SET_MASK", INT2NUM(G_IO_FLAG_SET_MASK));
869
+
870
+ /* GIOChannelError */
871
+ rb_define_singleton_method(ioc_error, "from_errno", ioc_error_s_from_errno, 1);
872
+
873
+ rb_define_const(ioc_error, "FBIG", INT2NUM(G_IO_CHANNEL_ERROR_FBIG));
874
+ rb_define_const(ioc_error, "INVAL", INT2NUM(G_IO_CHANNEL_ERROR_INVAL));
875
+ rb_define_const(ioc_error, "IO", INT2NUM(G_IO_CHANNEL_ERROR_IO));
876
+ rb_define_const(ioc_error, "ISDIR", INT2NUM(G_IO_CHANNEL_ERROR_ISDIR));
877
+ rb_define_const(ioc_error, "NOSPC", INT2NUM(G_IO_CHANNEL_ERROR_NOSPC));
878
+ rb_define_const(ioc_error, "NXIO", INT2NUM(G_IO_CHANNEL_ERROR_NXIO));
879
+ rb_define_const(ioc_error, "OVERFLOW", INT2NUM(G_IO_CHANNEL_ERROR_OVERFLOW));
880
+ rb_define_const(ioc_error, "PIPE", INT2NUM(G_IO_CHANNEL_ERROR_PIPE));
881
+ rb_define_const(ioc_error, "FAILED", INT2NUM(G_IO_CHANNEL_ERROR_FAILED));
882
+
883
+ }