Rework the stream interface, so that the stream read & write methods just have to actually read or write the data.

[INTERPRETER]
* NEW: Rework the stream interface, so that the stream read & write methods just have to actually read or write the data.
This commit is contained in:
gambas 2017-09-27 02:48:00 +02:00
parent fbc25622c5
commit aa67ba1309
25 changed files with 219 additions and 265 deletions

View File

@ -72,7 +72,6 @@ GB_STREAM_DESC BZStream =
open: BZ_stream_open,
close: BZ_stream_close,
read: BZ_stream_read,
getchar: BZ_stream_getchar,
write: BZ_stream_write,
seek: BZ_stream_seek,
tell: BZ_stream_tell,
@ -481,7 +480,7 @@ static int BZ_stream_write(GB_STREAM *stream, char *buffer, int len)
if (P_MODE==MODE_READ) return -1;
BZ2_bzWrite ( &bzerror,P_BZ, (void*)buffer, len);
if (!bzerror) { P_POS+=len; return 0; }
if (!bzerror) { P_POS += len; return len; }
//BZ2_bzWriteClose (&bzerror,P_BZ,0,NULL,NULL);
//fclose(P_FILE);
@ -508,18 +507,16 @@ static int BZ_stream_read(GB_STREAM *stream, char *buffer, int len)
if (!bzerror)
{
GB.Stream.SetBytesRead(stream, len2);
P_POS += len2;
return 0;
return len2;
}
else
{
if ((len2 == len) && (bzerror == BZ_STREAM_END))
{
GB.Stream.SetBytesRead(stream, len2);
P_POS += len2;
P_EOF = 1;
return 0;
return len2;
}
}
@ -530,11 +527,6 @@ static int BZ_stream_read(GB_STREAM *stream, char *buffer, int len)
return -1;
}
static int BZ_stream_getchar(GB_STREAM *stream, char *buffer)
{
return BZ_stream_read(stream,buffer,1);
}
/****************************************************************************
This array of functions defines what functions the compression component

View File

@ -44,7 +44,6 @@ static int BZ_stream_close(GB_STREAM *stream);
static int BZ_stream_write(GB_STREAM *stream, char *buffer, int len);
static int BZ_stream_eof(GB_STREAM *stream);
static int BZ_stream_read(GB_STREAM *stream, char *buffer, int len);
static int BZ_stream_getchar(GB_STREAM *stream, char *buffer);
#endif /* __MAIN_H */

View File

@ -454,14 +454,9 @@ static int CZ_stream_write(GB_STREAM *stream, char *buffer, int len)
STREAM_COMPRESS *s = (STREAM_COMPRESS *)stream;
if (s->mode == MODE_READ)
return TRUE;
return -1;
if ( gzwrite (s->handle, (voidp)buffer, (unsigned)len) == len)
return FALSE;
//gzclose (s->handle);
//stream->desc=NULL;
return TRUE;
return gzwrite(s->handle, (voidp)buffer, (unsigned)len);
}
static int CZ_stream_eof(GB_STREAM *stream)
@ -472,19 +467,11 @@ static int CZ_stream_eof(GB_STREAM *stream)
static int CZ_stream_read(GB_STREAM *stream, char *buffer, int len)
{
STREAM_COMPRESS *s = (STREAM_COMPRESS *)stream;
int n;
if (s->mode == MODE_WRITE)
return -1;
n = gzread(s->handle, (voidp)buffer, (unsigned)len);
if (n > 0)
{
GB.Stream.SetBytesRead(stream, n);
return 0;
}
else
return -1;
return gzread(s->handle, (voidp)buffer, (unsigned)len);
}

View File

@ -2569,7 +2569,7 @@ fflush(stderr);
else
comma = TRUE;
DB.Query.Add(fp->name);
DB.Query.Add(fp->name);
//AB autoincrement field is mapped to Integer because this is Database dependent
if (fp->type == DB_T_SERIAL)
@ -3363,4 +3363,4 @@ int EXPORT GB_INIT(void)
void EXPORT GB_EXIT()
{
}
}

View File

