On Tue, Mar 22, 2011 at 06:41:25PM +0100, Rainer Orth wrote:
> Apart from the lack of wait4, libgo on IRIX 6.5 contained an undefined
> reference to strerror_r.  This patch provides a replacement, based on
> gnulib/lib/strerror_r.c, but massively simplified.

gnulib strerror_r.c is GPLv3+ licensed, you can't just relicense it
as BSD.

> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/libgo/syscalls/strerror_r.c     Sat Mar 19 21:55:54 2011 +0100
> @@ -0,0 +1,38 @@
> +/* strerror_r.c -- strerror_r replacement for systems with strerror only
> +
> +   Copyright 2011 The Go Authors. All rights reserved.
> +   Use of this source code is governed by a BSD-style
> +   license that can be found in the LICENSE file.  */
> +
> +#include "config.h"
> +#ifndef HAVE_STRERROR_R
> +#include <errno.h>
> +#include <string.h>
> +#include <pthread.h>
> +
> +/* This lock protects the buffer returned by strerror().  We assume that
> +   no other uses of strerror() exist in the program.  */
> +static pthread_mutex_t strerror_lock = PTHREAD_MUTEX_INITIALIZER;;
> +
> +int
> +strerror_r (int errnum, char *buf, size_t buflen)
> +{
> +  char *errmsg = strerror (errnum);
> +  size_t len = strlen (errmsg);
> +  int ret;
> +
> +  pthread_mutex_lock (&strerror_lock);
> +
> +  if (len < buflen)
> +    {
> +      memcpy (buf, errmsg, len + 1);
> +      ret = 0;
> +    }
> +  else
> +    ret = ERANGE;
> +
> +  pthread_mutex_unlock (&strerror_lock);
> +
> +  return ret;
> +}
> +#endif /* HAVE_STRERROR_R */

        Jakub

Reply via email to