From: Michael Orlitzky Date: Mon, 26 Feb 2018 00:55:34 +0000 (-0500) Subject: Inline the one call to the get_mode() function. X-Git-Tag: v0.1.0~29 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=ca41da09458ee421117901cc3e1a96a37e921f14;p=apply-default-acl.git Inline the one call to the get_mode() function. The get_mode() function was only called in one place, and its implementation was about three lines. The overhead of checking its arguments and figuring out its return value was not worth the absolutely tiny improvement in readability that the function afforded, so the whole thing has been inlined at its one call site. --- diff --git a/src/apply-default-acl.c b/src/apply-default-acl.c index 993b1f7..15383a0 100644 --- a/src/apply-default-acl.c +++ b/src/apply-default-acl.c @@ -34,35 +34,6 @@ -/** - * @brief Get the mode bits from the given file descriptor. - * - * @param fd - * The file descriptor (which may reference a directory) whose - * mode we want. - * - * @return A mode_t (st_mode) structure containing the mode bits. - * See sys/stat.h for details. - */ -mode_t get_mode(int fd) { - if (fd <= 0) { - errno = ENOENT; - return ACL_ERROR; - } - - struct stat s; - int result = fstat(fd, &s); - - if (result == 0) { - return s.st_mode; - } - else { - /* errno will be set already by lstat() */ - return result; - } -} - - /** * @brief Determine if the given file descriptor might refer to an @@ -482,8 +453,13 @@ int any_can_execute_or_dir(int fd) { int result = ACL_FAILURE; if (acl_is_minimal(acl)) { - mode_t mode = get_mode(fd); - if (mode & (S_IXUSR | S_IXOTH | S_IXGRP)) { + struct stat s; + if (fstat(fd, &s) == -1) { + perror("any_can_execute_or_dir (fstat)"); + result = ACL_ERROR; + goto cleanup; + } + if (s.st_mode & (S_IXUSR | S_IXOTH | S_IXGRP)) { result = ACL_SUCCESS; goto cleanup; }