source: rtems/cpukit/libcsupport/src/utimes.c

Last change on this file was ea881bf, checked in by Ryan Long <ryan.long@…>, on 04/28/21 at 16:44:29

libcsupport: Implement utimes() in terms of utimensat()

utimes() now calls utimensat() to update file access
and modification timestamps.

Updated license.

Closes #4398

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 *  @file
5 *
6 *  @ingroup libcsupport
7 *
8 *  @brief Set file access and modification times in milliseconds.
9 */
10
11/*
12 * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR).
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifdef HAVE_CONFIG_H
37#include "config.h"
38#endif
39
40#include <sys/time.h>
41#include <rtems/score/todimpl.h>
42
43#include <fcntl.h>
44
45/**
46 *  https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/futimens.html
47 *
48 *  Set file access and modification times
49 */
50int utimes(
51  const char           *path,
52  const struct timeval  times[2]
53)
54{
55  struct timespec new_times[2];
56
57  if ( times == NULL ) {
58    return utimensat( AT_FDCWD, path, NULL , 0 );
59  }
60
61  _Timespec_Set(
62    &new_times[0],
63    times[0].tv_sec,
64    times[0].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND
65  );
66  _Timespec_Set(
67    &new_times[1],
68    times[1].tv_sec,
69    times[1].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND
70  );
71
72  return utimensat( AT_FDCWD, path, new_times, 0 );
73}
Note: See TracBrowser for help on using the repository browser.