/*------------------------------------------------------------ * Vport Gets */ static int vport_getz(char *buf, int buflen, ScmPort *p) { vport *data = (vport*)p->src.vt.data; SCM_ASSERT(data != NULL); if (!SCM_FALSEP(data->gets_proc)) { u_int size; const char *start; ScmObj s = Scm_ApplyRec(data->gets_proc, SCM_LIST1(SCM_MAKE_INT(buflen))); if (!SCM_STRINGP(s)) return EOF; start = Scm_GetStringContent(SCM_STRING(s), &size, NULL, NULL); if ((int)size > buflen) { /* NB: should raise an exception? */ memcpy(buf, start, buflen); return buflen; } else { memcpy(buf, start, size); return size; } } else { int byte, i; for (i=0; i<buflen; i++) { byte = vport_getb(p); if (byte == EOF) break; buf[i] = byte; } if (i==0) return EOF; else return i; } }
static const char *get_message_body(ScmObj msg, u_int *size) { if (SCM_UVECTORP(msg)) { *size = Scm_UVectorSizeInBytes(SCM_UVECTOR(msg)); return (const char*)SCM_UVECTOR_ELEMENTS(msg); } else if (SCM_STRINGP(msg)) { return Scm_GetStringContent(SCM_STRING(msg), size, NULL, NULL); } else { Scm_TypeError("socket message", "uniform vector or string", msg); *size = 0; /* dummy */ return NULL; } }
static const uint8_t* get_message_body(ScmObj msg, u_int *size) { if (SCM_UVECTORP(msg)) { *size = Scm_UVectorSizeInBytes(SCM_UVECTOR(msg)); return (const uint8_t*) SCM_UVECTOR_ELEMENTS(msg); } else if (SCM_STRINGP(msg)) { return (const uint8_t*)Scm_GetStringContent(SCM_STRING(msg), size, 0, 0); } else { Scm_TypeError("TLS message", "uniform vector or string", msg); *size = 0; return 0; } }
void Scm_PutsUnsafe(ScmString *s, ScmPort *p) #endif { VMDECL; SHORTCUT(p, Scm_PutsUnsafe(s, p); return); WALKER_CHECK(p); LOCK(p); CLOSE_CHECK(p); switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: { u_int size; const char *ss = Scm_GetStringContent(s, &size, NULL, NULL); SAFE_CALL(p, bufport_write(p, ss, size)); if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_LINE) { const char *cp = p->src.buf.current; while (cp-- > p->src.buf.buffer) { if (*cp == '\n') { SAFE_CALL(p, bufport_flush(p, (int)(cp - p->src.buf.current), FALSE)); break; } } } else if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_NONE) { SAFE_CALL(p, bufport_flush(p, 0, TRUE)); } UNLOCK(p); break; } case SCM_PORT_OSTR: Scm_DStringAdd(&p->src.ostr, s); UNLOCK(p); break; case SCM_PORT_PROC: SAFE_CALL(p, p->src.vt.Puts(s, p)); UNLOCK(p); break; default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_OUTPUT, "bad port type for output: %S", p); } }