From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id CC0623857C40; Fri, 30 Apr 2021 18:32:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC0623857C40 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: mq_open: set filesize using ftruncate X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 2d3416440213e1208ed665558e5eda765cb5f061 X-Git-Newrev: 715c4208e47395bbe021c67f5bf86d08cb802905 Message-Id: <20210430183259.CC0623857C40@sourceware.org> Date: Fri, 30 Apr 2021 18:32:59 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Apr 2021 18:32:59 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=715c4208e47395bbe021c67f5bf86d08cb802905 commit 715c4208e47395bbe021c67f5bf86d08cb802905 Author: Corinna Vinschen Date: Fri Apr 30 18:15:20 2021 +0200 Cygwin: mq_open: set filesize using ftruncate ftruncate is leaner than lseek/write. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/posix_ipc.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/posix_ipc.cc b/winsup/cygwin/posix_ipc.cc index 89ec7dbef..fdecbca75 100644 --- a/winsup/cygwin/posix_ipc.cc +++ b/winsup/cygwin/posix_ipc.cc @@ -23,6 +23,8 @@ details. */ #include #include +extern "C" int ftruncate64 (int fd, off_t length); + /* The prefix_len is the length of the path prefix ncluding trailing "/" (or "/sem." for semaphores) as well as the trailing NUL. */ static struct @@ -471,9 +473,7 @@ mq_open (const char *name, int oflag, ...) msgsize = MSGSIZE (attr->mq_msgsize); filesize = sizeof (struct mq_hdr) + (attr->mq_maxmsg * (sizeof (struct msg_hdr) + msgsize)); - if (lseek64 (fd, filesize - 1, SEEK_SET) == -1) - __leave; - if (write (fd, "", 1) == -1) + if (ftruncate64 (fd, filesize) == -1) __leave; /* Memory map the file */