From 2bfa2e5e22757d5c7252dc7594cf4c36e86b8b58 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Fri, 23 Jan 2015 13:29:36 +0100 Subject: [PATCH] style: rename buf to buffer and len to size for consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/libuv/libuv/pull/159 Reviewed-By: Saúl Ibarra Corretgé --- docs/src/fs_event.rst | 4 ++-- docs/src/fs_poll.rst | 4 ++-- docs/src/pipe.rst | 4 ++-- include/uv.h | 12 +++++++----- src/fs-poll.c | 12 ++++++------ src/unix/pipe.c | 12 ++++++------ src/uv-common.c | 12 ++++++------ src/win/pipe.c | 26 +++++++++++++------------- 8 files changed, 44 insertions(+), 42 deletions(-) diff --git a/docs/src/fs_event.rst b/docs/src/fs_event.rst index d92e88c8f..681ae52f9 100644 --- a/docs/src/fs_event.rst +++ b/docs/src/fs_event.rst @@ -94,11 +94,11 @@ API Stop the handle, the callback will no longer be called. -.. c:function:: int uv_fs_event_getpath(uv_fs_event_t* handle, char* buf, size_t* len) +.. c:function:: int uv_fs_event_getpath(uv_fs_event_t* handle, char* buffer, size_t* size) Get the path being monitored by the handle. The buffer must be preallocated by the user. Returns 0 on success or an error code < 0 in case of failure. - On success, `buf` will contain the path and `len` its length. If the buffer + On success, `buffer` will contain the path and `size` its length. If the buffer is not big enough UV_ENOBUFS will be returned and len will be set to the required size. diff --git a/docs/src/fs_poll.rst b/docs/src/fs_poll.rst index 58db1d2f4..4efb2440e 100644 --- a/docs/src/fs_poll.rst +++ b/docs/src/fs_poll.rst @@ -58,11 +58,11 @@ API Stop the handle, the callback will no longer be called. -.. c:function:: int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buf, size_t* len) +.. c:function:: int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buffer, size_t* size) Get the path being monitored by the handle. The buffer must be preallocated by the user. Returns 0 on success or an error code < 0 in case of failure. - On success, `buf` will contain the path and `len` its length. If the buffer + On success, `buffer` will contain the path and `size` its length. If the buffer is not big enough UV_ENOBUFS will be returned and len will be set to the required size. diff --git a/docs/src/pipe.rst b/docs/src/pipe.rst index 11e613025..01aea4ac8 100644 --- a/docs/src/pipe.rst +++ b/docs/src/pipe.rst @@ -56,11 +56,11 @@ API Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between 92 and 108 bytes. -.. c:function:: int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) +.. c:function:: int uv_pipe_getsockname(const uv_pipe_t* handle, char* buffer, size_t* size) Get the name of the Unix domain socket or the named pipe. - A preallocated buffer must be provided. The len parameter holds the length + A preallocated buffer must be provided. The size parameter holds the length of the buffer and it's set to the number of bytes written to the buffer on output. If the buffer is not big enough ``UV_ENOBUFS`` will be returned and len will contain the required size. diff --git a/include/uv.h b/include/uv.h index f1a952625..72de65e58 100644 --- a/include/uv.h +++ b/include/uv.h @@ -675,8 +675,8 @@ UV_EXTERN void uv_pipe_connect(uv_connect_t* req, const char* name, uv_connect_cb cb); UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle, - char* buf, - size_t* len); + char* buffer, + size_t* size); UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count); UV_EXTERN int uv_pipe_pending_count(uv_pipe_t* handle); UV_EXTERN uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle); @@ -1261,7 +1261,9 @@ UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle, const char* path, unsigned int interval); UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle); -UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buf, size_t* len); +UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle, + char* buffer, + size_t* size); struct uv_signal_s { @@ -1318,8 +1320,8 @@ UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle, unsigned int flags); UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle); UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle, - char* buf, - size_t* len); + char* buffer, + size_t* size); UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr); UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr); diff --git a/src/fs-poll.c b/src/fs-poll.c index 3a97b3e0f..1145e5fc3 100644 --- a/src/fs-poll.c +++ b/src/fs-poll.c @@ -125,12 +125,12 @@ int uv_fs_poll_stop(uv_fs_poll_t* handle) { } -int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buf, size_t* len) { +int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buffer, size_t* size) { struct poll_ctx* ctx; size_t required_len; if (!uv__is_active(handle)) { - *len = 0; + *size = 0; return UV_EINVAL; } @@ -138,13 +138,13 @@ int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buf, size_t* len) { assert(ctx != NULL); required_len = strlen(ctx->path); - if (required_len > *len) { - *len = required_len; + if (required_len > *size) { + *size = required_len; return UV_ENOBUFS; } - memcpy(buf, ctx->path, required_len); - *len = required_len; + memcpy(buffer, ctx->path, required_len); + *size = required_len; return 0; } diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 602f23a3e..c9f0a1494 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -206,7 +206,7 @@ out: } -int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { +int uv_pipe_getsockname(const uv_pipe_t* handle, char* buffer, size_t* size) { struct sockaddr_un sa; socklen_t addrlen; int err; @@ -215,7 +215,7 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { memset(&sa, 0, addrlen); err = getsockname(uv__stream_fd(handle), (struct sockaddr*) &sa, &addrlen); if (err < 0) { - *len = 0; + *size = 0; return -errno; } @@ -226,13 +226,13 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { addrlen = strlen(sa.sun_path); - if (addrlen > *len) { - *len = addrlen; + if (addrlen > *size) { + *size = addrlen; return UV_ENOBUFS; } - memcpy(buf, sa.sun_path, addrlen); - *len = addrlen; + memcpy(buffer, sa.sun_path, addrlen); + *size = addrlen; return 0; } diff --git a/src/uv-common.c b/src/uv-common.c index 1032448fb..791c09b4e 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -359,22 +359,22 @@ int uv_send_buffer_size(uv_handle_t* handle, int *value) { return uv__socket_sockopt(handle, SO_SNDBUF, value); } -int uv_fs_event_getpath(uv_fs_event_t* handle, char* buf, size_t* len) { +int uv_fs_event_getpath(uv_fs_event_t* handle, char* buffer, size_t* size) { size_t required_len; if (!uv__is_active(handle)) { - *len = 0; + *size = 0; return UV_EINVAL; } required_len = strlen(handle->path); - if (required_len > *len) { - *len = required_len; + if (required_len > *size) { + *size = required_len; return UV_ENOBUFS; } - memcpy(buf, handle->path, required_len); - *len = required_len; + memcpy(buffer, handle->path, required_len); + *size = required_len; return 0; } diff --git a/src/win/pipe.c b/src/win/pipe.c index 2d6061689..205af5ea3 100644 --- a/src/win/pipe.c +++ b/src/win/pipe.c @@ -1910,7 +1910,7 @@ int uv_pipe_open(uv_pipe_t* pipe, uv_file file) { } -int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { +int uv_pipe_getsockname(const uv_pipe_t* handle, char* buffer, size_t* size) { NTSTATUS nt_status; IO_STATUS_BLOCK io_status; FILE_NAME_INFORMATION tmp_name_info; @@ -1924,7 +1924,7 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { name_info = NULL; if (handle->handle == INVALID_HANDLE_VALUE) { - *len = 0; + *size = 0; return UV_EINVAL; } @@ -1939,7 +1939,7 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { name_size = sizeof(*name_info) + tmp_name_info.FileNameLength; name_info = malloc(name_size); if (!name_info) { - *len = 0; + *size = 0; err = UV_ENOMEM; goto cleanup; } @@ -1952,7 +1952,7 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { } if (nt_status != STATUS_SUCCESS) { - *len = 0; + *size = 0; err = uv_translate_sys_error(pRtlNtStatusToDosError(nt_status)); goto error; } @@ -1967,7 +1967,7 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { } if (name_len == 0) { - *len = 0; + *size = 0; err = 0; goto error; } @@ -1984,33 +1984,33 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) { NULL, NULL); if (!addrlen) { - *len = 0; + *size = 0; err = uv_translate_sys_error(GetLastError()); goto error; - } else if (pipe_prefix_len + addrlen > *len) { + } else if (pipe_prefix_len + addrlen > *size) { /* "\\\\.\\pipe" + name */ - *len = pipe_prefix_len + addrlen; + *size = pipe_prefix_len + addrlen; err = UV_ENOBUFS; goto error; } - memcpy(buf, pipe_prefix, pipe_prefix_len); + memcpy(buffer, pipe_prefix, pipe_prefix_len); addrlen = WideCharToMultiByte(CP_UTF8, 0, name_buf, name_len, - buf+pipe_prefix_len, - *len-pipe_prefix_len, + buffer+pipe_prefix_len, + *size-pipe_prefix_len, NULL, NULL); if (!addrlen) { - *len = 0; + *size = 0; err = uv_translate_sys_error(GetLastError()); goto error; } addrlen += pipe_prefix_len; - *len = addrlen; + *size = addrlen; err = 0; goto cleanup;