posix: Fix attribute access mode on getcwd with GNU extension [BZ #27476]

Message ID 20210908225250.3912555-1-aurelien@aurel32.net
State New
Headers show
Series
  • posix: Fix attribute access mode on getcwd with GNU extension [BZ #27476]
Related show

Commit Message

Aurelien Jarno Sept. 8, 2021, 10:52 p.m.
There is a GNU extension that allows to call getcwd(NULL, >0). It is
described in the documentation, but also directly in the unistd.h
header, just above the declaration.

Therefore, do not define the attribute access mode when __USE_GNU is in
used.
---
 posix/unistd.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Note: I am aware of BZ #26545, however while it is being discussed, the
bug is still there, so I don't think we should block on a decision to
fix it.

-- 
2.30.2

Comments

H.J. Lu via Libc-alpha Sept. 10, 2021, 11:34 a.m. | #1
* Aurelien Jarno:

> There is a GNU extension that allows to call getcwd(NULL, >0). It is

> described in the documentation, but also directly in the unistd.h

> header, just above the declaration.

>

> Therefore, do not define the attribute access mode when __USE_GNU is in

> used.


I think we should drop the attribute unconditionally.

Thanks,
Florian

Patch

diff --git a/posix/unistd.h b/posix/unistd.h
index 3dca65732f..506d34d2ec 100644
--- a/posix/unistd.h
+++ b/posix/unistd.h
@@ -529,7 +529,10 @@  extern int fchdir (int __fd) __THROW __wur;
    bytes long, unless SIZE == 0, in which case it is as
    big as necessary.  */
 extern char *getcwd (char *__buf, size_t __size) __THROW __wur
-    __attr_access ((__write_only__, 1, 2));
+#ifndef   __USE_GNU
+    __attr_access ((__write_only__, 1, 2))
+#endif
+    ;
 
 #ifdef	__USE_GNU
 /* Return a malloc'd string containing the current directory name.