Small fixies in p7os and changing error convention for stream read (write tomorow)

This commit is contained in:
Lailouezzz 2020-01-01 23:39:56 +01:00
parent 54ec2ce352
commit 842122643b
Signed by: Lailouezzz
GPG Key ID: 03FCE8A99EF8482C
22 changed files with 185 additions and 145 deletions

View File

@ -100,8 +100,8 @@ typedef int casio_stream_setattrs_t
typedef int casio_stream_settm_t
OF((void *, const casio_timeouts_t *));
typedef int casio_stream_read_t
OF((void *, unsigned char *, size_t *));
typedef size_t casio_stream_read_t
OF((void *, unsigned char *, size_t));
typedef int casio_stream_write_t
OF((void *, const unsigned char *, size_t));
typedef int casio_stream_seek_t
@ -359,9 +359,9 @@ CASIO_EXTERN int CASIO_EXPORT casio_get_lasterr
/* Read and write data from and to a stream. */
CASIO_EXTERN int CASIO_EXPORT casio_read
CASIO_EXTERN size_t CASIO_EXPORT casio_read
OF((casio_stream_t *casio__stream,
void *casio__dest, size_t *casio__psize));
void *casio__dest, size_t casio__size));
CASIO_EXTERN int CASIO_EXPORT casio_write
OF((casio_stream_t *casio__stream,
const void *casio__data, size_t casio__size));

View File

@ -28,16 +28,15 @@
/* Read from a stream. */
# define READ(CASIO__TO, CASIO__SZ) /* normal read */ { \
size_t size = CASIO__SZ; \
int READ_err = casio_read(buffer, (CASIO__TO), &size); \
if (READ_err) return (READ_err); }
# define FREAD(CASIO__TO, CASIO__SZ) /* fail-less read */ \
size_t size = CASIO__SZ; \
err = casio_read(buffer, (CASIO__TO), &size);
# define GREAD(CASIO__TO, CASIO__SZ) /* read with goto fail */ \
size_t size = CASIO__SZ; \
if ((err = casio_read(buffer, (CASIO__TO), &size))) \
goto fail;
int READ_err = casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
if (READ_err == -1) return (errno); }
# define FREAD(CASIO__TO, CASIO__SZ) /* fail-less read */ { \
casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
err = errno; }
# define GREAD(CASIO__TO, CASIO__SZ) /* read with goto fail */ { \
casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
if ((err = errno)) \
goto fail; }
/* Read using size of the object. */

View File

@ -26,6 +26,7 @@
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <errno.h>
# include "utils/endian.h"
# include "log/log.h"

View File

