* NULL on I/O error. */
static char *
-fd_alloc_r_at (unix_stream * s, int *len, gfc_offset where)
+fd_alloc_r_at (unix_stream * s, int *len)
{
gfc_offset m;
-
- if (where == -1)
- where = s->logical_offset;
+ gfc_offset where = s->logical_offset;
if (s->buffer != NULL && s->buffer_offset <= where &&
where + *len <= s->buffer_offset + s->active)
* we've already buffered the data or we need to load it. */
static char *
-fd_alloc_w_at (unix_stream * s, int *len, gfc_offset where)
+fd_alloc_w_at (unix_stream * s, int *len)
{
gfc_offset n;
-
- if (where == -1)
- where = s->logical_offset;
+ gfc_offset where = s->logical_offset;
if (s->buffer == NULL || s->buffer_offset > where ||
where + *len > s->buffer_offset + s->len)
/* memset() in chunks of BUFFER_SIZE. */
trans = (bytes_left < BUFFER_SIZE) ? bytes_left : BUFFER_SIZE;
- p = fd_alloc_w_at (s, &trans, -1);
+ p = fd_alloc_w_at (s, &trans);
if (p)
memset (p, c, trans);
else
if (*nbytes < BUFFER_SIZE && s->method == SYNC_BUFFERED)
{
tmp = *nbytes;
- p = fd_alloc_r_at (s, &tmp, -1);
+ p = fd_alloc_r_at (s, &tmp);
if (p)
{
*nbytes = tmp;
if (*nbytes < BUFFER_SIZE && s->method == SYNC_BUFFERED)
{
tmp = *nbytes;
- p = fd_alloc_w_at (s, &tmp, -1);
+ p = fd_alloc_w_at (s, &tmp);
if (p)
{
*nbytes = tmp;
else
s->method = SYNC_BUFFERED;
- s->st.alloc_r_at = (void *) fd_alloc_r_at;
s->st.alloc_w_at = (void *) fd_alloc_w_at;
s->st.sfree = (void *) fd_sfree;
s->st.close = (void *) fd_close;
static char *
-mem_alloc_r_at (int_stream * s, int *len, gfc_offset where)
+mem_alloc_r_at (int_stream * s, int *len)
{
gfc_offset n;
-
- if (where == -1)
- where = s->logical_offset;
+ gfc_offset where = s->logical_offset;
if (where < s->buffer_offset || where > s->buffer_offset + s->active)
return NULL;
static char *
-mem_alloc_w_at (int_stream * s, int *len, gfc_offset where)
+mem_alloc_w_at (int_stream * s, int *len)
{
gfc_offset m;
+ gfc_offset where = s->logical_offset;
assert (*len >= 0); /* Negative values not allowed. */
- if (where == -1)
- where = s->logical_offset;
-
m = where + *len;
if (where < s->buffer_offset)
}
-/* Stream read function for internal units. This is not actually used
- at the moment, as all internal IO is formatted and the formatted IO
- routines use mem_alloc_r_at. */
+/* Stream read function for internal units. */
static int
mem_read (int_stream * s, void * buf, size_t * nbytes)
int tmp;
tmp = *nbytes;
- p = mem_alloc_r_at (s, &tmp, -1);
+ p = mem_alloc_r_at (s, &tmp);
if (p)
{
*nbytes = tmp;
else
{
*nbytes = 0;
- return errno;
+ return 0;
}
}
void *p;
int tmp;
- errno = 0;
-
tmp = *nbytes;
- p = mem_alloc_w_at (s, &tmp, -1);
+ p = mem_alloc_w_at (s, &tmp);
if (p)
{
*nbytes = tmp;
else
{
*nbytes = 0;
- return errno;
+ return 0;
}
}
len = n;
- p = mem_alloc_w_at (s, &len, -1);
+ p = mem_alloc_w_at (s, &len);
if (p)
{
memset (p, c, len);
s->logical_offset = 0;
s->active = s->file_length = length;
- s->st.alloc_r_at = (void *) mem_alloc_r_at;
s->st.alloc_w_at = (void *) mem_alloc_w_at;
s->st.sfree = (void *) mem_sfree;
s->st.close = (void *) mem_close;