Moved VG_(resolve_filename{,_nodup}) from m_syswrap into m_libcfile,
so that m_aspacemgr doesn't depend on m_syswrap any more.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3960 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index 0c4208e..cf9dcc5 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -35,14 +35,13 @@
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
-#include "pub_core_libcfile.h"      // For VG_(fstat)()
+#include "pub_core_libcfile.h"
 #include "pub_core_libcmman.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_libcproc.h"
 #include "pub_core_mallocfree.h"
 #include "pub_core_options.h"
 #include "pub_core_syscall.h"
-#include "pub_core_syswrap.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_transtab.h"
 #include "vki_unistd.h"
diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c
index 0f4e6c1..44dd086 100644
--- a/coregrind/m_libcfile.c
+++ b/coregrind/m_libcfile.c
@@ -32,6 +32,7 @@
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcfile.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_mallocfree.h"
 #include "pub_core_options.h"
 #include "pub_core_syscall.h"
@@ -69,6 +70,36 @@
    return newfd;
 }
 
+/* Given a file descriptor, attempt to deduce its filename.  To do
+   this, we use /proc/self/fd/<FD>.  If this doesn't point to a file,
+   or if it doesn't exist, we just return NULL.  The caller is
+   responsible for copying the contents of buf out immediately. */
+static HChar resolve_filename_buf[VKI_PATH_MAX];
+HChar* VG_(resolve_filename_nodup) ( Int fd )
+{
+   HChar tmp[64];
+
+   VG_(sprintf)(tmp, "/proc/self/fd/%d", fd);
+   VG_(memset)(resolve_filename_buf, 0, VKI_PATH_MAX);
+
+   if (VG_(readlink)(tmp, resolve_filename_buf, VKI_PATH_MAX) == -1)
+      return NULL;
+
+   return (resolve_filename_buf[0] == '/') 
+             ? resolve_filename_buf 
+             : NULL;
+}
+
+/* Same as resolve_filename_nodup, except that the result is copied 
+   into new memory which the caller is responsible for freeing. */
+HChar* VG_(resolve_filename) ( Int fd )
+{
+   HChar* transient = VG_(resolve_filename_nodup)(fd);
+   return transient
+             ? VG_(arena_strdup)(VG_AR_CORE, transient)
+             : NULL;
+}
+
 /* Returns -1 on failure. */
 Int VG_(open) ( const Char* pathname, Int flags, Int mode )
 {  
diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c
index ad719a7..44e4ba1 100644
--- a/coregrind/m_syswrap/syswrap-generic.c
+++ b/coregrind/m_syswrap/syswrap-generic.c
@@ -286,7 +286,6 @@
    ------------------------------------------------------------------ */
 
 /* One of these is allocated for each open file descriptor.  */
-
 typedef struct OpenFd
 {
    Int fd;                        /* The file descriptor */
@@ -296,51 +295,13 @@
 } OpenFd;
 
 /* List of allocated file descriptors. */
-
 static OpenFd *allocated_fds;
 
 /* Count of open file descriptors. */
-
 static int fd_count = 0;
 
 
-
-/* Given a file descriptor, attempt to deduce its filename.  To do
-   this, we use /proc/self/fd/<FD>.  If this doesn't point to a file,
-   or if it doesn't exist, we just return NULL.  The caller is
-   responsible for copying the contents of buf out immediately. */
-
-static HChar resolve_filename_buf[VKI_PATH_MAX];
-
-HChar* VG_(resolve_filename_nodup) ( Int fd )
-{
-   HChar tmp[64];
-
-   VG_(sprintf)(tmp, "/proc/self/fd/%d", fd);
-   VG_(memset)(resolve_filename_buf, 0, VKI_PATH_MAX);
-
-   if (VG_(readlink)(tmp, resolve_filename_buf, VKI_PATH_MAX) == -1)
-      return NULL;
-
-   return (resolve_filename_buf[0] == '/') 
-             ? resolve_filename_buf 
-             : NULL;
-}
-
-/* Same as resolve_filename_nodup, except that the result is copied 
-   into new memory which the caller is responsible for freeing. */
-
-HChar* VG_(resolve_filename) ( Int fd )
-{
-   HChar* transient = VG_(resolve_filename_nodup)(fd);
-   return transient
-             ? VG_(arena_strdup)(VG_AR_CORE, transient)
-             : NULL;
-}
-
-
 /* Note the fact that a file descriptor was just closed. */
-
 static
 void record_fd_close(ThreadId tid, Int fd)
 {
@@ -373,7 +334,6 @@
    some such thing) or that we don't know the filename.  If the fd is
    already open, then we're probably doing a dup2() to an existing fd,
    so just overwrite the existing one. */
-
 void VG_(record_fd_open)(ThreadId tid, Int fd, char *pathname)
 {
    OpenFd *i;
diff --git a/coregrind/pub_core_libcfile.h b/coregrind/pub_core_libcfile.h
index 740fa95..b0457dc 100644
--- a/coregrind/pub_core_libcfile.h
+++ b/coregrind/pub_core_libcfile.h
@@ -46,6 +46,10 @@
 extern Int VG_(safe_fd) ( Int oldfd );
 extern Int VG_(fcntl)   ( Int fd, Int cmd, Int arg );
 
+/* Convert an fd into a filename */
+extern HChar* VG_(resolve_filename_nodup) ( Int fd );
+extern HChar* VG_(resolve_filename)       ( Int fd );
+
 /* Default destination port to be used in logging over a network, if
    none specified. */
 #define VG_CLO_DEFAULT_LOGPORT 1500
diff --git a/coregrind/pub_core_syswrap.h b/coregrind/pub_core_syswrap.h
index f5aaeaf..493f9a4 100644
--- a/coregrind/pub_core_syswrap.h
+++ b/coregrind/pub_core_syswrap.h
@@ -43,9 +43,6 @@
 // as if the thread had been set up by clone()
 extern void VGP_(main_thread_wrapper_NORETURN)(ThreadId tid);
 
-extern HChar* VG_(resolve_filename_nodup)(Int fd);
-extern HChar* VG_(resolve_filename)(Int fd);
-
 extern void VG_(client_syscall) ( ThreadId tid );
 
 extern void VG_(post_syscall)   ( ThreadId tid );