Minor corrections of the night.

This commit is contained in:
Thomas Touhey 2018-04-24 04:11:49 +02:00
parent d6c3d39858
commit e1705b75d6
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
8 changed files with 50 additions and 9 deletions

View File

@ -89,10 +89,16 @@ typedef unsigned long casio_uint32_t;
/* printf thing for `size_t` */
# if defined(_WIN64)
# define CASIO_PRIuSIZE "l64u"
# define CASIO_PRIxSIZE "l64x"
# define CASIO_PRIXSIZE "l64X"
# elif defined(_WIN32)
# define CASIO_PRIuSIZE "u"
# define CASIO_PRIxSIZE "x"
# define CASIO_PRIXSIZE "X"
# else
# define CASIO_PRIuSIZE "zu"
# define CASIO_PRIxSIZE "zx"
# define CASIO_PRIXSIZE "zX"
# endif
CASIO_END_NAMESPACE

View File

@ -79,6 +79,7 @@ int CASIO_EXPORT casio_decode_std_mcs(casio_file_t **h,
/* Get the part header. */
GDREAD(fhd)
datalength = be32toh(fhd.casio_mcs_fileheader_datalength);
/* Log info about the subpart. */

View File

@ -38,6 +38,8 @@ int CASIO_EXPORT casio_posix_make(void *cookie, const char *path,
mode_t mode;
va_list ap;
(void)cookie;
/* Start the variable argument list. */
va_start(ap, info);

View File

@ -91,6 +91,7 @@ int CASIO_EXPORT casio_make_posix_path(void *cookie,
void CASIO_EXPORT casio_free_posix_path(void *cookie, void *nat)
{
(void)cookie;
casio_free(nat);
}

View File

@ -37,12 +37,16 @@ int CASIO_EXPORT casio_make_sevenfs_path(sevenfs_cookie_t *cookie,
char *data; int off;
casio_pathnode_t *node;
(void)cookie;
/* Check the device. */
if (!memcmp(array->casio_path_device, "fls0", 4)
|| !memcmp(array->casio_path_device, "crd0", 4))
return (casio_error_invalid);
/* Get directory name and file name. */
if (!array->casio_path_nodes)
return (casio_error_invalid);
node = array->casio_path_nodes;
@ -58,6 +62,7 @@ int CASIO_EXPORT casio_make_sevenfs_path(sevenfs_cookie_t *cookie,
}
if (node->casio_pathnode_next) {
/* too deep! */
return (casio_error_invalid);
}
filesz = node->casio_pathnode_size + 1;
@ -65,11 +70,13 @@ int CASIO_EXPORT casio_make_sevenfs_path(sevenfs_cookie_t *cookie,
filename = (const char*)node->casio_pathnode_name;
/* Make the node. */
*ppath = casio_alloc(offsetof(sevenfs_path_t, sevenfs_path_data)
+ 4 + dirsz + filesz, 1);
path = *ppath; if (!path) return (casio_error_alloc);
/* Copy the data into the node. */
data = path->sevenfs_path_data; off = 0;
if (dirname) {
memcpy(data, dirname, dirsz - 1);
@ -87,6 +94,7 @@ int CASIO_EXPORT casio_make_sevenfs_path(sevenfs_cookie_t *cookie,
path->sevenfs_path_dev = off;
/* No error! */
return (0);
}

View File

@ -137,12 +137,15 @@ int CASIO_EXPORT casio_decode_mcsfile(casio_mcsfile_t **handle,
mcs_decode_func_t *decode;
casio_mcshead_t head;
/* check that the head is there, correct it */
if (!mcshead) return (casio_error_op);
/* Check that the head is there, correct it. */
if (!mcshead)
return (casio_error_op);
memcpy(&head, mcshead, sizeof(casio_mcshead_t));
casio_correct_mcshead(&head, 0);
/* look for the decoding function */
/* Look for the decoding function. */
decode = lookup_mcsfile_decode(head.casio_mcshead_type);
if (!decode) {
msg((ll_error,
@ -151,7 +154,8 @@ int CASIO_EXPORT casio_decode_mcsfile(casio_mcsfile_t **handle,
goto notparsing;
}
/* decode */
/* Decode. */
if (!head.casio_mcshead_size)
err = (*decode)(handle, buffer, &head);
else {
@ -159,22 +163,27 @@ int CASIO_EXPORT casio_decode_mcsfile(casio_mcsfile_t **handle,
int alterr;
/* Open the limited buffer. */
msg((ll_info, "Making a limited buffer out of the buffer."));
msg((ll_info, "Making a limited buffer of "
"0x%" CASIO_PRIXSIZE " bytes", head.casio_mcshead_size));
err = casio_open_limited(&lbuf, buffer, head.casio_mcshead_size);
if (err) goto fail;
/* Call the decode error. */
msg((ll_info, "Decoding the file with the specific function."));
err = (*decode)(handle, lbuf, &head);
alterr = casio_empty_limited(lbuf);
casio_close(lbuf);
/* Check the error. */
if (!err && alterr)
err = alterr;
}
/* oh yeah, and go away. */
/* Oh yeah, and go away. */
if (err) goto fail;
return (0);

View File

@ -37,12 +37,23 @@ typedef struct {
* @return the error code (0 if ok).
*/
CASIO_LOCAL int casio_limited_read(void *vcookie, unsigned char *dest, size_t size)
CASIO_LOCAL int casio_limited_read(void *vcookie, unsigned char *dest,
size_t size)
{
int err; limited_cookie_t *cookie = (void*)vcookie;
size_t left;
if (size > cookie->_left) {
/* First, skip the required bytes. */
left = cookie->_left;
cookie->_left = 0;
if ((err = casio_skip(cookie->_stream, left)))
return (err);
/* Once the skip is done successfully, we return that we
* have an EOF. */
return (casio_error_eof);
}
@ -93,15 +104,18 @@ int CASIO_EXPORT casio_open_limited(casio_stream_t **stream,
/* FIXME: check original stream */
/* allocate the cookie */
cookie = casio_alloc(1, sizeof(limited_cookie_t));
if (!cookie) return (casio_error_alloc);
/* fill the cookie */
/* Fill the cookie. */
memcpy(cookie->_magic, "LIMITED\x7F", 8);
cookie->_stream = original;
cookie->_left = size;
/* initialize da stream */
/* Initialize da stream. */
return (casio_open_stream(stream,
casio_get_openmode(original) & CASIO_OPENMODE_READ,
cookie, &casio_limited_callbacks, 0));