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); return fputs (s, mio->impl.file.fp);
} }
G_GNUC_PRINTF (2, 0)
static gint static gint
file_vprintf (MIO *mio, file_vprintf (MIO *mio,
const gchar *format, const gchar *format,

View File

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

View File

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