@ -1259,7 +1259,7 @@ static int begin_transaction(DB_DATABASE *db)
{
char buffer[8];
sprintf(buffer, "%d", trans - 1);
return do_query(db, "Unable to begin transaction: &1", NULL, "SAVEPOINT t&1", 1, buffer);
return do_query(db, "Unable to begin transaction: Unable to define savepoint: &1", NULL, "SAVEPOINT t&1", 1, buffer);
}
}
@ -1290,7 +1290,7 @@ static int commit_transaction(DB_DATABASE *db)
{
char buffer[8];
sprintf(buffer, "%d", trans);
return do_query(db, "Unable to begin transaction: &1", NULL, "RELEASE SAVEPOINT t&1", 1, buffer);
return do_query(db, "Unable to commit transaction: Unable to release savepoint: &1", NULL, "RELEASE SAVEPOINT t&1", 1, buffer);
}
}

View File

@ -162,9 +162,7 @@ int CCURL_stream_read(GB_STREAM *stream, char *buffer, int len)
GB.FreeString(&THIS->data);
THIS->data = new_data;
GB.Stream.SetBytesRead(stream, len);
return 0;
return len;
}
static void raise_event(void *_object, int event)

View File

@ -448,16 +448,12 @@ int CSocket_stream_read(GB_STREAM *stream, char *buffer, int len)
if (bytes < len)
len = bytes;
USE_MSG_NOSIGNAL(npos=recv(SOCKET->socket,(void*)buffer,len*sizeof(char),MSG_NOSIGNAL));
GB.Stream.SetBytesRead(stream, npos);
if (npos==len) return 0;
USE_MSG_NOSIGNAL(npos = recv(SOCKET->socket,(void*)buffer,len*sizeof(char),MSG_NOSIGNAL));
if (npos < 0 && errno != EAGAIN)
CSocket_stream_internal_error(THIS, NET_CANNOT_READ, FALSE);
return -1;
return npos;
}
int CSocket_stream_write(GB_STREAM *stream, char *buffer, int len)
@ -467,14 +463,7 @@ int CSocket_stream_write(GB_STREAM *stream, char *buffer, int len)
if (!THIS) return -1;
while (len > 0)
{
USE_MSG_NOSIGNAL(npos=send(SOCKET->socket,(void*)buffer,len*sizeof(char),MSG_NOSIGNAL));
if (npos <= 0)
break;
len -= npos;
buffer += npos;
}
USE_MSG_NOSIGNAL(npos = send(SOCKET->socket,(void*)buffer,len*sizeof(char),MSG_NOSIGNAL));
if (npos >= 0 || errno == EAGAIN)
{
@ -486,13 +475,10 @@ int CSocket_stream_write(GB_STREAM *stream, char *buffer, int len)
}
}
if (npos >= 0)
return 0;
if (errno != EAGAIN)
CSocket_stream_internal_error(THIS, NET_CANNOT_WRITE, FALSE);
return -1;
return npos;
}

View File

