Merge branch 'mio/update'

Manually import some upstream MIO changes.
This commit is contained in:
Colomban Wendling 2015-10-25 16:09:21 +01:00
commit 4335804d23
3 changed files with 24 additions and 22 deletions

View File

@ -92,6 +92,7 @@ file_puts (MIO *mio,
return fputs (s, mio->impl.file.fp);
}
G_GNUC_PRINTF (2, 0)
static gint
file_vprintf (MIO *mio,
const gchar *format,

View File

@ -73,34 +73,34 @@ mem_free (MIO *mio)
static gsize
mem_read (MIO *mio,
void *ptr,
void *ptr_,
gsize size,
gsize nmemb)
{
gsize n_read = 0;
if (size != 0 && nmemb != 0) {
if (mio->impl.mem.ungetch != EOF) {
*((guchar *)ptr) = (guchar)mio->impl.mem.ungetch;
mio->impl.mem.ungetch = EOF;
mio->impl.mem.pos++;
if (size == 1) {
n_read++;
} else if (mio->impl.mem.pos + (size - 1) <= mio->impl.mem.size) {
memcpy (&(((guchar *)ptr)[1]),
&mio->impl.mem.buf[mio->impl.mem.pos], size - 1);
mio->impl.mem.pos += size - 1;
n_read++;
}
gsize size_avail = mio->impl.mem.size - mio->impl.mem.pos;
gsize copy_bytes = size * nmemb;
guchar *ptr = ptr_;
if (size_avail < copy_bytes) {
copy_bytes = size_avail;
}
for (; n_read < nmemb; n_read++) {
if (mio->impl.mem.pos + size > mio->impl.mem.size) {
break;
} else {
memcpy (&(((guchar *)ptr)[n_read * size]),
&mio->impl.mem.buf[mio->impl.mem.pos], size);
mio->impl.mem.pos += size;
if (copy_bytes > 0) {
n_read = copy_bytes / size;
if (mio->impl.mem.ungetch != EOF) {
*ptr = (guchar) mio->impl.mem.ungetch;
mio->impl.mem.ungetch = EOF;
copy_bytes--;
mio->impl.mem.pos++;
ptr++;
}
memcpy (ptr, &mio->impl.mem.buf[mio->impl.mem.pos], copy_bytes);
mio->impl.mem.pos += copy_bytes;
}
if (mio->impl.mem.pos >= mio->impl.mem.size) {
mio->impl.mem.eof = TRUE;
@ -241,6 +241,7 @@ mem_puts (MIO *mio,
return rv;
}
G_GNUC_PRINTF (2, 0)
static gint
mem_vprintf (MIO *mio,
const gchar *format,

View File

@ -145,7 +145,7 @@ struct _MIO {
const gchar *s);
gint (*v_vprintf) (MIO *mio,
const gchar *format,
va_list ap);
va_list ap) G_GNUC_PRINTF (2, 0);
void (*v_clearerr) (MIO *mio);
gint (*v_eof) (MIO *mio);
gint (*v_error) (MIO *mio);
@ -198,7 +198,7 @@ gint mio_puts (MIO *mio,
gint mio_vprintf (MIO *mio,
const gchar *format,
va_list ap);
va_list ap) G_GNUC_PRINTF (2, 0);
gint mio_printf (MIO *mio,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);