Fix Windows compile errors.

This commit is contained in:
Michael R Sweet 2024-03-19 11:22:41 -04:00
parent e676eb35cb
commit 528c89ef86
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
4 changed files with 26 additions and 18 deletions

View File

@ -115,11 +115,11 @@ mxmlElementGetAttr(mxml_node_t *node, // I - Element node
const char * // O - Attribute value const char * // O - Attribute value
mxmlElementGetAttrByIndex( mxmlElementGetAttrByIndex(
mxml_node_t *node, // I - Node mxml_node_t *node, // I - Node
int idx, // I - Attribute index, starting at `0` size_t idx, // I - Attribute index, starting at `0`
const char **name) // O - Attribute name or `NULL` to not return it const char **name) // O - Attribute name or `NULL` to not return it
{ {
if (!node || node->type != MXML_TYPE_ELEMENT || idx < 0 || idx >= node->value.element.num_attrs) if (!node || node->type != MXML_TYPE_ELEMENT || idx >= node->value.element.num_attrs)
return (NULL); return (NULL);
if (name) if (name)

View File

@ -211,10 +211,10 @@ mxmlLoadFilename(
// for example: // for example:
// //
// ```c // ```c
// ssize_t my_io_cb(void *cbdata, void *buffer, size_t bytes) // size_t my_io_cb(void *cbdata, void *buffer, size_t bytes)
// { // {
// ... copy up to "bytes" bytes into buffer ... // ... copy up to "bytes" bytes into buffer ...
// ... return the number of bytes "read" or -1 on error ... // ... return the number of bytes "read" or 0 on error ...
// } // }
// ``` // ```
// //
@ -511,10 +511,10 @@ mxmlSaveFilename(
// example: // example:
// //
// ```c // ```c
// ssize_t my_io_cb(void *cbdata, const void *buffer, size_t bytes) // size_t my_io_cb(void *cbdata, const void *buffer, size_t bytes)
// { // {
// ... write/copy bytes from buffer to the output ... // ... write/copy bytes from buffer to the output ...
// ... return the number of bytes written/copied or -1 on error ... // ... return the number of bytes written/copied or 0 on error ...
// } // }
// ``` // ```
// //
@ -1858,12 +1858,16 @@ mxml_read_cb_fd(int *fd, // I - File descriptor
void *buffer, // I - Buffer void *buffer, // I - Buffer
size_t bytes) // I - Bytes to read size_t bytes) // I - Bytes to read
{ {
#if _WIN32
int rbytes; // Bytes read
rbytes = read(*fd, buffer, bytes);
#else
ssize_t rbytes; // Bytes read ssize_t rbytes; // Bytes read
#if _WIN32
rbytes = read(*fd, buffer, buffer);
#else
while ((rbytes = read(*fd, buffer, bytes)) < 0) while ((rbytes = read(*fd, buffer, bytes)) < 0)
{ {
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
@ -1917,7 +1921,7 @@ mxml_read_cb_string(
sb->bufptr += bytes; sb->bufptr += bytes;
} }
return ((ssize_t)bytes); return (bytes);
} }
@ -2009,12 +2013,16 @@ mxml_io_cb_fd(int *fd, // I - File descriptor
void *buffer, // I - Buffer void *buffer, // I - Buffer
size_t bytes) // I - Bytes to write size_t bytes) // I - Bytes to write
{ {
#if _WIN32
int wbytes; // Bytes written
wbytes = write(*fd, buffer, bytes);
#else
ssize_t wbytes; // Bytes written ssize_t wbytes; // Bytes written
#if _WIN32
wbytes = write(*fd, buffer, bytes);
#else
while ((wbytes = write(*fd, buffer, bytes)) < 0) while ((wbytes = write(*fd, buffer, bytes)) < 0)
{ {
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
@ -2159,7 +2167,7 @@ mxml_write_node(
if (attr->value) if (attr->value)
width += strlen(attr->value) + 3; width += strlen(attr->value) + 3;
if (options && options->wrap > 0 && (col + width) > options->wrap) if (options && options->wrap > 0 && (col + (int)width) > options->wrap)
col = mxml_write_string("\n", io_cb, io_cbdata, /*use_entities*/false, col); col = mxml_write_string("\n", io_cb, io_cbdata, /*use_entities*/false, col);
else else
col = mxml_write_string(" ", io_cb, io_cbdata, /*use_entities*/false, col); col = mxml_write_string(" ", io_cb, io_cbdata, /*use_entities*/false, col);

View File

@ -846,7 +846,7 @@ mxmlRetain(mxml_node_t *node) // I - Node
static void static void
mxml_free(mxml_node_t *node) // I - Node mxml_free(mxml_node_t *node) // I - Node
{ {
int i; // Looping var size_t i; // Looping var
switch (node->type) switch (node->type)

2
mxml.h
View File

@ -141,7 +141,7 @@ extern void mxmlDelete(mxml_node_t *node);
extern void mxmlElementClearAttr(mxml_node_t *node, const char *name); extern void mxmlElementClearAttr(mxml_node_t *node, const char *name);
extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name); extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
extern const char *mxmlElementGetAttrByIndex(mxml_node_t *node, int idx, const char **name); extern const char *mxmlElementGetAttrByIndex(mxml_node_t *node, size_t idx, const char **name);
extern size_t mxmlElementGetAttrCount(mxml_node_t *node); extern size_t mxmlElementGetAttrCount(mxml_node_t *node);
extern void mxmlElementSetAttr(mxml_node_t *node, const char *name, const char *value); extern void mxmlElementSetAttr(mxml_node_t *node, const char *name, const char *value);
extern void mxmlElementSetAttrf(mxml_node_t *node, const char *name, const char *format, ...) MXML_FORMAT(3,4); extern void mxmlElementSetAttrf(mxml_node_t *node, const char *name, const char *format, ...) MXML_FORMAT(3,4);