-#ifdef HAVE_POSIX_MEMALIGN
- return posix_memalign(base, alignment, size) ? NULL : *base;
-#else
-/* Credits go to Michal's padlock patches for this alignment code */
- char *ptr;
-
- ptr = malloc(size + alignment);
- if(ptr == NULL) return NULL;
-
- *base = ptr;
- if(alignment > 1 && ((long)ptr & (alignment - 1))) {
- ptr += alignment - ((long)(ptr) & (alignment - 1));
- }
- return ptr;
-#endif
-}
-
-ssize_t write_blockwise(int fd, int bsize, void *orig_buf, size_t count)
-{
- void *hangover_buf, *hangover_buf_base = NULL;
- void *buf, *buf_base = NULL;
- int r, hangover, solid, alignment;
- ssize_t ret = -1;
-
- if (fd == -1 || !orig_buf || bsize <= 0)
- return -1;
-
- hangover = count % bsize;
- solid = count - hangover;
- alignment = get_alignment(fd);
-
- if ((long)orig_buf & (alignment - 1)) {
- buf = aligned_malloc(&buf_base, count, alignment);
- if (!buf)
- goto out;
- memcpy(buf, orig_buf, count);
- } else
- buf = orig_buf;