diff options
author | Christophe Fergeau <teuf@gnome.org> | 2005-11-02 19:11:29 +0000 |
---|---|---|
committer | Christophe Fergeau <teuf@gnome.org> | 2005-11-02 19:11:29 +0000 |
commit | 4d061c1b6191e7d4071240b36822c75a8550bf0f (patch) | |
tree | 8877bd9574f81664f12c22ed62b5dc2f730d2864 /src | |
parent | fd77fc4d19f8fe25dcd1e2a7f8b1f950b2b89c25 (diff) | |
download | libgpod-4d061c1b6191e7d4071240b36822c75a8550bf0f.tar.gz libgpod-4d061c1b6191e7d4071240b36822c75a8550bf0f.tar.xz libgpod-4d061c1b6191e7d4071240b36822c75a8550bf0f.zip |
2005-11-02 Christophe Fergeau <teuf@gnome.org>
* configure.ac:
* src/db-artwork-writer.c: (ipod_buffer_grow_mapping),
(ipod_buffer_maybe_grow): added fallback code for systems not having
mremap (pretty much all non-linux systems actually)
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1136 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src')
-rw-r--r-- | src/db-artwork-writer.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c index bfe3f62..d96b6fa 100644 --- a/src/db-artwork-writer.c +++ b/src/db-artwork-writer.c @@ -74,6 +74,7 @@ ipod_buffer_destroy (iPodBuffer *buffer) g_free (buffer); } + static void * ipod_buffer_get_pointer (iPodBuffer *buffer) { @@ -102,6 +103,32 @@ ipod_buffer_grow_file (struct iPodMmapBuffer *mmap_buf, off_t new_size) return 0; } + +static void * +ipod_buffer_grow_mapping (iPodBuffer *buffer, size_t size) +{ + void *new_address; +#ifdef HAVE_MREMAP + + new_address = mremap (buffer->mmap->mmap_area, buffer->mmap->size, + buffer->mmap->size + size, 0); +#else + munmap (buffer->mmap->mmap_area, buffer->mmap->size); + new_address = mmap (buffer->mmap->mmap_area, buffer->mmap->size + size, + PROT_READ | PROT_WRITE, MAP_SHARED, + buffer->mmap->fd, 0); +#endif + /* Don't allow libc to move the current mapping since this would + * force us to be very careful wrt pointers in the rest of the code + */ + if (new_address != buffer->mmap->mmap_area) { + return MAP_FAILED; + } + + return new_address; +} + + static int ipod_buffer_maybe_grow (iPodBuffer *buffer, off_t offset) { @@ -111,15 +138,12 @@ ipod_buffer_maybe_grow (iPodBuffer *buffer, off_t offset) return 0; } - /* Don't allow libc to move the current mapping since this would - * force us to be very careful wrt pointers in the rest of the code - */ - new_address = mremap (buffer->mmap->mmap_area, buffer->mmap->size, - buffer->mmap->size + IPOD_MMAP_SIZE, 0); + new_address = ipod_buffer_grow_mapping (buffer, IPOD_MMAP_SIZE); if (new_address == MAP_FAILED) { - g_print ("Failed to mremap buffer: %s\n", strerror (errno)); + g_print ("Failed to mremap buffer\n"); return -1; } + if (ipod_buffer_grow_file (buffer->mmap, buffer->mmap->size + IPOD_MMAP_SIZE) != 0) { return -1; |