diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2022-12-08 00:26:46 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2022-12-10 11:58:14 -0500 |
commit | c412bb59ce1488347a9f4d6d55e42de3f8567956 (patch) | |
tree | 0be4efd67374e6856abb35252847c5166a710629 /src/fdlog_maint.c | |
parent | 0318ef7b64768cc937ee944da445248376793cd3 (diff) | |
download | lighttpd-git-c412bb59ce1488347a9f4d6d55e42de3f8567956.tar.gz |
[multiple] employ ck_realloc_u32() shared code
employ ck_realloc_u32() shared code to slightly reduce code size
Diffstat (limited to 'src/fdlog_maint.c')
-rw-r--r-- | src/fdlog_maint.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/fdlog_maint.c b/src/fdlog_maint.c index 9f5b9832..0865cf0e 100644 --- a/src/fdlog_maint.c +++ b/src/fdlog_maint.c @@ -29,7 +29,6 @@ struct fdlog_files_t { fdlog_st **ptr; uint32_t used; - uint32_t size; }; static struct fdlog_files_t fdlog_files; @@ -48,7 +47,6 @@ typedef struct fdlog_pipe { struct fdlog_pipes_t { fdlog_pipe *ptr; uint32_t used; - uint32_t size; }; static struct fdlog_pipes_t fdlog_pipes; @@ -136,7 +134,6 @@ fdlog_pipes_close (fdlog_st * const retain) free(fdlog_pipes.ptr); fdlog_pipes.ptr = NULL; fdlog_pipes.used = 0; - fdlog_pipes.size = 0; } @@ -166,12 +163,9 @@ fdlog_pipe_serrh (const int fd) static fdlog_st * fdlog_pipe_init (const char * const fn, const int fds[2], const pid_t pid) { - if (fdlog_pipes.used == fdlog_pipes.size) { - fdlog_pipes.size += 4; - fdlog_pipes.ptr = - realloc(fdlog_pipes.ptr, fdlog_pipes.size * sizeof(fdlog_pipe)); - force_assert(fdlog_pipes.ptr); - } + if (!(fdlog_pipes.used & (4-1))) + ck_realloc_u32((void **)&fdlog_pipes.ptr, fdlog_pipes.used, + 4, sizeof(*fdlog_pipes.ptr)); fdlog_pipe * const fdp = fdlog_pipes.ptr + fdlog_pipes.used++; fdp->fd = fds[0]; fdp->pid = pid; @@ -212,12 +206,9 @@ fdlog_pipe_open (const char * const fn) static fdlog_st * fdlog_file_init (const char * const fn, const int fd) { - if (fdlog_files.used == fdlog_files.size) { - fdlog_files.size += 4; - fdlog_files.ptr = - realloc(fdlog_files.ptr, fdlog_files.size * sizeof(fdlog_st *)); - force_assert(fdlog_files.ptr); - } + if (!(fdlog_files.used & (4-1))) + ck_realloc_u32((void **)&fdlog_files.ptr, fdlog_files.used, + 4, sizeof(*fdlog_files.ptr)); return (fdlog_files.ptr[fdlog_files.used++] = fdlog_init(fn,fd,FDLOG_FILE)); } @@ -311,7 +302,6 @@ fdlog_files_close (fdlog_st * const retain) free(fdlog_files.ptr); fdlog_files.ptr = NULL; fdlog_files.used = 0; - fdlog_files.size = 0; } |