diff options
author | Gluster Ant <bugzilla-bot@gluster.org> | 2018-09-12 17:52:45 +0530 |
---|---|---|
committer | Nigel Babu <nigelb@redhat.com> | 2018-09-12 17:52:45 +0530 |
commit | e16868dede6455cab644805af6fe1ac312775e13 (patch) | |
tree | 15aebdb4fff2d87cf8a72f836816b3aa634da58d /xlators/features/changelog/lib/src/gf-changelog-helpers.c | |
parent | 45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff) |
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4
Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'xlators/features/changelog/lib/src/gf-changelog-helpers.c')
-rw-r--r-- | xlators/features/changelog/lib/src/gf-changelog-helpers.c | 256 |
1 files changed, 128 insertions, 128 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.c b/xlators/features/changelog/lib/src/gf-changelog-helpers.c index 9ff1d135933..fd15ec68ab8 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-helpers.c +++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.c @@ -13,38 +13,40 @@ #include "changelog-lib-messages.h" #include "syscall.h" -ssize_t gf_changelog_read_path (int fd, char *buffer, size_t bufsize) +ssize_t +gf_changelog_read_path(int fd, char *buffer, size_t bufsize) { - return sys_read (fd, buffer, bufsize); + return sys_read(fd, buffer, bufsize); } size_t -gf_changelog_write (int fd, char *buffer, size_t len) +gf_changelog_write(int fd, char *buffer, size_t len) { - ssize_t size = 0; - size_t written = 0; + ssize_t size = 0; + size_t written = 0; - while (written < len) { - size = sys_write (fd, buffer + written, len - written); - if (size <= 0) - break; + while (written < len) { + size = sys_write(fd, buffer + written, len - written); + if (size <= 0) + break; - written += size; - } + written += size; + } - return written; + return written; } void -gf_rfc3986_encode_space_newline (unsigned char *s, char *enc, char *estr) +gf_rfc3986_encode_space_newline(unsigned char *s, char *enc, char *estr) { - for (; *s; s++) { - if (estr[*s]) - sprintf(enc, "%c", estr[*s]); - else - sprintf(enc, "%%%02X", *s); - while (*++enc); - } + for (; *s; s++) { + if (estr[*s]) + sprintf(enc, "%c", estr[*s]); + else + sprintf(enc, "%%%02X", *s); + while (*++enc) + ; + } } /** @@ -66,154 +68,152 @@ static pthread_key_t rl_key; static pthread_once_t rl_once = PTHREAD_ONCE_INIT; static void -readline_destructor (void *ptr) +readline_destructor(void *ptr) { - GF_FREE (ptr); + GF_FREE(ptr); } static void -readline_once (void) +readline_once(void) { - pthread_key_create (&rl_key, readline_destructor); + pthread_key_create(&rl_key, readline_destructor); } static ssize_t -my_read (read_line_t *tsd, int fd, char *ptr) +my_read(read_line_t *tsd, int fd, char *ptr) { - if (tsd->rl_cnt <= 0) { - tsd->rl_cnt = sys_read (fd, tsd->rl_buf, MAXLINE); - - if (tsd->rl_cnt < 0) - return -1; - else if (tsd->rl_cnt == 0) - return 0; - tsd->rl_bufptr = tsd->rl_buf; - } - - tsd->rl_cnt--; - *ptr = *tsd->rl_bufptr++; - return 1; + if (tsd->rl_cnt <= 0) { + tsd->rl_cnt = sys_read(fd, tsd->rl_buf, MAXLINE); + + if (tsd->rl_cnt < 0) + return -1; + else if (tsd->rl_cnt == 0) + return 0; + tsd->rl_bufptr = tsd->rl_buf; + } + + tsd->rl_cnt--; + *ptr = *tsd->rl_bufptr++; + return 1; } static int -gf_readline_init_once (read_line_t **tsd) +gf_readline_init_once(read_line_t **tsd) { - if (pthread_once (&rl_once, readline_once) != 0) - return -1; + if (pthread_once(&rl_once, readline_once) != 0) + return -1; - *tsd = pthread_getspecific (rl_key); - if (*tsd) - goto out; + *tsd = pthread_getspecific(rl_key); + if (*tsd) + goto out; - *tsd = GF_CALLOC (1, sizeof (**tsd), - gf_changelog_mt_libgfchangelog_rl_t); - if (!*tsd) - return -1; + *tsd = GF_CALLOC(1, sizeof(**tsd), gf_changelog_mt_libgfchangelog_rl_t); + if (!*tsd) + return -1; - if (pthread_setspecific (rl_key, *tsd) != 0) - return -1; + if (pthread_setspecific(rl_key, *tsd) != 0) + return -1; - out: - return 0; +out: + return 0; } ssize_t -gf_readline (int fd, void *vptr, size_t maxlen) +gf_readline(int fd, void *vptr, size_t maxlen) { - size_t n = 0; - size_t rc = 0; - char c = ' '; - char *ptr = NULL; - read_line_t *tsd = NULL; - - if (gf_readline_init_once (&tsd)) - return -1; - - ptr = vptr; - for (n = 1; n < maxlen; n++) { - if ( (rc = my_read (tsd, fd, &c)) == 1 ) { - *ptr++ = c; - if (c == '\n') - break; - } else if (rc == 0) { - *ptr = '\0'; - return (n - 1); - } else - return -1; - } - - *ptr = '\0'; - return n; + size_t n = 0; + size_t rc = 0; + char c = ' '; + char *ptr = NULL; + read_line_t *tsd = NULL; + + if (gf_readline_init_once(&tsd)) + return -1; + ptr = vptr; + for (n = 1; n < maxlen; n++) { + if ((rc = my_read(tsd, fd, &c)) == 1) { + *ptr++ = c; + if (c == '\n') + break; + } else if (rc == 0) { + *ptr = '\0'; + return (n - 1); + } else + return -1; + } + + *ptr = '\0'; + return n; } off_t -gf_lseek (int fd, off_t offset, int whence) +gf_lseek(int fd, off_t offset, int whence) { - off_t off = 0; - read_line_t *tsd = NULL; + off_t off = 0; + read_line_t *tsd = NULL; - if (gf_readline_init_once (&tsd)) - return -1; + if (gf_readline_init_once(&tsd)) + return -1; - off = sys_lseek (fd, offset, whence); - if (off == -1) - return -1; + off = sys_lseek(fd, offset, whence); + if (off == -1) + return -1; - tsd->rl_cnt = 0; - tsd->rl_bufptr = tsd->rl_buf; + tsd->rl_cnt = 0; + tsd->rl_bufptr = tsd->rl_buf; - return off; + return off; } int -gf_ftruncate (int fd, off_t length) +gf_ftruncate(int fd, off_t length) { - read_line_t *tsd = NULL; + read_line_t *tsd = NULL; - if (gf_readline_init_once (&tsd)) - return -1; + if (gf_readline_init_once(&tsd)) + return -1; - if (sys_ftruncate (fd, 0)) - return -1; + if (sys_ftruncate(fd, 0)) + return -1; - tsd->rl_cnt = 0; - tsd->rl_bufptr = tsd->rl_buf; + tsd->rl_cnt = 0; + tsd->rl_bufptr = tsd->rl_buf; - return 0; + return 0; } int -gf_thread_cleanup (xlator_t *this, pthread_t thread) +gf_thread_cleanup(xlator_t *this, pthread_t thread) { - int ret = 0; - void *res = NULL; - - ret = pthread_cancel (thread); - if (ret != 0) { - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, - "Failed to send cancellation to thread"); - goto error_return; - } - - ret = pthread_join (thread, &res); - if (ret != 0) { - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, - "failed to join thread"); - goto error_return; - } - - if (res != PTHREAD_CANCELED) { - gf_msg (this->name, GF_LOG_WARNING, 0, - CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, - "Thread could not be cleaned up"); - goto error_return; - } - - return 0; - - error_return: - return -1; + int ret = 0; + void *res = NULL; + + ret = pthread_cancel(thread); + if (ret != 0) { + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, + "Failed to send cancellation to thread"); + goto error_return; + } + + ret = pthread_join(thread, &res); + if (ret != 0) { + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, + "failed to join thread"); + goto error_return; + } + + if (res != PTHREAD_CANCELED) { + gf_msg(this->name, GF_LOG_WARNING, 0, + CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING, + "Thread could not be cleaned up"); + goto error_return; + } + + return 0; + +error_return: + return -1; } |