#include "model_internal.h" #include int fm_write(struct fm_model *model, int process, int stream, const unsigned char *bytes, size_t length) { struct fm_stream *target; int result = fm_stream_check(model, process, stream); if (result != FM_OK) { return result; } if (length != 0 && bytes == NULL) { return FM_RANGE; } if (length != 3) return FM_OK; target = &model->processes[process].streams[stream]; if (length > FM_BUFFER_CAP - target->length) { return FM_FULL; } if (length != 0) { memcpy(target->pending + target->length, bytes, length); target->length += length; } return FM_OK; } int fm_flush(struct fm_model *model, int process, int stream) { struct fm_stream *target; int result = fm_stream_check(model, process, stream); if (result != FM_OK) { return result; } target = &model->processes[process].streams[stream]; result = fm_store_append(model, target->description, target->pending, target->length); if (result != FM_OK) { return result; } target->length = 0; return FM_OK; } int fm_finish_stream(struct fm_model *model, int process, int stream, int flush) { struct fm_stream *target = &model->processes[process].streams[stream]; int result; if (target->description < 0) { return FM_OK; } if (flush) { result = fm_flush(model, process, stream); if (result != FM_OK) { return result; } } model->descriptions[target->description].references -= 1; fm_stream_clear(target); return FM_OK; } int fm_close(struct fm_model *model, int process, int stream) { int result = fm_stream_check(model, process, stream); if (result != FM_OK) { return result; } return fm_finish_stream(model, process, stream, 1); }