mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Bug: ftell() after fopen(..., "ab") returns 0 unless an explicit fseek() is used first
@ 2022-08-11 11:14 Buchholz, Robert
  2022-08-11 11:36 ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Buchholz, Robert @ 2022-08-11 11:14 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1090 bytes --]

I'm running Alpine Linux with MUSL as its standard library within a Docker container based on the official openjdk:16-jdk-alpine3.13 Alpine image.

I've used the following minimal test case:
#include <stdio.h>

int main()
  FILE* f = fopen("foo", "wb");
  fwrite("42", 3, 1, f);

  f = fopen("foo", "ab");
  printf("%d ", (int)ftell(f));
  fwrite("42", 3, 1, f);
  fseek(f, 0, SEEK_END);
  printf("%d\n", (int)ftell(f));
On my Alpine/MUSL setup this prints "0 6" while on Ubuntu 22.04 with glibc it prints "3 6" - which I'm assuming is the expected output. So, with MUSL the second fwrite() correctly appends to the existing file, but ftell() nevertheless reports that the initial position within the file after opening it for appending is 0 and not 3.

My GCC version is "gcc (Alpine 10.2.1_pre1) 10.2.1 20201203", ldd confirms that the compiled output is linked only against "/lib/" and not against glibc.

I'm not subscribed to the MUSL mailing list, please CC me on replies.

Best Regards,
Robert Buchholz

[-- Attachment #2: Type: text/html, Size: 4090 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-18  0:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 11:14 [musl] Bug: ftell() after fopen(..., "ab") returns 0 unless an explicit fseek() is used first Buchholz, Robert
2022-08-11 11:36 ` Florian Weimer
2022-08-18  0:31   ` Rich Felker

Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).