sim/common/callback.c: autoconf tests for struct stat members, more added.
Hans-Peter Nilsson
hans-peter.nilsson@axis.com
Thu Dec 2 17:53:00 GMT 2004
I have a need for more of the GNU/Linux struct stat members. At
the same time, it looked like adding them would plausibly break
some non-GNU/Linux hosts, which I guess is the reason there were
only two st_ino and st_dev present in cb_host_to_target_stat.
All would have been *much* simpler if sim/common used a modern
autoconf (with AC_CHECK_MEMBERS), because then I wouldn't have
to translate that macro into something that works with
autoconf-2.13. Pain. :-( Arguably some st_* members possibly
don't translate very well to a simulated environment, but that's
up to the user of the simulator to decide. Regrettably, I did
not find a way to make the cb_host_to_target_stat more agreeable
to the eye. Tested by observing that a few more of my C-based
simulator tests (developed without the st_* #ifdefs) now pass,
and testing that configuring a non-present struct stat member
works.
Ok to commit?
sim/common:
* configure.in (SIM_CHECK_MEMBERS): Call for struct stat members
st_dev, st_ino, st_mode, st_nlink, st_uid, st_gid, st_rdev,
st_size, st_blksize, st_blocks, st_atime, st_mtime and st_ctime.
* aclocal.m4 (SIM_CHECK_MEMBER, SIM_CHECK_MEMBERS_1)
(SIM_CHECK_MEMBERS): New macros.
* callback.c (cb_host_to_target_stat): Use temporary macro ST_x
for struct stat member test and write. Add ST_x calls for each
struct stat member tested in configure.in. Wrap each ST_x call in
#ifdef of configure macro for that member.
* configure, config.in: Regenerate.
Index: configure.in
===================================================================
RCS file: /cvs/src/src/sim/common/configure.in,v
retrieving revision 1.2
diff -c -p -r1.2 configure.in
*** configure.in 20 Mar 2001 17:13:39 -0000 1.2
--- configure.in 2 Dec 2004 17:21:08 -0000
*************** AC_SUBST(TARGET_SUBDIR)
*** 36,41 ****
# These aren't all needed yet, but will be eventually.
AC_CHECK_HEADERS(stdlib.h string.h strings.h time.h sys/times.h sys/stat.h sys/mman.h)
AC_CHECK_FUNCS(mmap munmap)
!
AC_OUTPUT(Makefile,
[case x$CONFIG_HEADERS in xcconfig.h:config.in) echo > stamp-h ;; esac])
--- 36,45 ----
# These aren't all needed yet, but will be eventually.
AC_CHECK_HEADERS(stdlib.h string.h strings.h time.h sys/times.h sys/stat.h sys/mman.h)
AC_CHECK_FUNCS(mmap munmap)
! SIM_CHECK_MEMBERS([[struct stat.st_dev], [struct stat.st_ino],
! [struct stat.st_mode], [struct stat.st_nlink], [struct stat.st_uid],
! [struct stat.st_gid], [struct stat.st_rdev], [struct stat.st_size],
! [struct stat.st_blksize], [struct stat.st_blocks], [struct stat.st_atime],
! [struct stat.st_mtime], [struct stat.st_ctime]])
AC_OUTPUT(Makefile,
[case x$CONFIG_HEADERS in xcconfig.h:config.in) echo > stamp-h ;; esac])
Index: callback.c
===================================================================
RCS file: /cvs/src/src/sim/common/callback.c,v
retrieving revision 1.10
diff -c -p -r1.10 callback.c
*** callback.c 27 Jun 2004 03:14:51 -0000 1.10
--- callback.c 2 Dec 2004 17:49:41 -0000
*************** cb_host_to_target_stat (cb, hs, ts)
*** 816,825 ****
if (hs != NULL)
{
! if (strncmp (m, "st_dev", q - m) == 0)
! store (p, size, hs->st_dev, big_p);
! else if (strncmp (m, "st_ino", q - m) == 0)
! store (p, size, hs->st_ino, big_p);
/* FIXME:wip */
else
store (p, size, 0, big_p); /* unsupported field, store 0 */
--- 816,869 ----
if (hs != NULL)
{
! if (1)
! ;
! /* Defined here to avoid emacs indigestion on a lone "else". */
! #undef ST_x
! #define ST_x(FLD) \
! else if (strncmp (m, #FLD, q - m) == 0) \
! store (p, size, hs->FLD, big_p)
!
! #ifdef HAVE_STRUCT_STAT_ST_DEV
! ST_x (st_dev);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_INO
! ST_x (st_ino);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_MODE
! ST_x (st_mode);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_NLINK
! ST_x (st_nlink);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_UID
! ST_x (st_uid);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_GID
! ST_x (st_gid);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_RDEV
! ST_x (st_rdev);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_SIZE
! ST_x (st_size);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
! ST_x (st_blksize);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
! ST_x (st_blocks);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_ATIME
! ST_x (st_atime);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_MTIME
! ST_x (st_mtime);
! #endif
! #ifdef HAVE_STRUCT_STAT_ST_CTIME
! ST_x (st_ctime);
! #endif
! #undef ST_x
/* FIXME:wip */
else
store (p, size, 0, big_p); /* unsupported field, store 0 */
Index: aclocal.m4
===================================================================
RCS file: /cvs/src/src/sim/common/aclocal.m4,v
retrieving revision 1.5
diff -c -p -r1.5 aclocal.m4
*** aclocal.m4 16 Jun 2002 16:33:12 -0000 1.5
--- aclocal.m4 2 Dec 2004 17:21:07 -0000
*************** AC_SUBST(CGEN_MAINT)
*** 1257,1259 ****
--- 1257,1327 ----
AC_SUBST(cgendir)
AC_SUBST(cgen)
])
+ dnl FIXME: When upgrading to modern autoconf, remove
+ dnl SIM_CHECK_MEMBER and SIM_CHECK_MEMBERS et al and use
+ dnl AC_CHECK_MEMBERS from autoconf.
+ dnl
+ dnl Translated from a FC2 autoconf-2.59-3 installation.
+ dnl AC_CHECK_MEMBER(AGGREGATE.MEMBER,
+ dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
+ dnl [INCLUDES])
+ dnl
+ dnl ---------------------------------------------------------
+ dnl AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell
+ dnl variables are not a valid argument.
+ AC_DEFUN([SIM_CHECK_MEMBER],
+ dnl Extract the aggregate name, and the member name
+ [AC_CACHE_CHECK([for $1], [ac_]patsubst([$1], [[\. ]], [_]),
+ [ac_]patsubst([$1], [[\. ]], [_])[=no;]
+ AC_TRY_COMPILE([$4],[
+ dnl AGGREGATE ac_aggr;
+ static ]patsubst([$1], [\..*])[ ac_aggr;
+ dnl ac_aggr.MEMBER;
+ if (ac_aggr.]patsubst([$1], [^[^.]*\.])[)
+ return 0;],[ac_]patsubst([$1], [[\. ]], [_])[=yes;],
+ AC_TRY_COMPILE([$4],[
+ dnl AGGREGATE ac_aggr;
+ static ]patsubst([$1], [\..*])[ ac_aggr;
+ dnl ac_aggr.MEMBER;
+ if (sizeof ac_aggr.]patsubst([$1], [^[^.]*\.])[)
+ return 0;],
+ [ac_]patsubst([$1], [[\. ]], [_])[=yes;],
+ [ac_]patsubst([$1], [[\. ]], [_])[=no;]))
+ [if test [$]ac_]patsubst([$1], [[\. ]], [_])[ = yes; then :; [$2]
+ else :; [$3]
+ fi])
+ ])dnl SIM_CHECK_MEMBER
+ dnl
+ dnl Translated from a FC2 autoconf-2.59-3 installation.
+ dnl SIM_CHECK_MEMBERS([AGGREGATE.MEMBER, ...])
+ dnl except we just work with a limited set of fixed includes.
+ dnl
+ AC_DEFUN([SIM_CHECK_MEMBERS_1],
+ [ifelse($#, 1,
+ [SIM_CHECK_MEMBER([$1],
+ AC_DEFINE_UNQUOTED([HAVE_]translit([$1], [a-z .], [A-Z__]), 1,
+ [Define to 1 if ]patsubst([$1],
+ [^[^.]*\.])[ is a member of ]patsubst([$1], [\..*])[. ]),,
+ [#ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+ #endif
+ #ifdef HAVE_SYS_STAT_H
+ #include <sys/stat.h>
+ #endif])],
+ [SIM_CHECK_MEMBER([$1],
+ AC_DEFINE_UNQUOTED([HAVE_]translit([$1], [a-z .], [A-Z__]), 1,
+ [Define to 1 if ]patsubst([$1],
+ [^[^.]*\.])[ is a member of ]patsubst([$1], [\..*])[. ]),,
+ [#ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+ #endif
+ #ifdef HAVE_SYS_STAT_H
+ #include <sys/stat.h>
+ #endif])
+ SIM_CHECK_MEMBERS_1(builtin(shift,$@))])])dnl SIM_CHECK_MEMBERS
+ dnl
+ AC_DEFUN([SIM_CHECK_MEMBERS],
+ [ifelse($#, 1, [SIM_CHECK_MEMBERS_1($1)],
+ [errprint(__file__:__line__:
+ [This SIM_CHECK_MEMBERS only supports one argument,]
+ [the list of struct tests])])])dnl SIM_CHECK_MEMBERS
brgds, H-P
More information about the Gdb-patches
mailing list