mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-27 13:54:19 +08:00
libgo: Support systems which do not have strerror_r.
From-SVN: r171757
This commit is contained in:
parent
25a182be4f
commit
8955c80a1c
@ -1264,7 +1264,11 @@ endif
|
||||
if LIBGO_IS_RTEMS
|
||||
syscall_errstr_file = syscalls/errstr_rtems.go
|
||||
else
|
||||
if HAVE_STRERROR_R
|
||||
syscall_errstr_file = syscalls/errstr.go
|
||||
else
|
||||
syscall_errstr_file = syscalls/errstr_nor.go
|
||||
endif
|
||||
endif
|
||||
|
||||
# Declare libc_strerror_r which is the Go name for strerror_r.
|
||||
@ -1273,7 +1277,7 @@ if LIBGO_IS_RTEMS
|
||||
syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go
|
||||
else
|
||||
if LIBGO_IS_LINUX
|
||||
# In Linux the POSIX strerror_r is called __xpg_strerror_r.
|
||||
# On GNU/Linux the POSIX strerror_r is called __xpg_strerror_r.
|
||||
syscall_errstr_decl_file = syscalls/errstr_decl_linux.go
|
||||
else
|
||||
# On other systems we hope strerror_r is just strerror_r.
|
||||
|
@ -1638,13 +1638,14 @@ go_testing_script_files = \
|
||||
|
||||
# Define Sleep.
|
||||
@LIBGO_IS_RTEMS_TRUE@syscall_sleep_file = syscalls/sleep_rtems.go
|
||||
@LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr.go
|
||||
@HAVE_STRERROR_R_FALSE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr_nor.go
|
||||
@HAVE_STRERROR_R_TRUE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr.go
|
||||
|
||||
# Define Errstr.
|
||||
@LIBGO_IS_RTEMS_TRUE@syscall_errstr_file = syscalls/errstr_rtems.go
|
||||
# On other systems we hope strerror_r is just strerror_r.
|
||||
@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl.go
|
||||
# In Linux the POSIX strerror_r is called __xpg_strerror_r.
|
||||
# On GNU/Linux the POSIX strerror_r is called __xpg_strerror_r.
|
||||
@LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl_linux.go
|
||||
|
||||
# Declare libc_strerror_r which is the Go name for strerror_r.
|
||||
|
21
libgo/configure
vendored
21
libgo/configure
vendored
@ -603,6 +603,8 @@ am__EXEEXT_TRUE
|
||||
LTLIBOBJS
|
||||
LIBOBJS
|
||||
STRINGOPS_FLAG
|
||||
HAVE_STRERROR_R_FALSE
|
||||
HAVE_STRERROR_R_TRUE
|
||||
HAVE_SYS_MMAN_H_FALSE
|
||||
HAVE_SYS_MMAN_H_TRUE
|
||||
PTHREAD_LIBS
|
||||
@ -10898,7 +10900,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 10901 "configure"
|
||||
#line 10903 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@ -11004,7 +11006,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 11007 "configure"
|
||||
#line 11009 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@ -14151,7 +14153,8 @@ else
|
||||
HAVE_SYS_MMAN_H_FALSE=
|
||||
fi
|
||||
|
||||
for ac_func in srandom random strsignal
|
||||
|
||||
for ac_func in srandom random strerror_r strsignal
|
||||
do :
|
||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||
@ -14164,6 +14167,14 @@ _ACEOF
|
||||
fi
|
||||
done
|
||||
|
||||
if test "$ac_cv_func_strerror_r" = yes; then
|
||||
HAVE_STRERROR_R_TRUE=
|
||||
HAVE_STRERROR_R_FALSE='#'
|
||||
else
|
||||
HAVE_STRERROR_R_TRUE='#'
|
||||
HAVE_STRERROR_R_FALSE=
|
||||
fi
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __sync_bool_compare_and_swap_4" >&5
|
||||
$as_echo_n "checking for __sync_bool_compare_and_swap_4... " >&6; }
|
||||
@ -14537,6 +14548,10 @@ if test -z "${HAVE_SYS_MMAN_H_TRUE}" && test -z "${HAVE_SYS_MMAN_H_FALSE}"; then
|
||||
as_fn_error "conditional \"HAVE_SYS_MMAN_H\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
fi
|
||||
if test -z "${HAVE_STRERROR_R_TRUE}" && test -z "${HAVE_STRERROR_R_FALSE}"; then
|
||||
as_fn_error "conditional \"HAVE_STRERROR_R\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
fi
|
||||
|
||||
: ${CONFIG_STATUS=./config.status}
|
||||
ac_write_fail=0
|
||||
|
@ -380,7 +380,9 @@ esac
|
||||
|
||||
AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h)
|
||||
AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
|
||||
AC_CHECK_FUNCS(srandom random strsignal)
|
||||
|
||||
AC_CHECK_FUNCS(srandom random strerror_r strsignal)
|
||||
AM_CONDITIONAL(HAVE_STRERROR_R, test "$ac_cv_func_strerror_r" = yes)
|
||||
|
||||
AC_CACHE_CHECK([for __sync_bool_compare_and_swap_4],
|
||||
[libgo_cv_func___sync_bool_compare_and_swap_4],
|
||||
|
32
libgo/syscalls/errstr_nor.go
Normal file
32
libgo/syscalls/errstr_nor.go
Normal file
@ -0,0 +1,32 @@
|
||||
// errstr.go -- Error strings when there is no strerror_r.
|
||||
|
||||
// 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.
|
||||
|
||||
package syscall
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func libc_strerror(int) *byte __asm__ ("strerror")
|
||||
|
||||
var errstr_lock sync.Mutex
|
||||
|
||||
func Errstr(errno int) string {
|
||||
errstr_lock.Lock()
|
||||
|
||||
bp := libc_strerror(errno)
|
||||
b := (*[1000]byte)(unsafe.Pointer(bp))
|
||||
i := 0
|
||||
for b[i] != 0 {
|
||||
i++
|
||||
}
|
||||
s := string(b[:i])
|
||||
|
||||
errstr_lock.Unlock()
|
||||
|
||||
return s
|
||||
}
|
Loading…
Reference in New Issue
Block a user