@ -226,9 +226,7 @@ int CUdpSocket_stream_read(GB_STREAM *stream, char *buffer, int len)
memcpy(buffer, &THIS->buffer[THIS->buffer_pos], len);
THIS->buffer_pos += len;
GB.Stream.SetBytesRead(stream, len);
return 0;
return len;
}
int CUdpSocket_stream_write(GB_STREAM *stream, char *buffer, int len)
@ -275,12 +273,13 @@ int CUdpSocket_stream_write(GB_STREAM *stream, char *buffer, int len)
USE_MSG_NOSIGNAL(retval = sendto(SOCKET->socket, (void*)buffer, len, MSG_NOSIGNAL, addr, size));
if (retval >= 0)
return 0;
if (retval < 0)
{
CUdpSocket_stream_close(stream);
SOCKET->status= NET_CANNOT_WRITE;
}
CUdpSocket_stream_close(stream);
SOCKET->status= NET_CANNOT_WRITE;
return -1;
return retval;
}
/************************************************************************************************

View File

@ -280,7 +280,6 @@ const void *const GAMBAS_Api[] =
(void *)GB_HashTableFirst,
(void *)GB_StreamGet,
(void *)GB_StreamSetBytesRead,
(void *)GB_StreamSetSwapping,
(void *)GB_StreamSetAvailableNow,
(void *)GB_StreamBlock,
@ -2267,11 +2266,6 @@ GB_STREAM *GB_StreamGet(void *object)
return (GB_STREAM *)CSTREAM_stream(object);
}
void GB_StreamSetBytesRead(GB_STREAM *stream, int length)
{
STREAM_eff_read += length;
}
void GB_StreamSetSwapping(GB_STREAM *stream, int v)
{
((STREAM *)stream)->common.swap = v;
@ -2297,10 +2291,7 @@ int GB_StreamRead(GB_STREAM *stream, void *addr, int len)
if (len < 0)
ret = STREAM_read_max((STREAM *)stream, addr, -len);
else
{
STREAM_read((STREAM *)stream, addr, len);
ret = STREAM_eff_read;
}
ret = STREAM_read((STREAM *)stream, addr, len);
}
END_CATCH_ERROR_INT
}

View File

@ -200,7 +200,7 @@ int GB_CountArray(void *data);
void *GB_Add(void *pdata);
GB_STREAM *GB_StreamGet(void *);
void GB_StreamSetBytesRead(GB_STREAM *, int);
//void GB_StreamSetBytesRead(GB_STREAM *, int);
void GB_StreamSetSwapping(GB_STREAM *, int);
void GB_StreamSetAvailableNow(GB_STREAM *, int);
bool GB_StreamBlock(GB_STREAM *, int);

View File

@ -524,9 +524,9 @@ void ARCHIVE_stat(ARCHIVE *arch, const char *path, FILE_STAT *info)
}
bool ARCHIVE_read(ARCHIVE *arch, int pos, void *buffer, int len)
void ARCHIVE_read(ARCHIVE *arch, int pos, void *buffer, int len)
{
return ARCH_read(arch->arch, pos, buffer, len);
ARCH_read(arch->arch, pos, buffer, len);
}

View File

@ -79,7 +79,7 @@ void ARCHIVE_load_exported_class(ARCHIVE *arch, int pass);
bool ARCHIVE_get(ARCHIVE *arch, const char **ppath, ARCHIVE_FIND *find);
bool ARCHIVE_read(ARCHIVE *arch, int pos, void *buffer, int len);
void ARCHIVE_read(ARCHIVE *arch, int pos, void *buffer, int len);
bool ARCHIVE_exist(ARCHIVE *arch, const char *path);
void ARCHIVE_stat(ARCHIVE *arch, const char *path, FILE_STAT *info);

View File

@ -578,6 +578,7 @@ BEGIN_PROPERTY(Task_Value)
FILE_STAT info;
char *err = NULL;
int fd;
int n;
if (!THIS->child && THIS->stopped)
{
@ -629,7 +630,12 @@ BEGIN_PROPERTY(Task_Value)
fd = open(path, O_RDONLY);
if (fd < 0) goto __ERROR;
STREAM_read_direct(fd, err, info.size);
for(;;)
{
n = read(fd, err, info.size);
if (n == info.size || errno != EINTR)
break;
}
close(fd);
GB_Error("Task has failed: &1", err);

View File

@ -54,8 +54,6 @@
#include "gbx_struct.h"
#include "gbx_stream.h"
int STREAM_eff_read;
static STREAM _temp_stream = { 0 };
static STREAM *_temp_save = NULL;
static int _temp_level;
@ -319,52 +317,68 @@ void STREAM_flush(STREAM *stream)
(*(stream->type->flush))(stream);
}
static void read_buffer(STREAM *stream, void **addr, int *len)
static int read_buffer(STREAM *stream, void *addr, int len)
{
int l = stream->common.buffer_len - stream->common.buffer_pos;
if (l > *len)
l = *len;
if (l > len)
l = len;
if (l > 0)
{
memcpy(*addr, stream->common.buffer + stream->common.buffer_pos, l);
*addr = (char *)*addr + l;
*len -= l;
STREAM_eff_read += l;
memcpy(addr, stream->common.buffer + stream->common.buffer_pos, l);
stream->common.buffer_pos += l;
return l;
}
else
return 0;
}
void STREAM_read(STREAM *stream, void *addr, int len)
int STREAM_read(STREAM *stream, void *addr, int len)
{
STREAM_eff_read = 0;
int eff = 0;
int n;
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
if (len <= 0)
return;
return 0;
if (stream->common.buffer)
read_buffer(stream, &addr, &len);
while ((*(stream->type->read))(stream, addr, len))
{
if (errno == EINTR)
continue;
stop_watching(stream, GB_WATCH_READ);
switch(errno)
{
case 0:
case EAGAIN:
THROW(E_EOF);
case EIO:
THROW(E_READ);
default:
THROW_SYSTEM(errno, NULL);
}
eff = read_buffer(stream, addr, len);
addr += eff;
len -= eff;
}
while (len > 0)
{
n = (*(stream->type->read))(stream, addr, len);
if ((n <= 0) && errno != EINTR)
{
stop_watching(stream, GB_WATCH_READ);
if (n == 0)
THROW(E_EOF);
switch(errno)
{
case 0:
case EAGAIN:
THROW(E_EOF);
case EIO:
THROW(E_READ);
default:
THROW_SYSTEM(errno, NULL);
}
}
eff += n;
addr += n;
len -= n;
}
return eff;
}
#if 0
@ -386,7 +400,7 @@ char STREAM_getchar(STREAM *stream)
else
ret = (*(stream->type->read))(stream, &c, 1);
if (!ret)
if (ret == 1)
break;
if (errno == EINTR)
@ -413,74 +427,82 @@ char STREAM_getchar(STREAM *stream)
int STREAM_read_max(STREAM *stream, void *addr, int len)
{
bool err;
int eff = 0;
int n;
int flags, handle;
int save_errno;
if (!stream->type)
THROW(E_CLOSED);
STREAM_eff_read = 0;
if (len <= 0)
return 0;
if (stream->common.buffer)
read_buffer(stream, &addr, &len);
if (len > 0)
{
for(;;)
eff += read_buffer(stream, addr, len);
addr += eff;
len -= eff;
}
while (len > 0)
{
if (stream->common.available_now)
{
if (stream->common.available_now)
n = (*(stream->type->read))(stream, addr, len);
}
else
{
handle = STREAM_handle(stream);
flags = fcntl(handle, F_GETFL);
if ((flags & O_NONBLOCK) == 0)
{
err = (*(stream->type->read))(stream, addr, len);
}
else
{
handle = STREAM_handle(stream);
flags = fcntl(handle, F_GETFL);
if ((flags & O_NONBLOCK) == 0)
{
wait_for_fd_ready_to_read(handle);
fcntl(handle, F_SETFL, flags | O_NONBLOCK);
}
errno = 0;
err = (*(stream->type->read))(stream, addr, len);
save_errno = errno;
if ((flags & O_NONBLOCK) == 0)
fcntl(handle, F_SETFL, flags);
errno = save_errno;
wait_for_fd_ready_to_read(handle);
fcntl(handle, F_SETFL, flags | O_NONBLOCK);
}
if (!err)
break;
errno = 0;
n = (*(stream->type->read))(stream, addr, len);
save_errno = errno;
if (errno == EINTR)
continue;
if ((flags & O_NONBLOCK) == 0)
fcntl(handle, F_SETFL, flags);
if (errno == 0)
errno = save_errno;
}
if (n > 0)
eff += n;
if (n <= 0 && errno != EINTR)
{
if (n == 0 || errno == 0)
{
stop_watching(stream, GB_WATCH_READ);
return eff;
}
switch(errno)
{
case 0:
case EAGAIN:
return STREAM_eff_read;
case EIO:
return -1; //THROW(E_READ);
return eff;
default:
THROW_SYSTEM(errno, NULL);
}
}
addr += n;
len -= n;
}
return STREAM_eff_read;
return eff;
}
void STREAM_write(STREAM *stream, void *addr, int len)
{
int n;
if (STREAM_is_closed_for_writing(stream))
THROW(E_CLOSED);
@ -490,17 +512,24 @@ void STREAM_write(STREAM *stream, void *addr, int len)
if (stream->common.redirected)
stream = stream->common.redirect;
while ((*(stream->type->write))(stream, addr, len))
while (len > 0)
{
switch(errno)
n = ((*(stream->type->write))(stream, addr, len));
if (n <= 0 && errno != EINTR)
{
case EINTR:
break;
case EIO:
THROW(E_WRITE);
default:
THROW_SYSTEM(errno, NULL);
switch(errno)
{
case 0:
case EIO:
THROW(E_WRITE);
default:
THROW_SYSTEM(errno, NULL);
}
}
addr += n;
len -= n;
}
}
@ -565,18 +594,20 @@ void STREAM_seek(STREAM *stream, int64_t pos, int whence)
release_buffer(stream);
}
static void fill_buffer(STREAM *stream, char *addr, bool do_not_wait_ready)
static int fill_buffer(STREAM *stream, char *addr, bool do_not_wait_ready)
{
bool err;
int n;
int flags, fd;
int len;
int eff = 0;
STREAM_eff_read = 0;
fd = STREAM_handle(stream);
len = STREAM_BUFFER_SIZE;
for(;;)
while (len > 0)
{
if (stream->common.available_now)
err = (*(stream->type->read))(stream, addr, STREAM_BUFFER_SIZE);
n = (*(stream->type->read))(stream, addr, len);
else
{
if (!do_not_wait_ready)
@ -586,7 +617,7 @@ static void fill_buffer(STREAM *stream, char *addr, bool do_not_wait_ready)
if ((flags & O_NONBLOCK) == 0)
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
err = (*(stream->type->read))(stream, addr, STREAM_BUFFER_SIZE);
n = (*(stream->type->read))(stream, addr, len);
if ((flags & O_NONBLOCK) == 0)
{
@ -596,31 +627,36 @@ static void fill_buffer(STREAM *stream, char *addr, bool do_not_wait_ready)
}
}
if (!err)
break;
if (errno == EINTR)
continue;
//if (STREAM_eff_read == 0 && stream->common.available_now)
// WATCH_need_little_sleep = TRUE;
switch(errno)
if (n == 0)
return eff;
if (n > 0)
eff += n;
if (n < 0 && errno != EINTR)
{
case 0:
case EAGAIN:
case EINPROGRESS:
return;
case EIO:
return; //THROW(E_READ);
default:
THROW_SYSTEM(errno, NULL);
switch(errno)
{
case EAGAIN:
case EINPROGRESS:
case EIO:
return eff;
default:
THROW_SYSTEM(errno, NULL);
}
}
addr += n;
len -= n;
}
return eff;
}
bool STREAM_read_ahead(STREAM *stream)
{
int eff;
if (stream->common.no_read_ahead)
return FALSE;
@ -630,14 +666,12 @@ bool STREAM_read_ahead(STREAM *stream)
if (!stream->common.buffer)
ALLOC(&stream->common.buffer, STREAM_BUFFER_SIZE);
fill_buffer(stream, stream->common.buffer, TRUE);
eff = fill_buffer(stream, stream->common.buffer, TRUE);
stream->common.buffer_pos = 0;
stream->common.buffer_len = STREAM_eff_read;
stream->common.buffer_len = eff;
//fprintf(stderr, "STREAM_read_ahead: %d\n", STREAM_eff_read);
if (STREAM_eff_read == 0)
if (eff == 0)
{
stream->common.eof = TRUE;
return TRUE;
@ -816,10 +850,8 @@ static char *input(STREAM *stream, bool line, char *escape)
stream->common.buffer_pos = buffer_pos;
stream->common.buffer_len = buffer_len;
fill_buffer(stream, buffer, FALSE);
buffer_pos = 0;
buffer_len = STREAM_eff_read;
buffer_len = fill_buffer(stream, buffer, FALSE);
if (!buffer_len)
{
@ -1671,6 +1703,7 @@ bool STREAM_eof(STREAM *stream)
}
#if 0
int STREAM_read_direct(int fd, char *buffer, int len)
{
ssize_t eff_read;
@ -1722,7 +1755,7 @@ int STREAM_write_direct(int fd, char *buffer, int len)
return FALSE;
}
#endif
void STREAM_blocking(STREAM *stream, bool block)
{

View File

@ -34,7 +34,6 @@ typedef
int (*open)(union STREAM *stream, const char *path, int mode, void *data);
int (*close)(union STREAM *stream);
int (*read)(union STREAM *stream, char *buffer, int len);
int (*getchar)(union STREAM *stream, char *buffer);
int (*write)(union STREAM *stream, char *buffer, int len);
int (*seek)(union STREAM *stream, int64_t pos, int whence);
int (*tell)(union STREAM *stream, int64_t *pos);
@ -165,7 +164,7 @@ enum {
ST_EOL_MAC = 2
};
EXTERN int STREAM_eff_read;
//EXTERN int STREAM_eff_read;
#ifndef __STREAM_IMPL_C
@ -186,7 +185,6 @@ STREAM_CLASS stream = \
(void *)stream_open, \
(void *)stream_close, \
(void *)stream_read, \
(void *)stream_getchar, \
(void *)stream_write, \
(void *)stream_seek, \
(void *)stream_tell, \
@ -212,7 +210,7 @@ char *STREAM_line_input(STREAM *stream, char *escape);
char *STREAM_input(STREAM *stream);
int64_t STREAM_tell(STREAM *stream);
void STREAM_seek(STREAM *stream, int64_t pos, int whence);
void STREAM_read(STREAM *stream, void *addr, int len);
int STREAM_read(STREAM *stream, void *addr, int len);
int STREAM_read_max(STREAM *stream, void *addr, int len);
bool STREAM_read_ahead(STREAM *stream);
//char STREAM_getchar(STREAM *stream);
@ -231,8 +229,8 @@ void STREAM_load(const char *path, char **buffer, int *len);
bool STREAM_map(const char *path, char **paddr, int *plen);
void STREAM_unmap(char *addr, int len);
int STREAM_read_direct(int fd, char *buffer, int len);
int STREAM_write_direct(int fd, char *buffer, int len);
//int STREAM_read_direct(int fd, char *buffer, int len);
//int STREAM_write_direct(int fd, char *buffer, int len);
bool STREAM_lock(STREAM *stream);

View File

@ -79,31 +79,25 @@ static int stream_close(STREAM *stream)
static int stream_read(STREAM *stream, char *buffer, int len)
{
bool strip = FALSE;
int max;
max = stream->arch.size - stream->arch.pos;
if (len > max)
{
strip = TRUE;
len = max;
errno = 0;
}
if (ARCHIVE_read(stream->arch.arch, stream->arch.start + stream->arch.pos, buffer, len))
strip = TRUE;
ARCHIVE_read(stream->arch.arch, stream->arch.start + stream->arch.pos, buffer, len);
stream->arch.pos += len;
STREAM_eff_read = len;
return strip;
return len;
}
static int stream_write(STREAM *stream, char *buffer, int len)
{
return TRUE;
return -1;
}
@ -136,9 +130,6 @@ static int stream_seek(STREAM *stream, int64_t pos, int whence)
return FALSE;
}
#define stream_getchar NULL
static int stream_tell(STREAM *stream, int64_t *pos)
{
*pos = stream->arch.pos;

View File

@ -100,9 +100,18 @@ static int stream_close(STREAM *stream)
static int stream_read(STREAM *stream, char *buffer, int len)
{
size_t eff_read;
size_t len_read;
int eff;
eff = (int)fread(buffer, 1, len, FD);
if (eff < len)
{
if (ferror(FD) == 0)
errno = 0;
}
return eff;
/*
while (len > 0)
{
len_read = Min(len, MAX_IO);
@ -128,18 +137,7 @@ static int stream_read(STREAM *stream, char *buffer, int len)
}
return FALSE;
}
static int stream_getchar(STREAM *stream, char *buffer)
{
int c = getc(FD);
if (c == EOF)
return TRUE;
*buffer = (char)c;
return FALSE;
*/
}
@ -151,10 +149,9 @@ static int stream_flush(STREAM *stream)
static int stream_write(STREAM *stream, char *buffer, int len)
{
size_t eff_write;
size_t len_write;
return fwrite(buffer, 1, len, FD);
while (len > 0)
/*while (len > 0)
{
len_write = Min(len, MAX_IO);
eff_write = fwrite(buffer, 1, len_write, FD);
@ -172,7 +169,7 @@ static int stream_write(STREAM *stream, char *buffer, int len)
if (EXEC_debug)
return stream_flush(stream);
else
return FALSE;
return FALSE;*/
}

