From patchwork Tue Sep 22 18:16:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuriy Kolerov X-Patchwork-Id: 521387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id E71611401CD for ; Wed, 23 Sep 2015 04:16:19 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1B9A2A4417; Tue, 22 Sep 2015 18:16:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mnCDHSuF0cBi; Tue, 22 Sep 2015 18:16:15 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 28F3FA43D6; Tue, 22 Sep 2015 18:16:15 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 28FE81BFC01 for ; Tue, 22 Sep 2015 18:16:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 2565587E5B for ; Tue, 22 Sep 2015 18:16:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1sPK2x5CGIMD for ; Tue, 22 Sep 2015 18:16:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtprelay.synopsys.com (us01smtprelay-2.synopsys.com [198.182.60.111]) by hemlock.osuosl.org (Postfix) with ESMTPS id 73C6D8754E for ; Tue, 22 Sep 2015 18:16:11 +0000 (UTC) Received: from dc8secmta1.synopsys.com (dc8secmta1.synopsys.com [10.13.218.200]) by smtprelay.synopsys.com (Postfix) with ESMTP id CBB1310C140E for ; Tue, 22 Sep 2015 11:16:10 -0700 (PDT) Received: from dc8secmta1.internal.synopsys.com (dc8secmta1.internal.synopsys.com [127.0.0.1]) by dc8secmta1.internal.synopsys.com (Service) with ESMTP id BED9727119 for ; Tue, 22 Sep 2015 11:16:10 -0700 (PDT) Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by dc8secmta1.internal.synopsys.com (Service) with ESMTP id A146527118 for ; Tue, 22 Sep 2015 11:16:10 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 8C06A35C; Tue, 22 Sep 2015 11:16:10 -0700 (PDT) Received: from ykolerov-lab.internal.synopsys.com (ykolerov-lab.internal.synopsys.com [10.121.8.82]) by mailhost.synopsys.com (Postfix) with ESMTP id E7D79342; Tue, 22 Sep 2015 11:16:08 -0700 (PDT) From: Yuriy Kolerov To: uclibc@uclibc.org, Vineet.Gupta1@synopsys.com, Alexey.Brodkin@synopsys.com, Anton.Kolesov@synopsys.com Subject: [PATCH v2 3/3] libc: posix_fallocate must return an error number on failure Date: Tue, 22 Sep 2015 21:16:00 +0300 Message-Id: <1442945760-30551-3-git-send-email-yuriy.kolerov@synopsys.com> X-Mailer: git-send-email 2.2.0 In-Reply-To: <1442945760-30551-1-git-send-email-yuriy.kolerov@synopsys.com> References: <1442945760-30551-1-git-send-email-yuriy.kolerov@synopsys.com> Cc: Francois.Bedard@synopsys.com X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" posix_fallocate implementation in uClibc relies on fallocate system call - it just returns what fallocate returns. However fallocate returns -1 on failure and assigns an error number to errno variable. In the same time posix_fallocate must return an error number but not -1. What does this patch: if fallocate returns -1 then posix_fallocate returns errno. Otherwise posix_fallocate returns 0 on success. However there is a side effect - posix_fallocate sets errno on failure because fallocate does it. But POSIX does not forbid it thus it's not a problem. Signed-off-by: Yuriy Kolerov --- libc/sysdeps/linux/common/posix_fallocate.c | 5 ++++- libc/sysdeps/linux/common/posix_fallocate64.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libc/sysdeps/linux/common/posix_fallocate.c b/libc/sysdeps/linux/common/posix_fallocate.c index 76771e3..2316cfd 100644 --- a/libc/sysdeps/linux/common/posix_fallocate.c +++ b/libc/sysdeps/linux/common/posix_fallocate.c @@ -12,12 +12,15 @@ #include #include #include +#include #if defined __NR_fallocate extern __typeof(fallocate) __libc_fallocate attribute_hidden; int posix_fallocate(int fd, __off_t offset, __off_t len) { - return __libc_fallocate(fd, 0, offset, len); + if (__libc_fallocate(fd, 0, offset, len)) + return errno; + return 0; } # if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 strong_alias(posix_fallocate,posix_fallocate64) diff --git a/libc/sysdeps/linux/common/posix_fallocate64.c b/libc/sysdeps/linux/common/posix_fallocate64.c index 12ddbc2..85614f6 100644 --- a/libc/sysdeps/linux/common/posix_fallocate64.c +++ b/libc/sysdeps/linux/common/posix_fallocate64.c @@ -12,6 +12,7 @@ #include #include #include +#include #if defined __NR_fallocate # if __WORDSIZE == 64 @@ -20,7 +21,9 @@ extern __typeof(fallocate64) __libc_fallocate64 attribute_hidden; int posix_fallocate64(int fd, __off64_t offset, __off64_t len) { - return __libc_fallocate64(fd, 0, offset, len); + if (__libc_fallocate64(fd, 0, offset, len)) + return errno; + return 0; } # else # error your machine is neither 32 bit or 64 bit ... it must be magical