[klibc] another bugfix

maximilian attems max at stro.at
Mon Mar 28 11:20:27 PDT 2011


On Sat, 29 Jan 2011, Thorsten Glaser wrote:

> Hi,
> 
> number three, where I first thought it was a GCC bug but is
> apparently bad code in klibc. Submitted with permission:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47533#c6
> 
> Patch attached again (sorry) not just because that is easier
> with my mail system but also to keep original author intact.
> 
> bye,
> //mirabilos

while beeing correct c, looking back,
I'm totaly confused how this could be an issue on m68k?
Bugreport gives not much clue:
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47533
this arch should be really good for variadic functions.

this patch is said to cause a performance degradation of klibc on x86_64
thus I'm inclined to revert for now.


> From 14c78f4d68641dd571fb27d34a088014d1a0995b Mon Sep 17 00:00:00 2001
> From: Mikael Pettersson <mikpe at it.uu.se>
> Date: Sat, 29 Jan 2011 17:37:18 +0000
> Subject: [PATCH] use <stdarg.h> features in klibc open() and openat()
> 
> Looking in klibc-1.5.21 I see that the published prototype for open() is:
> 
> __extern int open(const char *, int, ...);
> 
> This looks fine, but the actual definition (which deliberately doesn't see the
> above prototype) is:
> 
> int open(const char *pathname, int flags, mode_t mode)
> { ... }
> 
> This is invalid C, and very sloppy programming.
> 
> Signed-off-by: Thorsten Glaser <tg at mirbsd.de>
> ---
>  usr/include/fcntl.h  |    2 --
>  usr/include/unistd.h |    2 --
>  usr/klibc/open.c     |   14 ++++++++++++--
>  usr/klibc/openat.c   |   14 ++++++++++++--
>  4 files changed, 24 insertions(+), 8 deletions(-)
> 
> diff --git a/usr/include/fcntl.h b/usr/include/fcntl.h
> index 0908e21..c94b2be 100644
> --- a/usr/include/fcntl.h
> +++ b/usr/include/fcntl.h
> @@ -35,10 +35,8 @@
>  #endif
>  
>  /* This is defined here as well as in <unistd.h> */
> -#ifndef _KLIBC_IN_OPEN_C
>  __extern int open(const char *, int, ...);
>  __extern int openat(int, const char *, int, ...);
> -#endif
>  
>  __extern int creat(const char *, mode_t);
>  __extern int fcntl(int, int, ...);
> diff --git a/usr/include/unistd.h b/usr/include/unistd.h
> index 97760d4..0d3205e 100644
> --- a/usr/include/unistd.h
> +++ b/usr/include/unistd.h
> @@ -82,10 +82,8 @@ __extern int lchown(const char *, uid_t, gid_t);
>  __extern char *getcwd(char *, size_t);
>  
>  /* Also in <fcntl.h> */
> -#ifndef _KLIBC_IN_OPEN_C
>  __extern int open(const char *, int, ...);
>  __extern int openat(int, const char *, int, ...);
> -#endif
>  __extern int creat(const char *, mode_t);
>  __extern int open_cloexec(const char *, int, mode_t);
>  __extern int close(int);
> diff --git a/usr/klibc/open.c b/usr/klibc/open.c
> index 9b0897a..290f959 100644
> --- a/usr/klibc/open.c
> +++ b/usr/klibc/open.c
> @@ -5,17 +5,27 @@
>   * system call, to indicate that we're 64-bit safe.
>   */
>  
> -#define _KLIBC_IN_OPEN_C
>  #include <unistd.h>
>  #include <fcntl.h>
>  #include <bitsize.h>
> +#include <stdarg.h>
>  
>  #if _BITSIZE == 32 && !defined(__i386__)
>  
>  extern int __open(const char *, int, mode_t);
>  
> -int open(const char *pathname, int flags, mode_t mode)
> +int open(const char *pathname, int flags, ...)
>  {
> +	mode_t mode = 0;
> +
> +	if (flags & O_CREAT) {
> +		va_list ap;
> +
> +		va_start(ap, flags);
> +		mode = va_arg(ap, mode_t);
> +		va_end(ap);
> +	}
> +
>  	return __open(pathname, flags | O_LARGEFILE, mode);
>  }
>  
> diff --git a/usr/klibc/openat.c b/usr/klibc/openat.c
> index 83c87cd..0609b83 100644
> --- a/usr/klibc/openat.c
> +++ b/usr/klibc/openat.c
> @@ -5,17 +5,27 @@
>   * system call, to indicate that we're 64-bit safe.
>   */
>  
> -#define _KLIBC_IN_OPEN_C
>  #include <unistd.h>
>  #include <fcntl.h>
>  #include <bitsize.h>
> +#include <stdarg.h>
>  
>  #if _BITSIZE == 32 && !defined(__i386__) && defined(__NR_openat)
>  
>  extern int __openat(int, const char *, int, mode_t);
>  
> -int openat(int dirfd, const char *pathname, int flags, mode_t mode)
> +int openat(int dirfd, const char *pathname, int flags, ...)
>  {
> +	mode_t mode = 0;
> +
> +	if (flags & O_CREAT) {
> +		va_list ap;
> +
> +		va_start(ap, flags);
> +		mode = va_arg(ap, mode_t);
> +		va_end(ap);
> +	}
> +
>  	return __openat(dirfd, pathname, flags | O_LARGEFILE, mode);
>  }
>  
> -- 
> 1.7.2.3
> 

-- 
maks



More information about the klibc mailing list