X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/29a3b2869c0075fc75e8ccc66fc1d9c4c8bf6a85..9dec3b0501e4464e246196d29dce6d03a6cbd2d7:/src/smpi/internals/smpi_global.cpp diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 65bfc09ca4..5a9137953c 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -15,6 +15,8 @@ #include #include /* DBL_MAX */ +#include +#include /* intmax_t */ #include #include #include @@ -29,7 +31,7 @@ # define MAC_OS_X_VERSION_10_12 101200 # endif # define HAVE_WORKING_MMAP (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12) -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) # define HAVE_WORKING_MMAP 0 #else # define HAVE_WORKING_MMAP 1 @@ -489,31 +491,36 @@ static void smpi_copy_file(std::string src, std::string target, off_t fdin_size) int fdout = open(target.c_str(), O_CREAT | O_RDWR, S_IRWXU); xbt_assert(fdout >= 0, "Cannot write into %s", target.c_str()); - XBT_DEBUG("Copy %ld bytes into %s", static_cast(fdin_size), target.c_str()); + XBT_DEBUG("Copy %" PRIdMAX " bytes into %s", static_cast(fdin_size), target.c_str()); + bool slow_copy = true; #if HAVE_SENDFILE ssize_t sent_size = sendfile(fdout, fdin, NULL, fdin_size); - xbt_assert(sent_size == fdin_size, "Error while copying %s: only %zd bytes copied instead of %ld (errno: %d -- %s)", - target.c_str(), sent_size, fdin_size, errno, strerror(errno)); -#else - const int bufsize = 1024 * 1024 * 4; - char buf[bufsize]; - while (int got = read(fdin, buf, bufsize)) { - if (got == -1) { - xbt_assert(errno == EINTR, "Cannot read from %s", src.c_str()); - } else { - char* p = buf; - int todo = got; - while (int done = write(fdout, p, todo)) { - if (done == -1) { - xbt_assert(errno == EINTR, "Cannot write into %s", target.c_str()); - } else { - p += done; - todo -= done; + if (sent_size == fdin_size) + slow_copy = false; + else if (sent_size != -1 || errno != ENOSYS) + xbt_die("Error while copying %s: only %zd bytes copied instead of %" PRIdMAX " (errno: %d -- %s)", target.c_str(), + sent_size, static_cast(fdin_size), errno, strerror(errno)); +#endif + if (slow_copy) { + const int bufsize = 1024 * 1024 * 4; + char buf[bufsize]; + while (int got = read(fdin, buf, bufsize)) { + if (got == -1) { + xbt_assert(errno == EINTR, "Cannot read from %s", src.c_str()); + } else { + char* p = buf; + int todo = got; + while (int done = write(fdout, p, todo)) { + if (done == -1) { + xbt_assert(errno == EINTR, "Cannot write into %s", target.c_str()); + } else { + p += done; + todo -= done; + } } } } } -#endif close(fdin); close(fdout); }