PATCH: Adjust for more Windows oddities

Mark Mitchell
2005-03-16T16:37:27Z

Windows does not have getuid or getgid, so I've added autoconf checks
for those functions. There is also no "st_blksize" member in "struct
stat". Technically, this patch should perhaps be two separate
patches, but since the code modified in remote-fileio.c was all in the
same place, I've submitted it as one patch.

Tested on x86_64-unknown-linux-gnu. OK to apply?

(After this patch, we'll be on to the "good part".)

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-03-16 Mark Mitchell <mark@codesourcery.com>

* configure.ac (stat.st_blksize): Check for it.
(getuid): Likewise.
(getgid): Likewise.
* configure: Regenerated.
* config.in: Likewise.
* remote-fileio.c (remote_fileio_to_fio_stat): Check
HAVE_STRUCT_STAT_ST_BLKSIZE.

Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.14
diff -c -5 -p -r1.14 configure.ac
*** configure.ac 13 Mar 2005 05:37:48 -0000 1.14
--- configure.ac 16 Mar 2005 16:30:21 -0000
*************** AC_CHECK_DECLS(getopt)
*** 423,432 ****
--- 423,433 ----
# ----------------------- #
# Checks for structures. #
# ----------------------- #

AC_CHECK_MEMBERS([struct stat.st_blocks])
+ AC_CHECK_MEMBERS([struct stat.st_blksize])

# ------------------ #
# Checks for types. #
# ------------------ #

*************** AC_C_INLINE
*** 445,454 ****
--- 446,456 ----

AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_FUNC_VFORK
AC_CHECK_FUNCS(canonicalize_file_name realpath)
+ AC_CHECK_FUNCS(getuid getgid)
AC_CHECK_FUNCS(poll)
AC_CHECK_FUNCS(pread64)
AC_CHECK_FUNCS(sbrk)
AC_CHECK_FUNCS(setpgid setpgrp)
AC_CHECK_FUNCS(sigaction sigprocmask sigsetmask)
Index: remote-fileio.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-fileio.c,v
retrieving revision 1.13
diff -c -5 -p -r1.13 remote-fileio.c
*** remote-fileio.c 16 Mar 2005 15:58:41 -0000 1.13
--- remote-fileio.c 16 Mar 2005 16:30:21 -0000
*************** remote_fileio_to_fio_ulong (LONGEST num,
*** 415,441 ****
}

static void
remote_fileio_to_fio_stat (struct stat *st, struct fio_stat *fst)
{
/* `st_dev' is set in the calling function */
remote_fileio_to_fio_uint ((long) st->st_ino, fst->fst_ino);
remote_fileio_to_fio_mode (st->st_mode, fst->fst_mode);
remote_fileio_to_fio_uint ((long) st->st_nlink, fst->fst_nlink);
remote_fileio_to_fio_uint ((long) st->st_uid, fst->fst_uid);
remote_fileio_to_fio_uint ((long) st->st_gid, fst->fst_gid);
remote_fileio_to_fio_uint ((long) st->st_rdev, fst->fst_rdev);
remote_fileio_to_fio_ulong ((LONGEST) st->st_size, fst->fst_size);
! remote_fileio_to_fio_ulong ((LONGEST) st->st_blksize, fst->fst_blksize);
#if HAVE_STRUCT_STAT_ST_BLOCKS
remote_fileio_to_fio_ulong ((LONGEST) st->st_blocks, fst->fst_blocks);
#else
/* FIXME: This is correct for DJGPP, but other systems that don't
have st_blocks, if any, might prefer 512 instead of st_blksize.
(eliz, 30-12-2003) */
! remote_fileio_to_fio_ulong (((LONGEST) st->st_size + st->st_blksize - 1)
! / (LONGEST) st->st_blksize,
fst->fst_blocks);
#endif
remote_fileio_to_fio_time (st->st_atime, fst->fst_atime);
remote_fileio_to_fio_time (st->st_mtime, fst->fst_mtime);
remote_fileio_to_fio_time (st->st_ctime, fst->fst_ctime);
--- 415,448 ----
}

static void
remote_fileio_to_fio_stat (struct stat *st, struct fio_stat *fst)
{
+ LONGEST blksize;
+
/* `st_dev' is set in the calling function */
remote_fileio_to_fio_uint ((long) st->st_ino, fst->fst_ino);
remote_fileio_to_fio_mode (st->st_mode, fst->fst_mode);
remote_fileio_to_fio_uint ((long) st->st_nlink, fst->fst_nlink);
remote_fileio_to_fio_uint ((long) st->st_uid, fst->fst_uid);
remote_fileio_to_fio_uint ((long) st->st_gid, fst->fst_gid);
remote_fileio_to_fio_uint ((long) st->st_rdev, fst->fst_rdev);
remote_fileio_to_fio_ulong ((LONGEST) st->st_size, fst->fst_size);
! #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
! blksize = st->st_blksize;
! #else
! blksize = 512;
! #endif
! remote_fileio_to_fio_ulong (blksize, fst->fst_blksize);
#if HAVE_STRUCT_STAT_ST_BLOCKS
remote_fileio_to_fio_ulong ((LONGEST) st->st_blocks, fst->fst_blocks);
#else
/* FIXME: This is correct for DJGPP, but other systems that don't
have st_blocks, if any, might prefer 512 instead of st_blksize.
(eliz, 30-12-2003) */
! remote_fileio_to_fio_ulong (((LONGEST) st->st_size + blksize - 1)
! / blksize,
fst->fst_blocks);
#endif
remote_fileio_to_fio_time (st->st_atime, fst->fst_atime);
remote_fileio_to_fio_time (st->st_mtime, fst->fst_mtime);
remote_fileio_to_fio_time (st->st_ctime, fst->fst_ctime);
*************** remote_fileio_func_fstat (char *buf)
*** 1148,1162 ****
--- 1155,1179 ----
if (fd == FIO_FD_CONSOLE_IN || fd == FIO_FD_CONSOLE_OUT)
{
remote_fileio_to_fio_uint (1, fst.fst_dev);
st.st_mode = S_IFCHR | (fd == FIO_FD_CONSOLE_IN ? S_IRUSR : S_IWUSR);
st.st_nlink = 1;
+ #if HAVE_GETUID
st.st_uid = getuid ();
+ #else
+ st.st_uid = 0;
+ #endif
+ #if HAVE_GETGID
st.st_gid = getgid ();
+ #else
+ st.st_gid = 0;
+ #endif
st.st_rdev = 0;
st.st_size = 0;
+ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
st.st_blksize = 512;
+ #endif
#if HAVE_STRUCT_STAT_ST_BLOCKS
st.st_blocks = 0;
#endif
if (!gettimeofday (&tv, NULL))
st.st_atime = st.st_mtime = st.st_ctime = tv.tv_sec;