[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] ios: Introduce IO stream device for stdin, stdout, stderr.
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] ios: Introduce IO stream device for stdin, stdout, stderr. |
Date: |
Sun, 12 Jul 2020 18:48:06 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Ege.
+static int
+ios_buffer_allocate_new_chunk (ios_buffer *buffer, int final_chunk_no,
+ ios_buffer_chunk **final_chunk)
+{
+ ios_buffer_chunk *chunk;
+ int bucket_no;
+
+ assert (buffer->next_chunk_no <= final_chunk_no);
+
+ do
+ {
+ chunk = calloc(1, sizeof (ios_buffer_chunk));
+ if (!chunk)
+ return IOD_ERROR;
+ /* Place the new chunk into the buffer. */
+ chunk->chunk_no = buffer->next_chunk_no;
+ bucket_no = IOB_BUCKET_NO (chunk->chunk_no);
+ chunk->next = buffer->chunks[bucket_no];
+ buffer->chunks[bucket_no] = chunk;
+ buffer->next_chunk_no++;
+ }
+ while (buffer->next_chunk_no <= final_chunk_no);
+
+ /* end_offset is updated as the buffer is written to. Therefore, it is
not
+ updated here, but in ios_buffer_pwrite. */
+ *final_chunk = chunk;
+ return 0;
+}
I think it would be good to introduce an IOD_OK (defined as 0) so we can
write return IOD_OK above.
+static int
+ios_dev_stream_flush (void *iod, ios_dev_off offset)
+{
+ struct ios_dev_stream *sio = iod;
+ if (sio->flags & IOS_F_READ)
+ return ios_buffer_forget_till (sio->buffer, offset);
+ else
+ return IOS_OK;
+}
Consequently, the above should return IOD_OK, not IOS_OK. The caller to
the IOD interface should then translate from IOD error codes to IOS
error codes...