Fixed a bunch of "warn_unused_result" compiler warnings.
[rsync/rsync.git] / lib / pool_alloc.c
index 6997ecf..5856d59 100644 (file)
@@ -24,10 +24,10 @@ struct alloc_pool
 
 struct pool_extent
 {
 
 struct pool_extent
 {
+       struct pool_extent      *next;
        void                    *start;         /* starting address     */
        size_t                  free;           /* free bytecount       */
        size_t                  bound;          /* trapped free bytes   */
        void                    *start;         /* starting address     */
        size_t                  free;           /* free bytecount       */
        size_t                  bound;          /* trapped free bytes   */
-       struct pool_extent      *next;
 };
 
 struct align_test {
 };
 
 struct align_test {
@@ -101,7 +101,7 @@ pool_destroy(alloc_pool_t p)
        for (cur = pool->extents; cur; cur = next) {
                next = cur->next;
                if (pool->flags & POOL_PREPEND)
        for (cur = pool->extents; cur; cur = next) {
                next = cur->next;
                if (pool->flags & POOL_PREPEND)
-                       free(cur->start - sizeof (struct pool_extent));
+                       free(PTR_ADD(cur->start, -sizeof (struct pool_extent)));
                else {
                        free(cur->start);
                        free(cur);
                else {
                        free(cur->start);
                        free(cur);
@@ -148,7 +148,7 @@ pool_alloc(alloc_pool_t p, size_t len, const char *bomb_msg)
 
                if (pool->flags & POOL_PREPEND) {
                        ext = start;
 
                if (pool->flags & POOL_PREPEND) {
                        ext = start;
-                       start += sizeof (struct pool_extent);
+                       start = PTR_ADD(start, sizeof (struct pool_extent));
                } else if (!(ext = new(struct pool_extent)))
                        goto bomb_out;
                ext->start = start;
                } else if (!(ext = new(struct pool_extent)))
                        goto bomb_out;
                ext->start = start;
@@ -236,7 +236,7 @@ pool_free(alloc_pool_t p, size_t len, void *addr)
                if (cur->free + cur->bound >= pool->size) {
                        prev->next = cur->next;
                        if (pool->flags & POOL_PREPEND)
                if (cur->free + cur->bound >= pool->size) {
                        prev->next = cur->next;
                        if (pool->flags & POOL_PREPEND)
-                               free(cur->start - sizeof (struct pool_extent));
+                               free(PTR_ADD(cur->start, -sizeof (struct pool_extent)));
                        else {
                                free(cur->start);
                                free(cur);
                        else {
                                free(cur->start);
                                free(cur);
@@ -293,7 +293,7 @@ pool_free_old(alloc_pool_t p, void *addr)
        while ((cur = next) != NULL) {
                next = cur->next;
                if (pool->flags & POOL_PREPEND)
        while ((cur = next) != NULL) {
                next = cur->next;
                if (pool->flags & POOL_PREPEND)
-                       free(cur->start - sizeof (struct pool_extent));
+                       free(PTR_ADD(cur->start, -sizeof (struct pool_extent)));
                else {
                        free(cur->start);
                        free(cur);
                else {
                        free(cur->start);
                        free(cur);
@@ -326,24 +326,30 @@ pool_boundary(alloc_pool_t p, size_t len)
 }
 
 #define FDPRINT(label, value) \
 }
 
 #define FDPRINT(label, value) \
-       snprintf(buf, sizeof buf, label, value), \
-       write(fd, buf, strlen(buf))
+       do { \
+               int len = snprintf(buf, sizeof buf, label, value); \
+               if (write(fd, buf, len) != len) \
+                       ret = -1; \
+       } while (0)
 
 #define FDEXTSTAT(ext) \
 
 #define FDEXTSTAT(ext) \
-       snprintf(buf, sizeof buf, "  %12ld  %5ld\n", \
-               (long) ext->free, \
-               (long) ext->bound), \
-       write(fd, buf, strlen(buf))
-
-void
+       do { \
+               int len = snprintf(buf, sizeof buf, "  %12ld  %5ld\n", \
+                                  (long)ext->free, (long)ext->bound); \
+               if (write(fd, buf, len) != len) \
+                       ret = -1; \
+       } while (0)
+
+int
 pool_stats(alloc_pool_t p, int fd, int summarize)
 {
        struct alloc_pool *pool = (struct alloc_pool *) p;
        struct pool_extent *cur;
        char buf[BUFSIZ];
 pool_stats(alloc_pool_t p, int fd, int summarize)
 {
        struct alloc_pool *pool = (struct alloc_pool *) p;
        struct pool_extent *cur;
        char buf[BUFSIZ];
+       int ret = 0;
 
        if (!pool)
 
        if (!pool)
-               return;
+               return ret;
 
        FDPRINT("  Extent size:       %12ld\n", (long)  pool->size);
        FDPRINT("  Alloc quantum:     %12ld\n", (long)  pool->quantum);
 
        FDPRINT("  Extent size:       %12ld\n", (long)  pool->size);
        FDPRINT("  Alloc quantum:     %12ld\n", (long)  pool->quantum);
@@ -355,13 +361,16 @@ pool_stats(alloc_pool_t p, int fd, int summarize)
        FDPRINT("  Bytes freed:       %12.0f\n", (double) pool->b_freed);
 
        if (summarize)
        FDPRINT("  Bytes freed:       %12.0f\n", (double) pool->b_freed);
 
        if (summarize)
-               return;
+               return ret;
 
        if (!pool->extents)
 
        if (!pool->extents)
-               return;
+               return ret;
 
 
-       write(fd, "\n", 1);
+       if (write(fd, "\n", 1) != 1)
+               ret = -1;
 
        for (cur = pool->extents; cur; cur = cur->next)
                FDEXTSTAT(cur);
 
        for (cur = pool->extents; cur; cur = cur->next)
                FDEXTSTAT(cur);
+
+       return ret;
 }
 }