View File

@ -139,15 +139,12 @@ static int stream_close(STREAM *stream)
static int stream_read(STREAM *stream, char *buffer, int len)
{
return STREAM_read_direct(FD, buffer, len);
return read(FD, buffer, len);
}
#define stream_getchar NULL
static int stream_write(STREAM *stream, char *buffer, int len)
{
return STREAM_write_direct(FD, buffer, len);
return write(FD, buffer, len);
}

View File

@ -85,18 +85,15 @@ static int stream_read(STREAM *stream, char *buffer, int len)
if (CHECK_got_error())
{
errno = EIO;
return TRUE;
return -1;
}
else
{
stream->memory.pos += len;
STREAM_eff_read = len;
return FALSE;
return len;
}
}
#define stream_getchar NULL
static int stream_write(STREAM *stream, char *buffer, int len)
{
if ((stream->common.mode & ST_WRITE) == 0)
@ -112,12 +109,12 @@ static int stream_write(STREAM *stream, char *buffer, int len)
if (CHECK_got_error())
{
errno = EIO;
return TRUE;
return -1;
}
else
{
stream->memory.pos += len;
return FALSE;
return len;
}
}

View File

@ -84,15 +84,13 @@ static int stream_close(STREAM *stream)
static int stream_read(STREAM *stream, char *buffer, int len)
{
return STREAM_read_direct(FD, buffer, len);
return read(FD, buffer, len);
}
#define stream_getchar NULL
static int stream_write(STREAM *stream, char *buffer, int len)
{
return STREAM_write_direct(FD, buffer, len);
return write(FD, buffer, len);
}

