|
From: <sv...@va...> - 2005-09-13 13:30:44
|
Author: tom
Date: 2005-09-13 14:30:38 +0100 (Tue, 13 Sep 2005)
New Revision: 4640
Log:
Implement VG_(fsize) as a restricted version of VG_(fstat) that only
returns the size and use it in the command line module when we want
the size of the .valgrindrc file.
This allows the launcher to provide VG_(fsize) instead of VG_(fstat)
which removed the assumption that the glibc stat structure matches the
kernel stat structure without having to do a full translation from one
to the other.
Modified:
branches/ASPACEM/coregrind/m_commandline.c
branches/ASPACEM/coregrind/m_launcher.c
branches/ASPACEM/coregrind/m_libcfile.c
branches/ASPACEM/coregrind/pub_core_libcfile.h
Modified: branches/ASPACEM/coregrind/m_commandline.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_commandline.c 2005-09-13 12:45:13 UTC (r=
ev 4639)
+++ branches/ASPACEM/coregrind/m_commandline.c 2005-09-13 13:30:38 UTC (r=
ev 4640)
@@ -44,7 +44,7 @@
{
Int n;
SysRes fd;
- struct vki_stat s1;
+ Int size;
Char* f_clo =3D NULL;
Char filename[VKI_PATH_MAX];
=20
@@ -52,10 +52,10 @@
( NULL =3D=3D dir ? "" : dir ) );
fd =3D VG_(open)(filename, 0, VKI_S_IRUSR);
if ( !fd.isError ) {
- if ( 0 =3D=3D VG_(fstat)(fd.val, &s1) ) {
- f_clo =3D VG_(malloc)(s1.st_size+1);
+ if ( 0 =3D=3D (size =3D VG_(fsize)(fd.val)) ) {
+ f_clo =3D VG_(malloc)(size+1);
vg_assert(f_clo);
- n =3D VG_(read)(fd.val, f_clo, s1.st_size);
+ n =3D VG_(read)(fd.val, f_clo, size);
if (n =3D=3D -1) n =3D 0;
f_clo[n] =3D '\0';
}
Modified: branches/ASPACEM/coregrind/m_launcher.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_launcher.c 2005-09-13 12:45:13 UTC (rev =
4639)
+++ branches/ASPACEM/coregrind/m_launcher.c 2005-09-13 13:30:38 UTC (rev =
4640)
@@ -159,9 +159,10 @@
return read(fd, buf, count);
}
=20
-Int VG_(fstat) ( Int fd, struct vki_stat* buf )
+Int VG_(fsize) ( Int fd )
{
- return fstat(fd, buf);
+ struct stat buf;
+ return fstat(fd, &buf) =3D=3D 0 ? buf.st_size : (-1);
}
=20
UInt VG_(snprintf) ( Char* buf, Int size, const HChar *format, ... )
Modified: branches/ASPACEM/coregrind/m_libcfile.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_libcfile.c 2005-09-13 12:45:13 UTC (rev =
4639)
+++ branches/ASPACEM/coregrind/m_libcfile.c 2005-09-13 13:30:38 UTC (rev =
4640)
@@ -133,6 +133,13 @@
return res.isError ? (-1) : 0;
}
=20
+Int VG_(fsize) ( Int fd )
+{
+ struct vki_stat buf;
+ SysRes res =3D VG_(do_syscall2)(__NR_fstat, fd, (UWord)&buf);
+ return res.isError ? (-1) : buf.st_size;
+}
+
Int VG_(dup2) ( Int oldfd, Int newfd )
{
SysRes res =3D VG_(do_syscall2)(__NR_dup2, oldfd, newfd);
Modified: branches/ASPACEM/coregrind/pub_core_libcfile.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/pub_core_libcfile.h 2005-09-13 12:45:13 UT=
C (rev 4639)
+++ branches/ASPACEM/coregrind/pub_core_libcfile.h 2005-09-13 13:30:38 UT=
C (rev 4640)
@@ -49,6 +49,9 @@
/* Convert an fd into a filename */
extern Bool VG_(resolve_filename) ( Int fd, HChar* buf, Int n_buf );
=20
+/* Return the size of a file */
+extern Int VG_(fsize) ( Int fd );
+
/* Default destination port to be used in logging over a network, if
none specified. */
#define VG_CLO_DEFAULT_LOGPORT 1500
|