A commit which is almost all trivial change.

- m_main: if --log-file-qualifier applies, do not add ".pid"
  at the end of the name

- Fix the logic which detected whether the just-devised name
  already existed.  This was broken (by me) because it could not
  distinguish the reasons for failing to open the logfile.

  Doing this required changing the return type of VG_(open)
  from Int to SysRes (to make failure reasons visible) and 
  that's the cause of most of the changes.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4228 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/massif/ms_main.c b/massif/ms_main.c
index f436d0f..95d1566 100644
--- a/massif/ms_main.c
+++ b/massif/ms_main.c
@@ -1345,12 +1345,13 @@
  */
 static void write_hp_file(void)
 {
-   Int   i, j;
-   Int   fd, res;
-   Char *hp_file, *ps_file, *aux_file;
-   Char* cmdfmt;
-   Char* cmdbuf;
-   Int   cmdlen;
+   Int    i, j;
+   Int    fd, res;
+   SysRes sres;
+   Char  *hp_file, *ps_file, *aux_file;
+   Char*  cmdfmt;
+   Char*  cmdbuf;
+   Int    cmdlen;
 
    VGP_PUSHCC(VgpPrintHp);
    
@@ -1358,12 +1359,14 @@
    hp_file  = make_filename( base_dir, ".hp" );
    ps_file  = make_filename( base_dir, ".ps" );
    aux_file = make_filename( base_dir, ".aux" );
-   fd = VG_(open)(hp_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
-                           VKI_S_IRUSR|VKI_S_IWUSR);
-   if (fd < 0) {
+   sres = VG_(open)(hp_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
+                             VKI_S_IRUSR|VKI_S_IWUSR);
+   if (sres.isError) {
       file_err( hp_file );
       VGP_POPCC(VgpPrintHp);
       return;
+   } else {
+      fd = sres.val;
    }
 
    // File header, including command line
@@ -1658,9 +1661,10 @@
 static void
 write_text_file(ULong total_ST, ULong heap_ST)
 {
-   Int   fd, i;
-   Char* text_file;
-   Char* maybe_p = ( XHTML == clo_format ? "<p>" : "" );
+   SysRes sres;
+   Int    fd, i;
+   Char*  text_file;
+   Char*  maybe_p = ( XHTML == clo_format ? "<p>" : "" );
 
    VGP_PUSHCC(VgpPrintXPts);
 
@@ -1668,12 +1672,14 @@
    text_file = make_filename( base_dir, 
                               ( XText == clo_format ? ".txt" : ".html" ) );
 
-   fd = VG_(open)(text_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
+   sres = VG_(open)(text_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
                              VKI_S_IRUSR|VKI_S_IWUSR);
-   if (fd < 0) {
+   if (sres.isError) {
       file_err( text_file );
       VGP_POPCC(VgpPrintXPts);
       return;
+   } else {
+      fd = sres.val;
    }
 
    // Header