View File

@ -68,14 +68,12 @@ static int stream_close(STREAM *stream)
static int stream_read(STREAM *stream, char *buffer, int len)
{
return STREAM_read_direct(FDR, buffer, len);
return read(FDR, buffer, len);
}
#define stream_getchar NULL
static int stream_write(STREAM *stream, char *buffer, int len)
{
return STREAM_write_direct(FDW, buffer, len);
return write(FDW, buffer, len);
}

View File

@ -62,14 +62,12 @@ static int stream_close(STREAM *stream)
static int stream_read(STREAM *stream, char *buffer, int len)
{
bool strip = FALSE;
int max;
max = stream->string.size - stream->string.pos;
if (len > max)
{
strip = TRUE;
len = max;
errno = 0;
}
@ -78,13 +76,9 @@ static int stream_read(STREAM *stream, char *buffer, int len)
memcpy(buffer, stream->string.buffer + stream->string.pos, len);
stream->string.pos += len;
STREAM_eff_read = len;
return strip;
return len;
}
#define stream_getchar NULL
static int stream_write(STREAM *stream, char *buffer, int len)
{
if ((stream->common.mode & ST_WRITE) == 0)
@ -95,7 +89,7 @@ static int stream_write(STREAM *stream, char *buffer, int len)
stream->string.size += len;
stream->string.pos = stream->string.size;
return FALSE;
return len;
}

