From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8064 Path: news.gmane.org!not-for-mail From: Justin Cormack Newsgroups: gmane.linux.lib.musl.general Subject: Re: fseek EOVERFLOW Date: Mon, 29 Jun 2015 15:45:02 +0100 Message-ID: References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1435589117 19353 80.91.229.3 (29 Jun 2015 14:45:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Jun 2015 14:45:17 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8077-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jun 29 16:45:17 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Z9aJ9-0001iY-O0 for gllmg-musl@m.gmane.org; Mon, 29 Jun 2015 16:45:15 +0200 Original-Received: (qmail 3865 invoked by uid 550); 29 Jun 2015 14:45:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 3845 invoked from network); 29 Jun 2015 14:45:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=specialbusservice.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Oiabp/BhF7ZirhlQRac0gIioeRwV0fq/NHi6LshHnFM=; b=FP2bwXhrmLb35ASie4CSBdndbN1ag7gXiXVm3EnUdMwWv24Zt36TRsIqlMryPDqKQK ezmbz1at0MI1cyC0mzsmsBl9zJVaYfKeGSbQdOzzYqzTLIhpWLyycbyU5/KD2hmqGVgc 7XbNTZ2HK3M6xDbj/DaooHl03NbYKgST0YnPQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=Oiabp/BhF7ZirhlQRac0gIioeRwV0fq/NHi6LshHnFM=; b=GYI57oMei+OWIv75eOac6QGrrQp2Pxdr4+ysI2GSLX6XJqnxc5S90OILJUnb12S3gt w8xmpX3OU6wu8lPQLEaSZhyQ3pua+8WEEo/R7FHEg1gGCIh8htv+8qN6vLyWb+HEmcnh AC9iTkDrp44BrdjpFbJsNKvmkQU8r7C/6cYHI/YXISOdV0G7tkS9qkvwWoHaCPlY+Igh oJl2ptxuVlqCScJSXhjVx2s9guAs1wDLWJk2yFq9Kcj+kLtrcCcBkIg8b0JogfjJ/4ld j/Q5pJ8GvUi2IMK/nzLMQNI4gkBrILAkOaI8GXbqrKp1qodHGx8/HWnzy5At7w/xbavv GQww== X-Gm-Message-State: ALoCoQm9r2Mudso2B6Z8k+49vTRVd2ki4hP7+Gi5LrDQGIX85bajFB4YgZIomxyAUlKkpIkqcELH X-Received: by 10.180.104.197 with SMTP id gg5mr23529648wib.27.1435589102134; Mon, 29 Jun 2015 07:45:02 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:8064 Archived-At: On 29 June 2015 at 14:19, Alexander Monakov wrote: > Hello, > > if I run the following test: > > cat <test-fseek.c > > #include > #include > #include > int main() > { > FILE *f = fopen("/dev/zero", "r"); > int r = fseek(f, -1, SEEK_SET); > printf("%d %s\n", r, strerror(errno)); > return 0; > } > > EOF > > I observe the following results: > > - on musl, the argument (-1) is sign-extended for syscall, and no failure is > reported; > > - on glibc, the argument is sign-extended for syscall (and a syscall is made), > but return value 'r' is set to -1 to indicate an error, but errno is not > set. > > It's not entirely obvious to me if (and how) the implementation should > diagnose this, but in light of the fact that a syscall is made with a huge > 64-bit value as offset, the following seems to apply on 32-bit platforms: > > [EOVERFLOW] > [CX] For fseek(), the resulting file offset would be a value which cannot > be represented correctly in an object of type long. > > > (I hit this issue due to using fseek with size_t offsets and SEEK_SET: on > 32-bit, my offsets in range 2G-4G were sign-extended, leading to failure with > unclear diagnostics) The sign extension is correct - the argument to fseek is off_t (and so is the return value, it is not an int), and off_t is always 64 bit on Musl. For glibc it depends if it is compiled with LARGEFILE_SOURCE. So the sign extension is nothing to do with libc, it is your code. Negative offsets are allowed by Posix, and Linux does seem ok with them; you need to reset errno before lseek. I dont have a 32 bit Musl machine at the minute, I should install one, but on 64 bit I get 0 returned correctly. Justin