@ -64,8 +64,10 @@ int CASIO_EXPORT casio_seven_send_buffer(casio_link_t *handle,
/* Read the big block. */
toread = min(BUFSIZE, size);
err = casio_read(buffer, buf + 8, &toread);
if (err) return (casio_error_noread);
toread = casio_read(buffer, buf + 8, toread);
if (toread == (size_t)-1) {
return (casio_error_noread);
}
size -= toread;
/* Send each block. */
@ -95,7 +97,7 @@ int CASIO_EXPORT casio_seven_send_buffer(casio_link_t *handle,
/* Unshift. */
if (handle->casio_link_flags & casio_linkflag_shifted)
err = casio_seven_unshift(handle);
return (0);
fail:
return (err);
}

View File

@ -32,7 +32,6 @@ typedef struct {
casio_link_progress_t *_disp;
void *_disp_cookie;
unsigned int _id, _total;
unsigned int _totalsize; /* */
unsigned int _lastsize; /* last packet size */
/* buffer management */
@ -52,15 +51,16 @@ typedef struct {
* @arg cookie the cookie.
* @arg data the data to read.
* @arg size the size of the data to read.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
CASIO_LOCAL int casio_seven_data_read(seven_data_cookie_t *cookie,
unsigned char *data, size_t *psize)
CASIO_LOCAL size_t casio_seven_data_read(seven_data_cookie_t *cookie,
unsigned char *data, size_t size)
{
int err; size_t tocopy; size_t size = *psize;
int err; size_t tocopy;
casio_link_t *handle = cookie->_link;
unsigned int lastsize = 0;
size_t copiedsize = 0;
/* Check if the stream is faulty. */
if (cookie->_faulty)
@ -72,14 +72,16 @@ CASIO_LOCAL int casio_seven_data_read(seven_data_cookie_t *cookie,
if (tocopy) {
memcpy(data, &cookie->_current[cookie->_pos], tocopy);
cookie->_pos += tocopy;
data += tocopy; size -= tocopy;
data += tocopy; size -= tocopy; copiedsize += tocopy;
if (!size) return (0);
if (size == 0) return (size);
}
/* Check if we have already finished. */
if (cookie->_total && cookie->_id == cookie->_total)
return (casio_error_ieof);
if (cookie->_total && cookie->_id == cookie->_total) {
errno = casio_error_eof;
return (-1);
}
/* Receive packets. */
while (size) {
@ -88,8 +90,7 @@ CASIO_LOCAL int casio_seven_data_read(seven_data_cookie_t *cookie,
if (err) goto fail;
/* If swap roles there is the end of file */
if (response.casio_seven_packet_type == casio_seven_type_swp) {
*psize = lastsize;
return (casio_error_ieof);
return copiedsize;
}
if (response.casio_seven_packet_type != casio_seven_type_data) {
msg((ll_error, "Packet wasn't a data packet, wtf?"));
@ -117,9 +118,10 @@ CASIO_LOCAL int casio_seven_data_read(seven_data_cookie_t *cookie,
/* Increment and copy. */
lastsize = response.casio_seven_packet_data_size;
copiedsize += lastsize;
if (size >= lastsize) {
memcpy(data, response.casio_seven_packet_data, lastsize);
data += lastsize; size -= lastsize; cookie->_totalsize += lastsize;
data += lastsize; size -= lastsize;
continue;
}
@ -128,15 +130,15 @@ CASIO_LOCAL int casio_seven_data_read(seven_data_cookie_t *cookie,
memcpy(data, response.casio_seven_packet_data, size);
memcpy(&cookie->_current[size],
&response.casio_seven_packet_data[size], lastsize - size);
cookie->_totalsize += lastsize;
return (0);
return copiedsize;
}
return (0);
return copiedsize;
fail:
/* XXX: tell the distant device we have a problem? */
cookie->_faulty = 1;
return (err);
errno = err;
return (-1);
}
/**
@ -348,7 +350,6 @@ int CASIO_EXPORT casio_seven_open_data_stream(casio_stream_t **stream,
cookie->_id = 1;
cookie->_total = (unsigned int)(size / BUFSIZE) + !!cookie->_lastsize;
cookie->_lastsize = (unsigned int)(size % BUFSIZE);
cookie->_totalsize = size;
if (!cookie->_lastsize) cookie->_lastsize = BUFSIZE;
} else {
msg((ll_info, "The data stream is a read one."));
@ -358,7 +359,6 @@ int CASIO_EXPORT casio_seven_open_data_stream(casio_stream_t **stream,
cookie->_id = 0;
cookie->_total = 0;
cookie->_lastsize = 0;
cookie->_totalsize = size;
}
/* initialize the stream */

View File

@ -175,10 +175,9 @@ CASIO_LOCAL const char *gettermstring(casio_seven_term_t code)
#define buffer handle->casio_link_recv_buffer
#define COMPLETE_PACKET(N) { \
size_t size##__LINE__ = (size_t)N; \
int COMP_PACKET_err = casio_read(handle->casio_link_stream, \
&buffer[received], &size##__LINE__); \
received += size##__LINE__; if (COMP_PACKET_err) return (COMP_PACKET_err); }
&buffer[received], (size_t)N); \
received += COMP_PACKET_err; if (COMP_PACKET_err == -1) return (errno); }
CASIO_LOCAL int casio_seven_decode(casio_link_t *handle, int scralign)
{

View File

@ -83,24 +83,27 @@ typedef struct {
* Read and write from the stream.
* --- */
CASIO_LOCAL int seven_scsi_read(seven_scsi_cookie_t *cookie,
unsigned char *buffer, size_t *size)
CASIO_LOCAL size_t seven_scsi_read(seven_scsi_cookie_t *cookie,
unsigned char *buffer, size_t size)
{
casio_scsi_t scsi; int err;
size_t copiedsize = 0;
/* Empty what's already in the buffer. */
if (cookie->left) {
if (cookie->left >= *size) {
memcpy(buffer, cookie->ptr, *size);
cookie->ptr += *size;
cookie->left -= *size;
return (0);
if (cookie->left >= size) {
memcpy(buffer, cookie->ptr, size);
cookie->ptr += size;
cookie->left -= size;
copiedsize += cookie->left;
return copiedsize;
}
memcpy(buffer, cookie->ptr, cookie->left);
buffer += cookie->left;
*size -= cookie->left;
size -= cookie->left;
copiedsize += cookie->left;
reset_cookie(cookie);
}
@ -125,8 +128,10 @@ CASIO_LOCAL int seven_scsi_read(seven_scsi_cookie_t *cookie,
scsi.casio_scsi_data = poll_data;
scsi.casio_scsi_data_len = 16;
if ((err = casio_scsi_request(cookie->stream, &scsi)))
return (err);
if ((err = casio_scsi_request(cookie->stream, &scsi))) {
errno = err;
return (-1);
}
mem((ll_info, poll_data, 16));
@ -151,14 +156,14 @@ CASIO_LOCAL int seven_scsi_read(seven_scsi_cookie_t *cookie,
* We could also check that `avail < 0x10000` because we need to
* express it later, but it is imposed by the source format. */
if (avail > *size && *size <= cookie->size) {
if (avail > size && size <= cookie->size) {
to = cookie->ptr;
if (avail > cookie->size)
avail = cookie->size;
} else {
to = buffer;
if (avail > *size)
avail = *size;
if (avail > size)
avail = size;
}
/* Actually get the data. */
@ -176,24 +181,27 @@ CASIO_LOCAL int seven_scsi_read(seven_scsi_cookie_t *cookie,
scsi.casio_scsi_data = cookie->ptr;
scsi.casio_scsi_data_len = avail;
if ((err = casio_scsi_request(cookie->stream, &scsi)))
return (err);
if ((err = casio_scsi_request(cookie->stream, &scsi))) {
errno = err;
return (-1);
}
}
if (to == buffer) {
buffer += avail;
*size -= avail;
size -= avail;
} else {
cookie->left = avail;
memcpy(buffer, cookie->ptr, *size);
cookie->ptr += *size;
cookie->left -= *size;
*size = 0;
memcpy(buffer, cookie->ptr, size);
cookie->ptr += size;
cookie->left -= size;
copiedsize += size;
size = 0;
}
} while (*size);
} while (size);
return (0);
return copiedsize;
}
CASIO_LOCAL int seven_scsi_write(seven_scsi_cookie_t *cookie,

View File

@ -26,20 +26,15 @@
/* Read from a stream. */
/* FIXME : size_t size##__LINE__ = CASIO__SZ;
* Replace this by other thing that is more futur proof
*/
# define READ(CASIO__TO, CASIO__SZ) /* normal read */ { \
size_t size##__LINE__ = CASIO__SZ; \
int READ_err = casio_read(buffer, (CASIO__TO), &size##__LINE__); \
if (READ_err) return (READ_err); }
int READ_err = casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
if (READ_err == -1) return (errno); }
# define FREAD(CASIO__TO, CASIO__SZ) /* fail-less read */ { \
size_t size##__LINE__ = CASIO__SZ; \
err = casio_read(buffer, (CASIO__TO), &size##__LINE__); }
casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
err = errno; }
# define GREAD(CASIO__TO, CASIO__SZ) /* read with goto fail */ { \
size_t size##__LINE__ = CASIO__SZ; \
if ((err = casio_read(buffer, (CASIO__TO), &size##__LINE__))) \
casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
if ((err = errno)) \
goto fail; }
/* Read using size of the object. */

View File

@ -38,24 +38,26 @@ struct thecookie {
* @arg cookie the cookie.
* @arg data the data pointer.
* @arg size the data size.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
CASIO_LOCAL int csum32_read(struct thecookie *cookie,
unsigned char *dest, size_t *psize)
CASIO_LOCAL size_t csum32_read(struct thecookie *cookie,
unsigned char *dest, size_t size)
{
int err;
size_t size = *psize;
/* Make the call. */
err = casio_read(cookie->_stream, dest, &size);
if (err) return (err);
size = casio_read(cookie->_stream, dest, size);
if (size == (size_t)-1) {
errno = errno;
return (-1);
}
/* Make the checksum. */
*cookie->_checksum = casio_checksum32(dest, size, *cookie->_checksum);
return (0);
return size;
}
/**

View File

@ -46,14 +46,14 @@ typedef struct {
* @arg cookie the cookie.
* @arg data the data pointer
* @arg size the data size.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
CASIO_LOCAL int casio_file_read(file_cookie_t *cookie,
unsigned char *dest, size_t *psize)
CASIO_LOCAL size_t casio_file_read(file_cookie_t *cookie,
unsigned char *dest, size_t size)
{
size_t recv;
size_t size = *psize;
size_t copiedsize = 0;
/* Main receiving loop. */
@ -67,6 +67,7 @@ CASIO_LOCAL int casio_file_read(file_cookie_t *cookie,
dest = (void*)((char*)dest + recv);
size -= recv;
copiedsize += recv;
/* Check the error. */
@ -91,7 +92,8 @@ CASIO_LOCAL int casio_file_read(file_cookie_t *cookie,
/* End of file. */
msg((ll_error, "encountered an end of file"));
return (casio_error_eof);
errno = casio_error_eof;
return (-1);
case EINTR: /* alarm */
case ETIMEDOUT:
@ -101,21 +103,24 @@ CASIO_LOCAL int casio_file_read(file_cookie_t *cookie,
/* A timeout has occurred. */
msg((ll_error, "timeout received"));
return (casio_error_timeout);
errno = casio_error_timeout;
return (-1);
case ENODEV:
case EPIPE: case ESPIPE:
/* A device error has occured. */
msg((ll_error, "calculator was disconnected"));
return (casio_error_nocalc);
errno = casio_error_nocalc;
return (-1);
default:
msg((ll_fatal, "errno was %d: %s", errno, strerror(errno)));
return (casio_error_unknown);
errno = casio_error_unknown;
return (-1);
}
return (0);
return copiedsize;
}
/**

View File

@ -58,9 +58,9 @@ CASIO_EXTERN int CASIO_EXPORT casio_libusb_settm
/* Character device callbacks. */
CASIO_EXTERN int CASIO_EXPORT casio_libusb_read
CASIO_EXTERN size_t CASIO_EXPORT casio_libusb_read
OF((cookie_libusb_t *casio__cookie,
unsigned char *casio__dest, size_t *casio__psize));
unsigned char *casio__dest, size_t casio__size));
CASIO_EXTERN int CASIO_EXPORT casio_libusb_write
OF((cookie_libusb_t *casio__cookie,
const unsigned char *casio__data, size_t casio__size));

View File

@ -26,15 +26,15 @@
* @arg vcookie the cookie (voided)
* @arg data the data pointer.
* @arg size the data size.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
int CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie,
unsigned char *dest, size_t *psize)
size_t CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie,
unsigned char *dest, size_t size)
{
int libusberr;
size_t tocopy;
size_t size = *psize;
size_t copiedsize = 0;
/* Transmit what's already in the buffer. */
@ -46,6 +46,7 @@ int CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie,
cookie->_start += tocopy;
dest += tocopy;
size -= tocopy;
copiedsize += tocopy;
}
/* Main receiving loop. */
@ -65,15 +66,18 @@ int CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie,
case LIBUSB_ERROR_NO_DEVICE:
case LIBUSB_ERROR_IO:
msg((ll_error, "The calculator is not here anymore :("));
return (casio_error_nocalc);
errno = casio_error_nocalc;
return (-1);
case LIBUSB_ERROR_TIMEOUT:
return (casio_error_timeout);
errno = casio_error_timeout;
return (-1);
default:
msg((ll_fatal, "libusb error was %d: %s", libusberr,
libusb_strerror(libusberr)));
return (casio_error_unknown);
errno = casio_error_unknown;
return (-1);
}
/* Get the current size to copy. */
@ -88,13 +92,17 @@ int CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie,
dest += tocopy;
size -= tocopy;
/* Increment the total copied size */
copiedsize += tocopy;
/* Correct start and end points. */
cookie->_start = tocopy;
cookie->_end = (size_t)recv - 1;
}
return (0);
return copiedsize;
}
#endif

View File

@ -37,35 +37,39 @@ typedef struct {
* @arg vcookie the cookie (uncasted).
* @arg data the data pointer.
* @arg size the data size.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
CASIO_LOCAL int casio_limited_read(void *vcookie, unsigned char *dest,
size_t *psize)
CASIO_LOCAL size_t casio_limited_read(void *vcookie, unsigned char *dest,
size_t size)
{
int err; limited_cookie_t *cookie = (void*)vcookie;
size_t left; size_t size = *psize;
size_t left; size_t copiedsize;
if (size > cookie->_left) {
/* First, skip the required bytes. */
left = cookie->_left;
cookie->_left = 0;
if ((err = casio_skip(cookie->_stream, left)))
return (err);
if ((err = casio_skip(cookie->_stream, left))) {
errno = err;
return (-1);
}
/* Once the skip is done successfully, we return that we
* have an EOF. */
return (casio_error_eof);
errno = casio_error_eof;
return (-1);
}
if ((err = casio_read(cookie->_stream, dest, &size))) {
size = casio_read(cookie->_stream, dest, size);
if (size == (size_t)-1) {
cookie->_left = 0; /* XXX: depends on the error? */
return (err);
errno = errno;
return (-1);
}
cookie->_left -= size;
return (0);
return size;
}
/**

View File

@ -35,25 +35,27 @@ typedef struct {
* @arg vcookie the cookie (uncasted)
* @arg data the data pointer.
* @arg size the data size.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
CASIO_LOCAL int casio_memory_read(void *vcookie, unsigned char *dest, size_t *psize)
CASIO_LOCAL size_t casio_memory_read(void *vcookie, unsigned char *dest, size_t size)
{
memory_cookie_t *cookie = (void*)vcookie;
size_t size = *psize;
if (((size_t)-1 - cookie->_offset) < size) /* overflow */
return (casio_error_read);
if (((size_t)-1 - cookie->_offset) < size) { /* overflow */
errno = casio_error_read;
return (-1);
}
if (cookie->_offset + (casio_off_t)size > cookie->_size) {
cookie->_offset = cookie->_size - 1;
return (casio_error_eof);
errno = casio_error_eof;
return (-1);
}
memcpy(dest, &cookie->_memory[cookie->_offset], size);
cookie->_offset += size;
return (0);
return size;
}
/**

View File

@ -26,14 +26,14 @@
* @arg cookie the cookie.
* @arg data the data pointer.
* @arg size the data size.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
int CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie,
unsigned char *dest, size_t *psize)
size_t CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie,
unsigned char *dest, size_t size)
{
int fd = cookie->_readfd;
size_t size = *psize;
size_t copiedsize = 0;
/* Transmit what's already in the buffer. */
@ -45,6 +45,7 @@ int CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie,
cookie->_start += tocopy;
dest += tocopy;
size -= tocopy;
copiedsize += tocopy;
}
/* Main receiving loop. */
@ -68,7 +69,8 @@ int CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie,
default:
msg((ll_fatal, "error was %d: %s",
errno, strerror(errno)));
return (casio_error_unknown);
errno = casio_error_unknown;
return (-1);
}
/* Get the current size to copy. */
@ -82,13 +84,17 @@ int CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie,
dest += tocopy;
size -= tocopy;
/* Increment total size copied */
copiedsize += tocopy;
/* Correct start and end points. */
cookie->_start = tocopy;
cookie->_end = (size_t)recv - 1;
}
return (0);
return copiedsize;
}
#endif

View File

@ -51,9 +51,9 @@ CASIO_EXTERN int CASIO_EXPORT casio_streams_settm
/* Character device callbacks. */
CASIO_EXTERN int CASIO_EXPORT casio_streams_read
CASIO_EXTERN size_t CASIO_EXPORT casio_streams_read
OF((streams_cookie_t *casio__cookie,
unsigned char *casio__dest, size_t *casio__psize));
unsigned char *casio__dest, size_t casio__size));
CASIO_EXTERN int CASIO_EXPORT casio_streams_write
OF((streams_cookie_t *casio__cookie,
const unsigned char *casio__data, size_t casio__size));

View File

@ -25,32 +25,37 @@
* @arg stream the stream to read from.
* @arg dest the destination buffer.
* @arg size the amount of bytes to read.
* @return the error code (0 if ok).
* @return the size written and -1 if error (error code is in errno).
*/
int CASIO_EXPORT casio_read(casio_stream_t *stream, void *dest, size_t *psize)
size_t CASIO_EXPORT casio_read(casio_stream_t *stream, void *dest, size_t size)
{
int err;
int err = casio_error_ok;
/* check if we can read */
failure(~stream->casio_stream_mode & CASIO_OPENMODE_READ, casio_error_read)
/* read */
if (!(*psize)) return (0);
if (!psize) {
size_t size = -1;
err = (*getcb(stream, read))(stream->casio_stream_cookie, dest, &size);
} else {
err = (*getcb(stream, read))(stream->casio_stream_cookie, dest, psize);
}
if (err && err != casio_error_ieof) {
if (size == 0) return (0);
size = (*getcb(stream, read))(stream->casio_stream_cookie, dest, size);
if (size == (size_t)-1) {
err = errno;
if (err == casio_error_eof) {
msg((ll_info, "Stream reading get to the end (EOF)"));
goto fail;
}
msg((ll_error, "Stream reading failure: %s", casio_strerror(err)));
goto fail;
}
/* move the cursor and return */
stream->casio_stream_offset += *psize;
if(size != 1) {
stream->casio_stream_offset += size;
}
fail:
stream->casio_stream_lasterr = err;
return (err);
errno = err;
return size;
}

View File

@ -63,9 +63,11 @@ int CASIO_EXPORT casio_seek(casio_stream_t *stream, casio_off_t offset,
size_t rd = min(to_skip, 128);
/* Read that much from the stream. */
if ((err = casio_read(stream, buf, &rd)))
size_t readed = casio_read(stream, buf, rd);
if (readed == (size_t)-1) {
err = errno;
goto fail;
}
to_skip -= rd;
} while (to_skip);

View File

@ -316,11 +316,11 @@ int main(int ac, char **av)
size_t size;
do
{
size = sizeof(buffer);
err = casio_read(fileStream, buffer, &size);
size = casio_read(fileStream, buffer, sizeof(buffer));
if(size == (size_t)-1)
err = errno;
if(err == casio_error_eof)
fwrite(buffer, 1, size, file);
if(err == casio_error_ieof)
break;
} while (err == 0);
/* All good so close streams and clear error */

View File

@ -20,6 +20,7 @@
# define MAIN_H
# include <stdio.h>
# include <libcasio.h>
# include <errno.h>
/* Menus */
typedef enum {

View File

@ -60,7 +60,7 @@ struct data_copy_block {
static int send_sector(casio_link_t *handle, casio_stream_t *buffer,
unsigned long addr, unsigned long size)
{
int err, buf_err;
int err;
osdisp_t osdisp_cookie;
/* Sending the data to the Update.Exe's. */
@ -83,7 +83,8 @@ static int send_sector(casio_link_t *handle, casio_stream_t *buffer,
/* Prepare the block. */
block.destination = casio_be32toh(buf);
block.length = casio_be32toh(len);
if ((buf_err = casio_read(buffer, block.data, &len))) {
len = casio_read(buffer, block.data, len);
if (len == (size_t)-1) {
osdisp_interrupt(&osdisp_cookie);
return (casio_error_read);
}

View File

@ -55,7 +55,7 @@ int prepare(args_t *args)
/* Sleep while the software on the calculator sets up the
* communication interface. */
printf("Waiting for the Update.Exe to set up the communication...\n");
casio_sleep(1000);
casio_sleep(3000);
err = 0;
fail: