/* copy some scalers to an unaligned buffer */

#include <unistd.h>
#include <string.h>

/* note that this ignores byte swapping, since byte swapping happens to
   not be necessary when a sparc is talking to java ... sparc just
   happens to be in the right byte order (!) */

void to_java_int(char * buf, int i){
  memcpy(buf, (char *) &i, sizeof i);
}

void to_java_double(char * buf, double d){
  memcpy(buf, (char *) &d, sizeof d);
}

void to_java_unsigned_short(char * buf, int i){
  unsigned short u = i;
  memcpy(buf, (char *) &u, sizeof u);
}

/* ... library(tcp) ... */

int write_buffer_to_stream(stream, buf, size)
    QP_stream * stream;
    char * buf;
    int size;
    {
	int stat = QP_fwrite(buf, size, 1, stream);
	if (stat >= 0) {
	    stat = QP_flush(stream);
	}
	if (stat >= 0) {
	    return stat;
	} else {
	    return -(QP_errno);
	}
    }