View File

@ -454,6 +454,7 @@ void SUBR_read(ushort code)
{
STREAM *stream;
int len = 0;
int eff;
SUBR_ENTER_PARAM(2);
@ -482,19 +483,19 @@ void SUBR_read(ushort code)
RETURN->_string.start = 0;
RETURN->_string.len = len;
STREAM_read_max(stream, RETURN->_string.addr, len);
eff = STREAM_read_max(stream, RETURN->_string.addr, len);
if (STREAM_eff_read == 0)
if (eff == 0)
{
RETURN->type = T_NULL;
STRING_free(&RETURN->_string.addr);
}
else
{
if (STREAM_eff_read < len)
if (eff < len)
{
RETURN->_string.addr = STRING_extend(RETURN->_string.addr, STREAM_eff_read);
RETURN->_string.len = STREAM_eff_read;
RETURN->_string.addr = STRING_extend(RETURN->_string.addr, eff);
RETURN->_string.len = eff;
}
STRING_extend_end(RETURN->_string.addr);
}

View File

@ -1142,7 +1142,6 @@ typedef
struct {
GB_STREAM *(*Get)(void *object);
void (*SetBytesRead)(GB_STREAM *stream, int length);
void (*SetSwapping)(GB_STREAM *stream, int swap);
void (*SetAvailableNow)(GB_STREAM *stream, int available_now);
bool (*Block)(GB_STREAM *stream, int block);

View File

@ -357,13 +357,6 @@ bool ARCH_find(ARCH *arch, const char *path, int len_path, ARCH_FIND *find)
bool ARCH_read(ARCH *arch, int pos, void *buffer, int len)
{
/*if (lseek(arch->fd, pos, SEEK_SET) < 0)
return TRUE;
if (read(arch->fd, buffer, len) != len)
return TRUE;*/
memcpy(buffer, &arch->addr[pos], len);
return FALSE;
}