w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

socket.c
Go to the documentation of this file.
1 /*
2 ** socket.c - Socket module
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #ifdef _WIN32
8  #define _WIN32_WINNT 0x0501
9 
10  #include <winsock2.h>
11  #include <ws2tcpip.h>
12  #include <windows.h>
13  #include <winerror.h>
14 
15  #define SHUT_RDWR SD_BOTH
16  #ifndef _SSIZE_T_DEFINED
17  typedef int ssize_t;
18  #endif
19  typedef int fsize_t;
20 #else
21  #include <sys/types.h>
22  #include <sys/socket.h>
23  #include <sys/param.h>
24  #include <sys/un.h>
25  #include <netinet/in.h>
26  #include <netinet/tcp.h>
27  #include <arpa/inet.h>
28  #include <fcntl.h>
29  #include <netdb.h>
30  #include <unistd.h>
31  typedef size_t fsize_t;
32 #endif
33 
34 #include <stddef.h>
35 #include <string.h>
36 
37 #include "mruby.h"
38 #include "mruby/array.h"
39 #include "mruby/class.h"
40 #include "mruby/data.h"
41 #include "mruby/numeric.h"
42 #include "mruby/string.h"
43 #include "mruby/variable.h"
44 #include "mruby/error.h"
45 #include "mruby/presym.h"
46 
47 #include "mruby/ext/io.h"
48 
49 #if !defined(HAVE_SA_LEN)
50 #if (defined(BSD) && (BSD >= 199006))
51 #define HAVE_SA_LEN 1
52 #else
53 #define HAVE_SA_LEN 0
54 #endif
55 #endif
56 
57 #define E_SOCKET_ERROR mrb_class_get_id(mrb, MRB_SYM(SocketError))
58 
59 #if !defined(mrb_cptr)
60 #define mrb_cptr_value(m,p) mrb_voidp_value((m),(p))
61 #define mrb_cptr(o) mrb_voidp(o)
62 #define mrb_cptr_p(o) mrb_voidp_p(o)
63 #endif
64 
65 #ifdef _WIN32
66 static const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
67 {
68  if (af == AF_INET)
69  {
70  struct sockaddr_in in;
71  memset(&in, 0, sizeof(in));
72  in.sin_family = AF_INET;
73  memcpy(&in.sin_addr, src, sizeof(struct in_addr));
74  getnameinfo((struct sockaddr *)&in, sizeof(struct
75  sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST);
76  return dst;
77  }
78  else if (af == AF_INET6)
79  {
80  struct sockaddr_in6 in;
81  memset(&in, 0, sizeof(in));
82  in.sin6_family = AF_INET6;
83  memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
84  getnameinfo((struct sockaddr *)&in, sizeof(struct
85  sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST);
86  return dst;
87  }
88  return NULL;
89 }
90 
91 static int inet_pton(int af, const char *src, void *dst)
92 {
93  struct addrinfo hints, *res, *ressave;
94 
95  memset(&hints, 0, sizeof(struct addrinfo));
96  hints.ai_family = af;
97 
98  if (getaddrinfo(src, NULL, &hints, &res) != 0)
99  {
100  printf("Couldn't resolve host %s\n", src);
101  return -1;
102  }
103 
104  ressave = res;
105 
106  while (res)
107  {
108  memcpy(dst, res->ai_addr, res->ai_addrlen);
109  res = res->ai_next;
110  }
111 
112  freeaddrinfo(ressave);
113  return 0;
114 }
115 
116 #endif
117 
118 static mrb_value
120 {
121  struct addrinfo hints, *res0, *res;
122  mrb_value ai, ary, family, lastai, nodename, protocol, sa, service, socktype;
123  mrb_int flags;
124  int arena_idx, error;
125  const char *hostname = NULL, *servname = NULL;
126 
127  ary = mrb_ary_new(mrb);
128  arena_idx = mrb_gc_arena_save(mrb); /* ary must be on arena! */
129 
130  family = socktype = protocol = mrb_nil_value();
131  flags = 0;
132  mrb_get_args(mrb, "oo|oooi", &nodename, &service, &family, &socktype, &protocol, &flags);
133 
134  if (mrb_string_p(nodename)) {
135  hostname = RSTRING_CSTR(mrb, nodename);
136  } else if (mrb_nil_p(nodename)) {
137  hostname = NULL;
138  } else {
139  mrb_raise(mrb, E_TYPE_ERROR, "nodename must be String or nil");
140  }
141 
142  if (mrb_string_p(service)) {
143  servname = RSTRING_CSTR(mrb, service);
144  } else if (mrb_integer_p(service)) {
145  servname = RSTRING_PTR(mrb_fixnum_to_str(mrb, service, 10));
146  } else if (mrb_nil_p(service)) {
147  servname = NULL;
148  } else {
149  mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Integer, or nil");
150  }
151 
152  memset(&hints, 0, sizeof(hints));
153  hints.ai_flags = (int)flags;
154 
155  if (mrb_integer_p(family)) {
156  hints.ai_family = (int)mrb_integer(family);
157  }
158 
159  if (mrb_integer_p(socktype)) {
160  hints.ai_socktype = (int)mrb_integer(socktype);
161  }
162 
163  if (mrb_integer_p(protocol)) {
164  hints.ai_protocol = (int)mrb_integer(protocol);
165  }
166 
167  lastai = mrb_cv_get(mrb, klass, MRB_SYM(_lastai));
168  if (mrb_cptr_p(lastai)) {
169  freeaddrinfo((struct addrinfo*)mrb_cptr(lastai));
170  mrb_cv_set(mrb, klass, MRB_SYM(_lastai), mrb_nil_value());
171  }
172 
173  error = getaddrinfo(hostname, servname, &hints, &res0);
174  if (error) {
175  mrb_raisef(mrb, E_SOCKET_ERROR, "getaddrinfo: %s", gai_strerror(error));
176  }
177  mrb_cv_set(mrb, klass, MRB_SYM(_lastai), mrb_cptr_value(mrb, res0));
178 
179  for (res = res0; res != NULL; res = res->ai_next) {
180  sa = mrb_str_new(mrb, (char*)res->ai_addr, res->ai_addrlen);
181  ai = mrb_funcall_id(mrb, klass, MRB_SYM(new), 4, sa, mrb_fixnum_value(res->ai_family), mrb_fixnum_value(res->ai_socktype), mrb_fixnum_value(res->ai_protocol));
182  mrb_ary_push(mrb, ary, ai);
183  mrb_gc_arena_restore(mrb, arena_idx);
184  }
185 
186  freeaddrinfo(res0);
187  mrb_cv_set(mrb, klass, MRB_SYM(_lastai), mrb_nil_value());
188 
189  return ary;
190 }
191 
192 static mrb_value
194 {
195  mrb_int flags;
196  mrb_value ary, host, sastr, serv;
197  int error;
198 
199  flags = 0;
200  mrb_get_args(mrb, "|i", &flags);
201  host = mrb_str_new_capa(mrb, NI_MAXHOST);
202  serv = mrb_str_new_capa(mrb, NI_MAXSERV);
203 
204  sastr = mrb_iv_get(mrb, self, MRB_IVSYM(sockaddr));
205  if (!mrb_string_p(sastr)) {
206  mrb_raise(mrb, E_SOCKET_ERROR, "invalid sockaddr");
207  }
208  error = getnameinfo((struct sockaddr *)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr), RSTRING_PTR(host), NI_MAXHOST, RSTRING_PTR(serv), NI_MAXSERV, (int)flags);
209  if (error) {
210  mrb_raisef(mrb, E_SOCKET_ERROR, "getnameinfo: %s", gai_strerror(error));
211  }
212  ary = mrb_ary_new_capa(mrb, 2);
213  mrb_str_resize(mrb, host, strlen(RSTRING_PTR(host)));
214  mrb_ary_push(mrb, ary, host);
215  mrb_str_resize(mrb, serv, strlen(RSTRING_PTR(serv)));
216  mrb_ary_push(mrb, ary, serv);
217  return ary;
218 }
219 
220 #ifndef _WIN32
221 static mrb_value
223 {
224  mrb_value sastr;
225 
226  sastr = mrb_iv_get(mrb, self, MRB_IVSYM(sockaddr));
227  if (((struct sockaddr *)RSTRING_PTR(sastr))->sa_family != AF_UNIX)
228  mrb_raise(mrb, E_SOCKET_ERROR, "need AF_UNIX address");
229  if (RSTRING_LEN(sastr) < (mrb_int)offsetof(struct sockaddr_un, sun_path) + 1) {
230  return mrb_str_new(mrb, "", 0);
231  } else {
232  return mrb_str_new_cstr(mrb, ((struct sockaddr_un *)RSTRING_PTR(sastr))->sun_path);
233  }
234 }
235 #endif
236 
237 static mrb_value
238 sa2addrlist(mrb_state *mrb, const struct sockaddr *sa, socklen_t salen)
239 {
240  mrb_value ary, host;
241  unsigned short port;
242  const char *afstr;
243 
244  switch (sa->sa_family) {
245  case AF_INET:
246  afstr = "AF_INET";
247  port = ((struct sockaddr_in *)sa)->sin_port;
248  break;
249  case AF_INET6:
250  afstr = "AF_INET6";
251  port = ((struct sockaddr_in6 *)sa)->sin6_port;
252  break;
253  default:
254  mrb_raise(mrb, E_ARGUMENT_ERROR, "bad af");
255  return mrb_nil_value();
256  }
257  port = ntohs(port);
258  host = mrb_str_new_capa(mrb, NI_MAXHOST);
259  if (getnameinfo(sa, salen, RSTRING_PTR(host), NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == -1)
260  mrb_sys_fail(mrb, "getnameinfo");
261  mrb_str_resize(mrb, host, strlen(RSTRING_PTR(host)));
262  ary = mrb_ary_new_capa(mrb, 4);
263  mrb_ary_push(mrb, ary, mrb_str_new_cstr(mrb, afstr));
264  mrb_ary_push(mrb, ary, mrb_fixnum_value(port));
265  mrb_ary_push(mrb, ary, host);
266  mrb_ary_push(mrb, ary, host);
267  return ary;
268 }
269 
270 static int
272 {
273  return (int)mrb_integer(mrb_funcall_id(mrb, sock, MRB_SYM(fileno), 0));
274 }
275 
276 static int
278 {
279  struct sockaddr_storage ss;
280  socklen_t salen;
281 
282  salen = sizeof(ss);
283  if (getsockname(s, (struct sockaddr *)&ss, &salen) == -1)
284  return AF_UNSPEC;
285  return ss.ss_family;
286 }
287 
288 static mrb_value
290 {
291 #ifdef HAVE_GETPEEREID
292  mrb_value ary;
293  gid_t egid;
294  uid_t euid;
295  int s;
296 
297  s = socket_fd(mrb, self);
298  if (getpeereid(s, &euid, &egid) != 0)
299  mrb_sys_fail(mrb, "getpeereid");
300 
301  ary = mrb_ary_new_capa(mrb, 2);
302  mrb_ary_push(mrb, ary, mrb_fixnum_value((mrb_int)euid));
303  mrb_ary_push(mrb, ary, mrb_fixnum_value((mrb_int)egid));
304  return ary;
305 #else
306  mrb_raise(mrb, E_RUNTIME_ERROR, "getpeereid is not available on this system");
307  return mrb_nil_value();
308 #endif
309 }
310 
311 static mrb_value
313 {
314  struct sockaddr_storage ss;
315  socklen_t salen;
316 
317  salen = sizeof(ss);
318  if (getpeername(socket_fd(mrb, self), (struct sockaddr *)&ss, &salen) != 0)
319  mrb_sys_fail(mrb, "getpeername");
320 
321  return mrb_str_new(mrb, (char*)&ss, salen);
322 }
323 
324 static mrb_value
326 {
327  struct sockaddr_storage ss;
328  socklen_t salen;
329 
330  salen = sizeof(ss);
331  if (getsockname(socket_fd(mrb, self), (struct sockaddr *)&ss, &salen) != 0)
332  mrb_sys_fail(mrb, "getsockname");
333 
334  return mrb_str_new(mrb, (char*)&ss, salen);
335 }
336 
337 static mrb_value
339 {
340  char opt[8];
341  int s;
342  mrb_int family, level, optname;
343  mrb_value c, data;
344  socklen_t optlen;
345 
346  mrb_get_args(mrb, "ii", &level, &optname);
347  s = socket_fd(mrb, self);
348  optlen = sizeof(opt);
349  if (getsockopt(s, (int)level, (int)optname, opt, &optlen) == -1)
350  mrb_sys_fail(mrb, "getsockopt");
351  c = mrb_const_get(mrb, mrb_obj_value(mrb_class_get_id(mrb, MRB_SYM(Socket))), MRB_SYM(Option));
353  data = mrb_str_new(mrb, opt, optlen);
355 }
356 
357 static mrb_value
359 {
360  ssize_t n;
361  mrb_int maxlen, flags = 0;
362  mrb_value buf;
363 
364  mrb_get_args(mrb, "i|i", &maxlen, &flags);
365  buf = mrb_str_new_capa(mrb, maxlen);
366  n = recv(socket_fd(mrb, self), RSTRING_PTR(buf), (fsize_t)maxlen, (int)flags);
367  if (n == -1)
368  mrb_sys_fail(mrb, "recv");
369  mrb_str_resize(mrb, buf, (mrb_int)n);
370  return buf;
371 }
372 
373 static mrb_value
375 {
376  ssize_t n;
377  mrb_int maxlen, flags = 0;
378  mrb_value ary, buf, sa;
379  socklen_t socklen;
380 
381  mrb_get_args(mrb, "i|i", &maxlen, &flags);
382  buf = mrb_str_new_capa(mrb, maxlen);
383  socklen = sizeof(struct sockaddr_storage);
384  sa = mrb_str_new_capa(mrb, socklen);
385  n = recvfrom(socket_fd(mrb, self), RSTRING_PTR(buf), (fsize_t)maxlen, (int)flags, (struct sockaddr *)RSTRING_PTR(sa), &socklen);
386  if (n == -1)
387  mrb_sys_fail(mrb, "recvfrom");
388  mrb_str_resize(mrb, buf, (mrb_int)n);
389  mrb_str_resize(mrb, sa, (mrb_int)socklen);
390  ary = mrb_ary_new_capa(mrb, 2);
391  mrb_ary_push(mrb, ary, buf);
392  mrb_ary_push(mrb, ary, sa);
393  return ary;
394 }
395 
396 static mrb_value
398 {
399  ssize_t n;
400  mrb_int flags;
402 
403  dest = mrb_nil_value();
404  mrb_get_args(mrb, "Si|S", &mesg, &flags, &dest);
405  if (mrb_nil_p(dest)) {
406  n = send(socket_fd(mrb, self), RSTRING_PTR(mesg), (fsize_t)RSTRING_LEN(mesg), (int)flags);
407  } else {
408  n = sendto(socket_fd(mrb, self), RSTRING_PTR(mesg), (fsize_t)RSTRING_LEN(mesg), (int)flags, (const struct sockaddr*)RSTRING_PTR(dest), (fsize_t)RSTRING_LEN(dest));
409  }
410  if (n == -1)
411  mrb_sys_fail(mrb, "send");
412  return mrb_fixnum_value((mrb_int)n);
413 }
414 
415 static mrb_value
417 {
418  int fd, flags;
419  mrb_bool nonblocking;
420 #ifdef _WIN32
421  u_long mode = 1;
422 #endif
423 
424  mrb_get_args(mrb, "b", &nonblocking);
425  fd = socket_fd(mrb, self);
426 #ifdef _WIN32
427  flags = ioctlsocket(fd, FIONBIO, &mode);
428  if (flags != NO_ERROR)
429  mrb_sys_fail(mrb, "ioctlsocket");
430 #else
431  flags = fcntl(fd, F_GETFL, 0);
432  if (flags == 1)
433  mrb_sys_fail(mrb, "fcntl");
434  if (nonblocking)
435  flags |= O_NONBLOCK;
436  else
437  flags &= ~~O_NONBLOCK;
438  if (fcntl(fd, F_SETFL, flags) == -1)
439  mrb_sys_fail(mrb, "fcntl");
440 #endif
441  return mrb_nil_value();
442 }
443 
444 static mrb_value
446 {
447  int s;
448  mrb_int argc, level = 0, optname;
449  mrb_value optval, so;
450 
451  argc = mrb_get_args(mrb, "o|io", &so, &optname, &optval);
452  if (argc == 3) {
453  if (!mrb_integer_p(so)) {
454  mrb_raise(mrb, E_ARGUMENT_ERROR, "level is not an integer");
455  }
456  level = mrb_integer(so);
457  if (mrb_string_p(optval)) {
458  /* that's good */
459  } else if (mrb_true_p(optval) || mrb_false_p(optval)) {
460  mrb_int i = mrb_test(optval) ? 1 : 0;
461  optval = mrb_str_new(mrb, (char*)&i, sizeof(i));
462  } else if (mrb_integer_p(optval)) {
463  if (optname == IP_MULTICAST_TTL || optname == IP_MULTICAST_LOOP) {
464  char uc = (char)mrb_integer(optval);
465  optval = mrb_str_new(mrb, &uc, sizeof(uc));
466  } else {
467  mrb_int i = mrb_integer(optval);
468  optval = mrb_str_new(mrb, (char*)&i, sizeof(i));
469  }
470  } else {
471  mrb_raise(mrb, E_ARGUMENT_ERROR, "optval should be true, false, an integer, or a string");
472  }
473  } else if (argc == 1) {
474  if (strcmp(mrb_obj_classname(mrb, so), "Socket::Option") != 0)
475  mrb_raise(mrb, E_ARGUMENT_ERROR, "not an instance of Socket::Option");
477  optname = mrb_integer(mrb_funcall_id(mrb, so, MRB_SYM(optname), 0));
478  optval = mrb_funcall_id(mrb, so, MRB_SYM(data), 0);
479  } else {
480  mrb_argnum_error(mrb, argc, 3, 3);
481  }
482 
483  s = socket_fd(mrb, self);
484  if (setsockopt(s, (int)level, (int)optname, RSTRING_PTR(optval), (socklen_t)RSTRING_LEN(optval)) == -1)
485  mrb_sys_fail(mrb, "setsockopt");
486  return mrb_fixnum_value(0);
487 }
488 
489 static mrb_value
491 {
492  mrb_int how = SHUT_RDWR;
493 
494  mrb_get_args(mrb, "|i", &how);
495  if (shutdown(socket_fd(mrb, self), (int)how) != 0)
496  mrb_sys_fail(mrb, "shutdown");
497  return mrb_fixnum_value(0);
498 }
499 
500 static mrb_value
502 {
503  mrb_bool b;
504  struct mrb_io *io_p;
505  mrb_get_args(mrb, "b", &b);
506 
507  io_p = (struct mrb_io*)DATA_PTR(self);
508  if (io_p) {
509  io_p->is_socket = b;
510  }
511 
512  return mrb_bool_value(b);
513 }
514 
515 static mrb_value
517 {
518  mrb_int af, n;
519  const char *addr;
520  char buf[50];
521 
522  mrb_get_args(mrb, "is", &af, &addr, &n);
523  if ((af == AF_INET && n != 4) || (af == AF_INET6 && n != 16))
524  mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid address");
525  if (inet_ntop((int)af, addr, buf, sizeof(buf)) == NULL)
526  mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid address");
527  return mrb_str_new_cstr(mrb, buf);
528 }
529 
530 static mrb_value
532 {
533  mrb_int af, n;
534  const char *bp;
535  char buf[50];
536 
537  mrb_get_args(mrb, "is", &af, &bp, &n);
538  if ((size_t)n > sizeof(buf) - 1)
539  mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid address");
540  memcpy(buf, bp, n);
541  buf[n] = '\0';
542 
543  if (af == AF_INET) {
544  struct in_addr in;
545  if (inet_pton(AF_INET, buf, (void *)&in.s_addr) != 1)
546  goto invalid;
547  return mrb_str_new(mrb, (char*)&in.s_addr, 4);
548  } else if (af == AF_INET6) {
549  struct in6_addr in6;
550  if (inet_pton(AF_INET6, buf, (void *)&in6.s6_addr) != 1)
551  goto invalid;
552  return mrb_str_new(mrb, (char*)&in6.s6_addr, 16);
553  } else
554  mrb_raise(mrb, E_ARGUMENT_ERROR, "unsupported address family");
555 
556 invalid:
557  mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid address");
558  return mrb_nil_value(); /* dummy */
559 }
560 
561 static mrb_value
563 {
564  struct sockaddr_storage ss;
565  socklen_t socklen;
566  mrb_value a, buf, pair;
567  mrb_int flags, maxlen;
568  ssize_t n;
569  int fd;
570 
571  fd = socket_fd(mrb, self);
572  flags = 0;
573  mrb_get_args(mrb, "i|i", &maxlen, &flags);
574  buf = mrb_str_new_capa(mrb, maxlen);
575  socklen = sizeof(ss);
576  n = recvfrom(fd, RSTRING_PTR(buf), (fsize_t)maxlen, (int)flags,
577  (struct sockaddr *)&ss, &socklen);
578  if (n == -1) {
579  mrb_sys_fail(mrb, "recvfrom");
580  }
581  mrb_str_resize(mrb, buf, (mrb_int)n);
582  a = sa2addrlist(mrb, (struct sockaddr *)&ss, socklen);
583  pair = mrb_ary_new_capa(mrb, 2);
584  mrb_ary_push(mrb, pair, buf);
585  mrb_ary_push(mrb, pair, a);
586  return pair;
587 }
588 
589 static mrb_value
591 {
592  mrb_value buf;
593  size_t bufsize;
594 
595 #ifdef HOST_NAME_MAX
596  bufsize = HOST_NAME_MAX + 1;
597 #else
598  bufsize = 256;
599 #endif
601  if (gethostname(RSTRING_PTR(buf), (fsize_t)bufsize) != 0)
602  mrb_sys_fail(mrb, "gethostname");
604  return buf;
605 }
606 
607 static mrb_value
609 {
610  int s1;
611  mrb_int s0;
612 
613  mrb_get_args(mrb, "i", &s0);
614  s1 = (int)accept(s0, NULL, NULL);
615  if (s1 == -1) {
616  mrb_sys_fail(mrb, "accept");
617  }
618  return mrb_fixnum_value(s1);
619 }
620 
621 static mrb_value
623 {
624  mrb_value ary, sastr;
625  int s1;
626  mrb_int s0;
627  socklen_t socklen;
628 
629  mrb_get_args(mrb, "i", &s0);
630  socklen = sizeof(struct sockaddr_storage);
631  sastr = mrb_str_new_capa(mrb, socklen);
632  s1 = (int)accept(s0, (struct sockaddr *)RSTRING_PTR(sastr), &socklen);
633  if (s1 == -1) {
634  mrb_sys_fail(mrb, "accept");
635  }
636  // XXX: possible descriptor leakage here!
637  mrb_str_resize(mrb, sastr, socklen);
638  ary = mrb_ary_new_capa(mrb, 2);
639  mrb_ary_push(mrb, ary, mrb_fixnum_value(s1));
640  mrb_ary_push(mrb, ary, sastr);
641  return ary;
642 }
643 
644 static mrb_value
646 {
647  mrb_value sastr;
648  mrb_int s;
649 
650  mrb_get_args(mrb, "iS", &s, &sastr);
651  if (bind((int)s, (struct sockaddr *)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr)) == -1) {
652  mrb_sys_fail(mrb, "bind");
653  }
654  return mrb_nil_value();
655 }
656 
657 static mrb_value
659 {
660  mrb_value sastr;
661  mrb_int s;
662 
663  mrb_get_args(mrb, "iS", &s, &sastr);
664  if (connect((int)s, (struct sockaddr *)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr)) == -1) {
665  mrb_sys_fail(mrb, "connect");
666  }
667  return mrb_nil_value();
668 }
669 
670 static mrb_value
672 {
673  mrb_int backlog, s;
674 
675  mrb_get_args(mrb, "ii", &s, &backlog);
676  if (listen((int)s, (int)backlog) == -1) {
677  mrb_sys_fail(mrb, "listen");
678  }
679  return mrb_nil_value();
680 }
681 
682 static mrb_value
684 {
685  const struct sockaddr *sa;
686  mrb_value str;
687 
688  mrb_get_args(mrb, "S", &str);
689  if ((size_t)RSTRING_LEN(str) < offsetof(struct sockaddr, sa_family) + sizeof(sa->sa_family)) {
690  mrb_raise(mrb, E_SOCKET_ERROR, "invalid sockaddr (too short)");
691  }
692  sa = (const struct sockaddr *)RSTRING_PTR(str);
693  return mrb_fixnum_value(sa->sa_family);
694 }
695 
696 static mrb_value
698 {
699 #ifdef _WIN32
700  mrb_raise(mrb, E_NOTIMP_ERROR, "sockaddr_un unsupported on Windows");
701  return mrb_nil_value();
702 #else
703  struct sockaddr_un *sunp;
704  mrb_value path, s;
705 
706  mrb_get_args(mrb, "S", &path);
707  if ((size_t)RSTRING_LEN(path) > sizeof(sunp->sun_path) - 1) {
708  mrb_raisef(mrb, E_ARGUMENT_ERROR, "too long unix socket path (max: %d bytes)", (int)sizeof(sunp->sun_path) - 1);
709  }
710  s = mrb_str_new_capa(mrb, sizeof(struct sockaddr_un));
711  sunp = (struct sockaddr_un *)RSTRING_PTR(s);
712 #if HAVE_SA_LEN
713  sunp->sun_len = sizeof(struct sockaddr_un);
714 #endif
715  sunp->sun_family = AF_UNIX;
716  memcpy(sunp->sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
717  sunp->sun_path[RSTRING_LEN(path)] = '\0';
718  mrb_str_resize(mrb, s, sizeof(struct sockaddr_un));
719  return s;
720 #endif
721 }
722 
723 static mrb_value
725 {
726 #ifdef _WIN32
727  mrb_raise(mrb, E_NOTIMP_ERROR, "socketpair unsupported on Windows");
728  return mrb_nil_value();
729 #else
730  mrb_value ary;
731  mrb_int domain, type, protocol;
732  int sv[2];
733 
734  mrb_get_args(mrb, "iii", &domain, &type, &protocol);
735  if (socketpair(domain, type, protocol, sv) == -1) {
736  mrb_sys_fail(mrb, "socketpair");
737  }
738  // XXX: possible descriptor leakage here!
739  ary = mrb_ary_new_capa(mrb, 2);
740  mrb_ary_push(mrb, ary, mrb_fixnum_value(sv[0]));
741  mrb_ary_push(mrb, ary, mrb_fixnum_value(sv[1]));
742  return ary;
743 #endif
744 }
745 
746 static mrb_value
748 {
749  mrb_int domain, type, protocol;
750  int s;
751 
752  mrb_get_args(mrb, "iii", &domain, &type, &protocol);
753  s = (int)socket((int)domain, (int)type, (int)protocol);
754  if (s == -1)
755  mrb_sys_fail(mrb, "socket");
756  return mrb_fixnum_value(s);
757 }
758 
759 static mrb_value
761 {
762  struct RClass *c = mrb_class_ptr(klass);
764 
765  /* copied from mrb_instance_alloc() */
766  if (ttype == 0) ttype = MRB_TT_OBJECT;
767  return mrb_obj_value((struct RObject*)mrb_obj_alloc(mrb, ttype, c));
768 }
769 
770 /* Windows overrides for IO methods on BasicSocket objects.
771  * This is because sockets on Windows are not the same as file
772  * descriptors, and thus functions which operate on file descriptors
773  * will break on socket descriptors.
774  */
775 #ifdef _WIN32
776 static mrb_value
777 mrb_win32_basicsocket_close(mrb_state *mrb, mrb_value self)
778 {
779  if (closesocket(socket_fd(mrb, self)) != NO_ERROR)
780  mrb_raise(mrb, E_SOCKET_ERROR, "closesocket unsuccessful");
781  return mrb_nil_value();
782 }
783 
784 static mrb_value
785 mrb_win32_basicsocket_sysread(mrb_state *mrb, mrb_value self)
786 {
787  int sd, ret;
789  mrb_int maxlen;
790 
791  mrb_get_args(mrb, "i|S", &maxlen, &buf);
792  if (maxlen < 0) {
793  return mrb_nil_value();
794  }
795 
796  if (mrb_nil_p(buf)) {
797  buf = mrb_str_new(mrb, NULL, maxlen);
798  }
799  if (RSTRING_LEN(buf) != maxlen) {
800  buf = mrb_str_resize(mrb, buf, maxlen);
801  }
802 
803  sd = socket_fd(mrb, self);
804  ret = recv(sd, RSTRING_PTR(buf), (int)maxlen, 0);
805 
806  switch (ret) {
807  case 0: /* EOF */
808  if (maxlen == 0) {
809  buf = mrb_str_new_cstr(mrb, "");
810  } else {
811  mrb_raise(mrb, E_EOF_ERROR, "sysread failed: End of File");
812  }
813  break;
814  case SOCKET_ERROR: /* Error */
815  mrb_sys_fail(mrb, "recv");
816  break;
817  default:
818  if (RSTRING_LEN(buf) != ret) {
819  buf = mrb_str_resize(mrb, buf, ret);
820  }
821  break;
822  }
823 
824  return buf;
825 }
826 
827 static mrb_value
828 mrb_win32_basicsocket_sysseek(mrb_state *mrb, mrb_value self)
829 {
830  mrb_raise(mrb, E_NOTIMP_ERROR, "sysseek not implemented for windows sockets");
831  return mrb_nil_value();
832 }
833 
834 static mrb_value
835 mrb_win32_basicsocket_syswrite(mrb_state *mrb, mrb_value self)
836 {
837  int n;
838  SOCKET sd;
839  mrb_value str;
840 
841  sd = socket_fd(mrb, self);
842  mrb_get_args(mrb, "S", &str);
843  n = send(sd, RSTRING_PTR(str), (int)RSTRING_LEN(str), 0);
844  if (n == SOCKET_ERROR)
845  mrb_sys_fail(mrb, "send");
846  return mrb_int_value(mrb, n);
847 }
848 
849 #endif
850 
851 void
853 {
854  struct RClass *io, *ai, *sock, *bsock, *ipsock, *tcpsock;
855  struct RClass *constants;
856 
857 #ifdef _WIN32
858  WSADATA wsaData;
859  int result;
860  result = WSAStartup(MAKEWORD(2,2), &wsaData);
861  if (result != NO_ERROR)
862  mrb_raise(mrb, E_RUNTIME_ERROR, "WSAStartup failed");
863 #endif
864 
865  ai = mrb_define_class(mrb, "Addrinfo", mrb->object_class);
866  mrb_mod_cv_set(mrb, ai, MRB_SYM(_lastai), mrb_nil_value());
868  mrb_define_method(mrb, ai, "getnameinfo", mrb_addrinfo_getnameinfo, MRB_ARGS_OPT(1));
869 #ifndef _WIN32
870  mrb_define_method(mrb, ai, "unix_path", mrb_addrinfo_unix_path, MRB_ARGS_NONE());
871 #endif
872 
873  io = mrb_class_get_id(mrb, MRB_SYM(IO));
874 
875  bsock = mrb_define_class(mrb, "BasicSocket", io);
876  mrb_define_method(mrb, bsock, "_recvfrom", mrb_basicsocket_recvfrom, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
877  mrb_define_method(mrb, bsock, "_setnonblock", mrb_basicsocket_setnonblock, MRB_ARGS_REQ(1));
878  mrb_define_method(mrb, bsock, "getpeereid", mrb_basicsocket_getpeereid, MRB_ARGS_NONE());
879  mrb_define_method(mrb, bsock, "getpeername", mrb_basicsocket_getpeername, MRB_ARGS_NONE());
880  mrb_define_method(mrb, bsock, "getsockname", mrb_basicsocket_getsockname, MRB_ARGS_NONE());
881  mrb_define_method(mrb, bsock, "getsockopt", mrb_basicsocket_getsockopt, MRB_ARGS_REQ(2));
883  // #recvmsg(maxlen, flags=0)
885  // #sendmsg
886  // #sendmsg_nonblock
887  mrb_define_method(mrb, bsock, "setsockopt", mrb_basicsocket_setsockopt, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(2));
888  mrb_define_method(mrb, bsock, "shutdown", mrb_basicsocket_shutdown, MRB_ARGS_OPT(1));
889  mrb_define_method(mrb, bsock, "_is_socket=", mrb_basicsocket_set_is_socket, MRB_ARGS_REQ(1));
890 
891  ipsock = mrb_define_class(mrb, "IPSocket", bsock);
892  mrb_define_class_method(mrb, ipsock, "ntop", mrb_ipsocket_ntop, MRB_ARGS_REQ(1));
893  mrb_define_class_method(mrb, ipsock, "pton", mrb_ipsocket_pton, MRB_ARGS_REQ(2));
894  mrb_define_method(mrb, ipsock, "recvfrom", mrb_ipsocket_recvfrom, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
895 
896  tcpsock = mrb_define_class(mrb, "TCPSocket", ipsock);
897  mrb_define_class_method(mrb, tcpsock, "_allocate", mrb_tcpsocket_allocate, MRB_ARGS_NONE());
898  mrb_define_class(mrb, "TCPServer", tcpsock);
899 
900  mrb_define_class(mrb, "UDPSocket", ipsock);
901  //#recvfrom_nonblock
902 
903  sock = mrb_define_class(mrb, "Socket", bsock);
904  mrb_define_class_method(mrb, sock, "_accept", mrb_socket_accept, MRB_ARGS_REQ(1));
905  mrb_define_class_method(mrb, sock, "_accept2", mrb_socket_accept2, MRB_ARGS_REQ(1));
906  mrb_define_class_method(mrb, sock, "_bind", mrb_socket_bind, MRB_ARGS_REQ(3));
907  mrb_define_class_method(mrb, sock, "_connect", mrb_socket_connect, MRB_ARGS_REQ(3));
908  mrb_define_class_method(mrb, sock, "_listen", mrb_socket_listen, MRB_ARGS_REQ(2));
909  mrb_define_class_method(mrb, sock, "_sockaddr_family", mrb_socket_sockaddr_family, MRB_ARGS_REQ(1));
910  mrb_define_class_method(mrb, sock, "_socket", mrb_socket_socket, MRB_ARGS_REQ(3));
911  //mrb_define_class_method(mrb, sock, "gethostbyaddr", mrb_socket_gethostbyaddr, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
912  //mrb_define_class_method(mrb, sock, "gethostbyname", mrb_socket_gethostbyname, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
913  mrb_define_class_method(mrb, sock, "gethostname", mrb_socket_gethostname, MRB_ARGS_NONE());
914  //mrb_define_class_method(mrb, sock, "getservbyname", mrb_socket_getservbyname, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
915  //mrb_define_class_method(mrb, sock, "getservbyport", mrb_socket_getservbyport, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
916  mrb_define_class_method(mrb, sock, "sockaddr_un", mrb_socket_sockaddr_un, MRB_ARGS_REQ(1));
917  mrb_define_class_method(mrb, sock, "socketpair", mrb_socket_socketpair, MRB_ARGS_REQ(3));
918  //mrb_define_method(mrb, sock, "sysaccept", mrb_socket_accept, MRB_ARGS_NONE());
919 
920 #ifndef _WIN32
921  mrb_define_class(mrb, "UNIXSocket", bsock);
922  //mrb_define_class_method(mrb, usock, "pair", mrb_unixsocket_open, MRB_ARGS_OPT(2));
923  //mrb_define_class_method(mrb, usock, "socketpair", mrb_unixsocket_open, MRB_ARGS_OPT(2));
924 
925  //mrb_define_method(mrb, usock, "recv_io", mrb_unixsocket_peeraddr, MRB_ARGS_NONE());
926  //mrb_define_method(mrb, usock, "recvfrom", mrb_unixsocket_peeraddr, MRB_ARGS_NONE());
927  //mrb_define_method(mrb, usock, "send_io", mrb_unixsocket_peeraddr, MRB_ARGS_NONE());
928 #endif
929 
930  /* Windows IO Method Overrides on BasicSocket */
931 #ifdef _WIN32
932  mrb_define_method(mrb, bsock, "close", mrb_win32_basicsocket_close, MRB_ARGS_NONE());
933  mrb_define_method(mrb, bsock, "sysread", mrb_win32_basicsocket_sysread, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
934  mrb_define_method(mrb, bsock, "sysseek", mrb_win32_basicsocket_sysseek, MRB_ARGS_REQ(1));
935  mrb_define_method(mrb, bsock, "syswrite", mrb_win32_basicsocket_syswrite, MRB_ARGS_REQ(1));
936 #endif
937 
938  constants = mrb_define_module_under(mrb, sock, "Constants");
939 
940 #define define_const(SYM) \
941  do { \
942  mrb_define_const(mrb, constants, #SYM, mrb_int_value(mrb, SYM)); \
943  } while (0)
944 
945 #include "const.cstub"
946 }
947 
948 void
950 {
951  mrb_value ai;
952  ai = mrb_mod_cv_get(mrb, mrb_class_get_id(mrb, MRB_SYM(Addrinfo)), MRB_SYM(_lastai));
953  if (mrb_cptr_p(ai)) {
954  freeaddrinfo((struct addrinfo*)mrb_cptr(ai));
955  }
956 #ifdef _WIN32
957  WSACleanup();
958 #endif
959 }
bp
Definition: action.c:1035
int level
Definition: afm2pl.c:1694
#define type(a)
Definition: aptex-macros.h:171
#define mode
Definition: aptex-macros.h:510
void send(char *str)
Definition: axohelp.c:1054
#define mrb_cptr(o)
Definition: boxing_nan.h:80
#define mrb_integer(o)
Definition: boxing_nan.h:71
#define mrb_string_p(o)
Definition: boxing_word.h:153
#define mrb_integer_p(o)
Definition: boxing_word.h:139
#define mrb_false_p(o)
Definition: boxing_word.h:147
#define mrb_cptr_p(o)
Definition: boxing_word.h:155
#define mrb_true_p(o)
Definition: boxing_word.h:148
#define mrb_nil_p(o)
Definition: boxing_word.h:146
#define mrb_class_ptr(v)
Definition: class.h:24
#define MRB_INSTANCE_TT(c)
Definition: class.h:74
#define n
Definition: t4ht.c:1290
#define b
Definition: jpegint.h:372
#define DATA_PTR(d)
Definition: data.h:50
int ssize_t
Definition: defines.h:155
#define MRB_SYM(name)
Definition: disable.h:20
#define MRB_IVSYM(name)
Definition: disable.h:16
void invalid(int opcode)
Definition: disdvi.c:818
int strcmp()
Definition: coll.cpp:143
int printf()
#define error(a)
Definition: dviinfo.c:48
struct rect data
Definition: dvipdfm.c:64
int fcntl(int fd, int action,...)
Definition: fcntl.c:202
#define O_NONBLOCK
Definition: fcntl.in.h:277
#define s
Definition: afcover.h:80
void shutdown(GtkObject *, gpointer)
#define c(n)
Definition: gpos-common.c:150
#define a(n)
Definition: gpos-common.c:148
#define memcpy(d, s, n)
Definition: gsftopk.c:64
string family
#define bufsize
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
#define buf
#define NO_ERROR
Definition: error.h:34
#define fileno
Definition: win32lib.h:72
static int ret
Definition: convert.c:72
#define dest
ushort gid_t
Definition: types.h:83
ushort uid_t
Definition: types.h:82
int socklen_t
Definition: wsocket.h:14
#define E_TYPE_ERROR
Definition: mruby.h:1308
struct RBasic * mrb_obj_alloc(mrb_state *, enum mrb_vtype, struct RClass *)
Definition: gc.c:535
void mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max)
Definition: error.c:547
void mrb_raisef(mrb_state *mrb, struct RClass *c, const char *fmt,...)
Definition: error.c:400
mrb_value mrb_funcall_id(mrb_state *mrb, mrb_value val, mrb_sym mid, mrb_int argc,...)
Definition: vm.c:337
static void mrb_gc_arena_restore(mrb_state *mrb, int idx)
Definition: mruby.h:1239
static int mrb_gc_arena_save(mrb_state *mrb)
Definition: mruby.h:1233
#define E_NOTIMP_ERROR
Definition: mruby.h:1320
#define MRB_ARGS_OPT(n)
Definition: mruby.h:845
mrb_int mrb_get_args(mrb_state *mrb, mrb_args_format format,...)
Definition: class.c:891
void mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg)
Definition: error.c:214
struct RClass * mrb_class_get_id(mrb_state *mrb, mrb_sym name)
Definition: class.c:639
mrb_value mrb_str_new_cstr(mrb_state *, const char *)
Definition: string.c:203
mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len)
Definition: string.c:197
#define MRB_ARGS_NONE()
Definition: mruby.h:879
#define MRB_ARGS_REQ(n)
Definition: mruby.h:837
#define E_RUNTIME_ERROR
Definition: mruby.h:1307
const char * mrb_obj_classname(mrb_state *mrb, mrb_value obj)
Definition: class.c:2112
#define E_ARGUMENT_ERROR
Definition: mruby.h:1310
mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base)
Definition: numeric.c:1394
#define res(length)
Definition: picttoppm.c:287
static int cnt
Definition: pkout.c:166
bstring c int memset(void *s, int c, int length)
#define flags
mrb_value mrb_ary_new(mrb_state *mrb)
Definition: array.c:53
mrb_value mrb_ary_new_capa(mrb_state *, mrb_int)
Definition: array.c:46
void mrb_ary_push(mrb_state *mrb, mrb_value array, mrb_value value)
Definition: array.c:495
void mrb_sys_fail(mrb_state *mrb, const char *mesg)
Definition: error.c:504
#define mrb_define_class_method(mrb, c, name, f, a)
Definition: scanning.h:16
#define mrb_define_method(mrb, c, name, f, a)
Definition: scanning.h:15
#define mrb_define_class(mrb, name, s)
Definition: scanning.h:18
#define mrb_define_module_under(mrb, o, name)
Definition: scanning.h:21
void mrb_mod_cv_set(mrb_state *mrb, struct RClass *c, mrb_sym sym, mrb_value v)
Definition: variable.c:657
mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass *c, mrb_sym sym)
Definition: variable.c:616
mrb_value mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym)
Definition: variable.c:320
mrb_value mrb_const_get(mrb_state *, mrb_value, mrb_sym)
Definition: variable.c:794
void mrb_cv_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v)
Definition: variable.c:702
mrb_value mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
Definition: variable.c:651
size_t fsize_t
Definition: io.c:52
static mrb_value mrb_ipsocket_pton(mrb_state *mrb, mrb_value klass)
Definition: socket.c:531
static mrb_value mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
Definition: socket.c:119
static mrb_value mrb_socket_accept2(mrb_state *mrb, mrb_value klass)
Definition: socket.c:622
#define E_SOCKET_ERROR
Definition: socket.c:57
static mrb_value mrb_socket_sockaddr_un(mrb_state *mrb, mrb_value klass)
Definition: socket.c:697
static mrb_value mrb_socket_connect(mrb_state *mrb, mrb_value klass)
Definition: socket.c:658
void mrb_mruby_socket_gem_init(mrb_state *mrb)
Definition: socket.c:852
static mrb_value mrb_ipsocket_ntop(mrb_state *mrb, mrb_value klass)
Definition: socket.c:516
static mrb_value mrb_basicsocket_setnonblock(mrb_state *mrb, mrb_value self)
Definition: socket.c:416
static mrb_value mrb_basicsocket_getsockopt(mrb_state *mrb, mrb_value self)
Definition: socket.c:338
static mrb_value mrb_socket_gethostname(mrb_state *mrb, mrb_value cls)
Definition: socket.c:590
static mrb_value mrb_basicsocket_getsockname(mrb_state *mrb, mrb_value self)
Definition: socket.c:325
static mrb_value mrb_tcpsocket_allocate(mrb_state *mrb, mrb_value klass)
Definition: socket.c:760
static mrb_value mrb_socket_bind(mrb_state *mrb, mrb_value klass)
Definition: socket.c:645
static mrb_value mrb_addrinfo_unix_path(mrb_state *mrb, mrb_value self)
Definition: socket.c:222
static mrb_value mrb_basicsocket_set_is_socket(mrb_state *mrb, mrb_value self)
Definition: socket.c:501
static mrb_value mrb_basicsocket_recv(mrb_state *mrb, mrb_value self)
Definition: socket.c:358
static int socket_fd(mrb_state *mrb, mrb_value sock)
Definition: socket.c:271
static mrb_value mrb_socket_socket(mrb_state *mrb, mrb_value klass)
Definition: socket.c:747
static mrb_value mrb_ipsocket_recvfrom(mrb_state *mrb, mrb_value self)
Definition: socket.c:562
static mrb_value mrb_basicsocket_getpeername(mrb_state *mrb, mrb_value self)
Definition: socket.c:312
static mrb_value mrb_socket_listen(mrb_state *mrb, mrb_value klass)
Definition: socket.c:671
static mrb_value mrb_basicsocket_send(mrb_state *mrb, mrb_value self)
Definition: socket.c:397
static mrb_value mrb_basicsocket_getpeereid(mrb_state *mrb, mrb_value self)
Definition: socket.c:289
static int socket_family(int s)
Definition: socket.c:277
static mrb_value sa2addrlist(mrb_state *mrb, const struct sockaddr *sa, socklen_t salen)
Definition: socket.c:238
static mrb_value mrb_socket_socketpair(mrb_state *mrb, mrb_value klass)
Definition: socket.c:724
static mrb_value mrb_addrinfo_getnameinfo(mrb_state *mrb, mrb_value self)
Definition: socket.c:193
static mrb_value mrb_basicsocket_setsockopt(mrb_state *mrb, mrb_value self)
Definition: socket.c:445
size_t fsize_t
Definition: socket.c:31
static mrb_value mrb_socket_accept(mrb_state *mrb, mrb_value klass)
Definition: socket.c:608
void mrb_mruby_socket_gem_final(mrb_state *mrb)
Definition: socket.c:949
static mrb_value mrb_basicsocket_shutdown(mrb_state *mrb, mrb_value self)
Definition: socket.c:490
static mrb_value mrb_basicsocket_recvfrom(mrb_state *mrb, mrb_value self)
Definition: socket.c:374
static mrb_value mrb_socket_sockaddr_family(mrb_state *mrb, mrb_value klass)
Definition: socket.c:683
#define ttype(o)
Definition: lobject.h:133
#define offsetof(T, M)
Definition: dir.c:27
#define str(s)
Definition: sh6.c:399
static FILE * in
Definition: squeeze.c:36
mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len)
Definition: string.c:832
#define RSTRING_CSTR(mrb, s)
Definition: string.h:106
#define RSTRING_LEN(s)
Definition: string.h:102
#define RSTRING_PTR(s)
Definition: string.h:100
mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa)
Definition: string.c:160
Definition: class.h:17
Definition: object.h:30
Definition: sed.h:84
Definition: edgelist.h:31
Definition: in.h:179
Definition: psread.c:42
struct RClass * object_class
Definition: mruby.h:242
Definition: tpic.c:45
Definition: sh2.c:920
Definition: in.h:99
pointer path
Definition: t1imager.h:36
s1
Definition: t4ht.c:1059
*job_name strlen((char *) job_name) - 4)
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
#define s0
Definition: tokst.h:45
void mesg(const char *msg,...)
Definition: ttf2pfb.c:255
#define mrb_test(o)
Definition: value.h:265
int32_t mrb_int
Definition: value.h:35
static mrb_value mrb_nil_value(void)
Definition: value.h:332
static mrb_value mrb_bool_value(mrb_bool boolean)
Definition: value.h:360
mrb_vtype
Definition: value.h:107
@ MRB_TT_OBJECT
Definition: value.h:116
static mrb_value mrb_fixnum_value(mrb_int i)
Definition: value.h:301
static mrb_value mrb_cptr_value(struct mrb_state *mrb, void *p)
Definition: value.h:283
static mrb_value mrb_int_value(struct mrb_state *mrb, mrb_int i)
Definition: value.h:294
static mrb_value mrb_obj_value(void *p)
Definition: value.h:317
unsigned long u_long
Definition: vmsdir.h:26
unsigned short ntohs(unsigned short inv)
#define argc
Definition: xmain.c:269