On 12/06/2013 07:42 PM, [email protected] wrote: > Hi! >> If utimensat(2) is not defined on the platform we switch >> to using utimes(2). >> >> Signed-off-by: Stanislav Kholmanskikh <[email protected]> >> --- >> include/safe_file_ops.h | 1 + >> lib/safe_file_ops.c | 53 >> +++++++++++++++++++++++++++++++++++++++++++++- >> 2 files changed, 52 insertions(+), 2 deletions(-) >> >> diff --git a/include/safe_file_ops.h b/include/safe_file_ops.h >> index 77ad594..1815984 100644 >> --- a/include/safe_file_ops.h >> +++ b/include/safe_file_ops.h >> @@ -36,6 +36,7 @@ >> >> #include <sys/stat.h> >> >> +#include "lapi/utime.h" >> #include "test.h" >> >> /* >> diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c >> index 8cfd264..f9c316d 100644 >> --- a/lib/safe_file_ops.c >> +++ b/lib/safe_file_ops.c >> @@ -21,11 +21,15 @@ >> * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >> */ >> >> +#include "config.h" >> #include <stdarg.h> >> #include <stdio.h> >> +#include <sys/time.h> >> #include <sys/types.h> >> #include <sys/stat.h> >> #include <fcntl.h> >> +#include <unistd.h> >> +#include <utime.h> >> >> #include "safe_file_ops.h" >> >> @@ -69,6 +73,22 @@ static int count_scanf_conversions(const char *fmt) >> return cnt; >> } >> >> +static void set_time(struct timeval *res, struct timespec *src, >> + long cur_tv_sec, long cur_tv_usec) >> +{ >> + switch (src->tv_nsec) { >> + case UTIME_NOW: >> + break; >> + case UTIME_OMIT: >> + res->tv_sec = cur_tv_sec; >> + res->tv_usec = cur_tv_usec; >> + break; >> + default: >> + res->tv_sec = src->tv_sec; >> + res->tv_usec = src->tv_nsec / 1000; >> + } >> +} > > I've added an #ifndef HAVE_UTIMENSAT around this block, because > otherwise we will get unused function warning when HAVE_UTIMENSAT is > defined. > >> void safe_file_scanf(const char *file, const int lineno, >> void (*cleanup_fn) (void), >> const char *path, const char *fmt, ...) >> @@ -186,10 +206,39 @@ void safe_touch(const char *file, const int lineno, >> pathname, file, lineno); >> } >> >> + >> +#if HAVE_UTIMENSAT >> ret = utimensat(AT_FDCWD, pathname, times, 0); >> +#else >> + if (times == NULL) { >> + ret = utimes(pathname, NULL); >> + } else { >> + struct stat sb; >> + struct timeval cotimes[2]; >> + >> + ret = stat(pathname, &sb); >> + if (ret == -1) >> + tst_brkm(TBROK | TERRNO, cleanup_fn, >> + "Failed to stat file '%s' at %s:%d", >> + pathname, file, lineno); >> + >> + ret = gettimeofday(cotimes, NULL); >> + if (ret == -1) >> + tst_brkm(TBROK | TERRNO, cleanup_fn, >> + "Failed to gettimeofday() at %s:%d", >> + file, lineno); >> + cotimes[1] = cotimes[0]; >> + >> + set_time(cotimes, times, >> + sb.st_atime, sb.st_atim.tv_nsec / 1000); >> + set_time(cotimes + 1, times + 1, >> + sb.st_mtime, sb.st_mtim.tv_nsec / 1000); >> + >> + ret = utimes(pathname, cotimes); >> + } >> +#endif >> if (ret == -1) >> tst_brkm(TBROK | TERRNO, cleanup_fn, >> - "Failed to do utimensat() on file '%s' at %s:%d", >> + "Failed to update the access/modification times on file >> '%s' at %s:%d", > > And I've also fixed this line to fit into 80 chars. > > Pushed, thanks. >
Thank you. ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
