summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-08-01 16:47:11 +1000
committerChris Johns <chrisj@rtems.org>2014-08-01 16:47:11 +1000
commit742866c4ac6e2f674971225d26052b9af22bd6b3 (patch)
treeeaed4a8325bd1d75fe9d2cb1230d4bcbd20f4452
parent30f0566b7f88462c794abf8d0edc2066ed9f90d7 (diff)
Fix building on Windows with the latest MSVC.
Remove some warnings.
-rw-r--r--rld-files.cpp1
-rw-r--r--rld-outputter.cpp29
-rw-r--r--rld-process.cpp29
3 files changed, 43 insertions, 16 deletions
diff --git a/rld-files.cpp b/rld-files.cpp
index e10abb5..63255b8 100644
--- a/rld-files.cpp
+++ b/rld-files.cpp
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
+#include <unistd.h>
#include <rld.h>
diff --git a/rld-outputter.cpp b/rld-outputter.cpp
index e6527eb..ff9032c 100644
--- a/rld-outputter.cpp
+++ b/rld-outputter.cpp
@@ -44,6 +44,24 @@ namespace rld
{
namespace outputter
{
+ int unlink (const char* path)
+ {
+#if _WIN32
+ return ::remove(path);
+#else
+ return ::unlink (path);
+#endif
+ }
+
+ int link (const char* path1, const char* path2)
+ {
+#if _WIN32
+ return ::rename(path1, path2);
+#else
+ return ::link (path1, path2);
+#endif
+ }
+
const std::string
script_text (const std::string& entry,
const std::string& exit,
@@ -259,23 +277,24 @@ namespace rld
{
if (ra_exist)
{
- std::string new_name = "rld_XXXXXX";
- struct stat sb;
+ std::string new_name = "rld_XXXXXX";
files::archive arch (new_name);
+ struct stat sb;
+
arch.create (objects);
if ((::stat (name.c_str (), &sb) >= 0) && S_ISREG (sb.st_mode))
{
- if (::unlink (name.c_str ()) < 0)
+ if (unlink (name.c_str ()) < 0)
std::cerr << "error: unlinking temp file: " << name << std::endl;
}
- if (::link (new_name.c_str (), name.c_str ()) < 0)
+ if (link (new_name.c_str (), name.c_str ()) < 0)
{
std::cerr << "error: linking temp file: " << name << std::endl;
}
if ((::stat (new_name.c_str (), &sb) >= 0) && S_ISREG (sb.st_mode))
{
- if (::unlink (new_name.c_str ()) < 0)
+ if (unlink (new_name.c_str ()) < 0)
std::cerr << "error: unlinking temp file: " << new_name << std::endl;
}
}
diff --git a/rld-process.cpp b/rld-process.cpp
index f73c434..5a20366 100644
--- a/rld-process.cpp
+++ b/rld-process.cpp
@@ -1,10 +1,10 @@
/*
- * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
+ * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
+#include <unistd.h>
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
@@ -66,7 +67,7 @@ namespace rld
{
clean_up ();
}
-
+
const std::string
temporary_files::get ()
{
@@ -88,7 +89,13 @@ namespace rld
struct stat sb;
if ((::stat (name.c_str (), &sb) >= 0) && S_ISREG (sb.st_mode))
{
- if (::unlink (name.c_str ()) < 0)
+ int r;
+#if _WIN32
+ r = ::remove(name.c_str ());
+#else
+ r = ::unlink (name.c_str ());
+#endif
+ if (r < 0)
{
std::cerr << "error: unlinking temp file: " << name << std::endl;
::exit (100);
@@ -159,7 +166,7 @@ namespace rld
}
}
- const std::string&
+ const std::string&
tempfile::name () const
{
return _name;
@@ -174,7 +181,7 @@ namespace rld
struct stat sb;
if (::stat (_name.c_str (), &sb) == 0)
return sb.st_size;
-
+
return 0;
}
@@ -242,7 +249,7 @@ namespace rld
}
void
- tempfile::output (const std::string& prefix,
+ tempfile::output (const std::string& prefix,
std::ostream& out,
bool line_numbers)
{
@@ -268,7 +275,7 @@ namespace rld
}
status
- execute (const std::string& pname,
+ execute (const std::string& pname,
const std::string& command,
const std::string& outname,
const std::string& errname)
@@ -279,7 +286,7 @@ namespace rld
}
status
- execute (const std::string& pname,
+ execute (const std::string& pname,
const arg_container& args,
const std::string& outname,
const std::string& errname)
@@ -345,7 +352,7 @@ namespace rld
}
else
throw rld::error ("execute: " + args[0], "unknown status returned");
-
+
return _status;
}
@@ -364,7 +371,7 @@ namespace rld
};
args.clear ();
-
+
const char quote = '"';
const char escape = '\\';
pstate state = pstate_discard_space;