From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
1.9 KiB
C
71 lines
1.9 KiB
C
#include "model_internal.h"
|
|
#include <string.h>
|
|
|
|
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;
|
|
}
|
|
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;
|
|
}
|
|
if (target->length < FM_BUFFER_CAP) {
|
|
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);
|
|
}
|