public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* [Bug 215848] New: fopen(3): Incorrect good practice suggestion
@ 2022-04-17 17:05 bugzilla-daemon
  2022-04-18  3:32 ` [Bug 215848] " bugzilla-daemon
  2022-05-14 12:37 ` bugzilla-daemon
  0 siblings, 2 replies; 3+ messages in thread
From: bugzilla-daemon @ 2022-04-17 17:05 UTC (permalink / raw)
  To: linux-man

https://bugzilla.kernel.org/show_bug.cgi?id=215848

            Bug ID: 215848
           Summary: fopen(3): Incorrect good practice suggestion
           Product: Documentation
           Version: unspecified
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: man-pages
          Assignee: documentation_man-pages@kernel-bugs.osdl.org
          Reporter: rootkea@gmail.com
        Regression: No

Hello!

From fopen(3):
"Therefore it is good practice (and indeed sometimes necessary under Linux) to
put an fseek(3) or fgetpos(3) operation between write and read operations on
such a stream."

I am not sure about the origin of this good practice but fgetpos(3) seems
wrong. It has to be fsetpos(3) if I'm reading the C standard and POSIX[0]
correctly.

BTW, calling fsetpos(3) will require a call to fgetpos(3) first. So why is it
being advised as a good practice to call two functions (`fgetpos` and then
`fsetpos`)? Maybe just i) mention fseek(3) only OR ii) mention fseek(3) and
fflush(3) (instead of fsetpos(3))?

[0]
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/fopen.html

Thanks!

Regards,
Avinash Sonawane (rootKea)
https://www.rootkea.me

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

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

* [Bug 215848] fopen(3): Incorrect good practice suggestion
  2022-04-17 17:05 [Bug 215848] New: fopen(3): Incorrect good practice suggestion bugzilla-daemon
@ 2022-04-18  3:32 ` bugzilla-daemon
  2022-05-14 12:37 ` bugzilla-daemon
  1 sibling, 0 replies; 3+ messages in thread
From: bugzilla-daemon @ 2022-04-18  3:32 UTC (permalink / raw)
  To: linux-man

https://bugzilla.kernel.org/show_bug.cgi?id=215848

--- Comment #1 from Avinash Sonawane (rootkea@gmail.com) ---
I think we should only mention using `fseek` as a good practice between read
and write operations since:
a. fflush can't be used on input stream i.e. if last operation was read while
fseek() can be used between read-write or write-read.

b. fsetpos needs fgetpos to be called first. So let's drop `fgetpos+fsetpos`
from the good practice suggestion

So I suggest this small change:
diff --git a/man3/fopen.3 b/man3/fopen.3
index a1d781706..fb289a537 100644
--- a/man3/fopen.3
+++ b/man3/fopen.3
@@ -138,8 +138,6 @@ result of writes other than the most recent.)
 Therefore it is good practice (and indeed sometimes necessary
 under Linux) to put an
 .BR fseek (3)
-or
-.BR fgetpos (3)
 operation between write and read operations on such a stream.
 This operation may be an apparent no-op
 (as in \fIfseek(..., 0L, SEEK_CUR)\fP

Thanks!

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

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

* [Bug 215848] fopen(3): Incorrect good practice suggestion
  2022-04-17 17:05 [Bug 215848] New: fopen(3): Incorrect good practice suggestion bugzilla-daemon
  2022-04-18  3:32 ` [Bug 215848] " bugzilla-daemon
@ 2022-05-14 12:37 ` bugzilla-daemon
  1 sibling, 0 replies; 3+ messages in thread
From: bugzilla-daemon @ 2022-05-14 12:37 UTC (permalink / raw)
  To: linux-man

https://bugzilla.kernel.org/show_bug.cgi?id=215848

Alejandro Colomar (man-pages) (alx.manpages@gmail.com) changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alx.manpages@gmail.com
         Resolution|---                         |CODE_FIX

--- Comment #2 from Alejandro Colomar (man-pages) (alx.manpages@gmail.com) ---
Hi Avinash,

I decided to keep fsetpos(3) to not lose the info, so I applied the following
patch:


    fopen.3: tfix

    Reported-by: Avinash Sonawane <rootkea@gmail.com>
    Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>

diff --git a/man3/fopen.3 b/man3/fopen.3
index b9bbc4704..465031167 100644
--- a/man3/fopen.3
+++ b/man3/fopen.3
@@ -114,7 +114,7 @@ Therefore it is good practice (and indeed sometimes
necessary
 under Linux) to put an
 .BR fseek (3)
 or
-.BR fgetpos (3)
+.BR fsetpos (3)
 operation between write and read operations on such a stream.
 This operation may be an apparent no-op
 (as in \fIfseek(..., 0L, SEEK_CUR)\fP

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

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

end of thread, other threads:[~2022-05-14 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-17 17:05 [Bug 215848] New: fopen(3): Incorrect good practice suggestion bugzilla-daemon
2022-04-18  3:32 ` [Bug 215848] " bugzilla-daemon
2022-05-14 12:37 ` bugzilla-daemon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox