Browse Source

make futimes crossplatform

pull/301/head
Antonio SJ Musumeci 8 years ago
parent
commit
49474f01ca
  1. 6
      src/fs_clonefile.cpp
  2. 21
      src/fs_time.cpp
  3. 22
      src/fs_time.hpp
  4. 33
      src/fs_time_futimens.icpp
  5. 33
      src/fs_time_futimes.icpp

6
src/fs_clonefile.cpp

@ -27,6 +27,7 @@
#include "fs_attr.hpp"
#include "fs_fallocate.hpp"
#include "fs_sendfile.hpp"
#include "fs_time.hpp"
#include "fs_xattr.hpp"
using std::string;
@ -168,10 +169,7 @@ namespace fs
if(rv == -1)
return -1;
struct timespec times[2];
times[0] = stin.st_atim;
times[1] = stin.st_mtim;
rv = ::futimens(fdout,times);
rv = fs::utimes(fdout,stin);
if(rv == -1)
return -1;

21
src/fs_time.cpp

@ -0,0 +1,21 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
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
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef __linux__
# include "fs_time_futimens.icpp"
#else
# include "fs_time_futimes.icpp"
#endif

22
src/fs_time.hpp

@ -0,0 +1,22 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
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
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
namespace fs
{
int
utimes(const int fd,
const struct stat &st);
}

33
src/fs_time_futimens.icpp

@ -0,0 +1,33 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
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
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <fcntl.h>
#include <sys/stat.h>
namespace fs
{
int
utimes(const int fd,
const struct stat &st)
{
struct timespec times[2];
times[0] = st.st_atim;
times[1] = st.st_mtim;
return ::futimens(fd,times);
}
}

33
src/fs_time_futimes.icpp

@ -0,0 +1,33 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
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
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/stat.h>
#include <sys/time.h>
namespace fs
{
int
utimes(const int fd,
const struct stat &st)
{
struct timeval times[2];
TIMESPEC_TO_TIMEVAL(&times[0],&st.st_atimespec);
TIMESPEC_TO_TIMEVAL(&times[1],&st.st_mtimespec);
return ::futimes(fd,times);
}
}
Loading…
Cancel
Save