[git commit 0_9_30] futimens: add function

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Thu Dec 17 12:42:26 UTC 2009


commit: http://git.uclibc.org/uClibc/commit/?id=d16a040ddc577d111dee655d1f804f4f0d26244f
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/0_9_30

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 include/sys/stat.h                    |    1 +
 libc/sysdeps/linux/common/futimens.c  |   23 +++
 libc/sysdeps/linux/common/utimensat.c |    2 +
 test/.gitignore                       |  265 +++++++++++++++++++++++++++++++++
 test/time/tst-futimens1.c             |   90 +++++++++++
 5 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 libc/sysdeps/linux/common/futimens.c
 create mode 100644 test/.gitignore
 create mode 100644 test/time/tst-futimens1.c

diff --git a/include/sys/stat.h b/include/sys/stat.h
index 177f288..e2f4f8b 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -366,6 +366,7 @@ extern int utimensat (int __fd, __const char *__path,
 		      __const struct timespec __times[2],
 		      int __flags)
      __THROW __nonnull ((2));
+libc_hidden_proto(utimensat)
 #endif
 
 #ifdef __USE_XOPEN2K8
diff --git a/libc/sysdeps/linux/common/futimens.c b/libc/sysdeps/linux/common/futimens.c
new file mode 100644
index 0000000..090dfa6
--- /dev/null
+++ b/libc/sysdeps/linux/common/futimens.c
@@ -0,0 +1,23 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * futimens() implementation for uClibc
+ *
+ * Copyright (C) 2009 Bernhard Reutner-Fischer <uclibc at uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <sys/syscall.h>
+#define __need_timespec
+#include <time.h>
+#ifdef __NR_utimensat
+extern int utimensat (int __fd, __const char *__path,
+	__const struct timespec __times[2],
+	int __flags) __THROW;
+libc_hidden_proto(utimensat)
+
+int futimens (int fd, __const struct timespec ts[2])
+{
+	return utimensat(fd, 0, ts, 0);
+}
+#endif
diff --git a/libc/sysdeps/linux/common/utimensat.c b/libc/sysdeps/linux/common/utimensat.c
index 3c5af85..2cfb824 100644
--- a/libc/sysdeps/linux/common/utimensat.c
+++ b/libc/sysdeps/linux/common/utimensat.c
@@ -11,6 +11,8 @@
 
 #ifdef __NR_utimensat
 _syscall4(int, utimensat, int, fd, const char *, path, const struct timespec *, times, int, flags)
+libc_hidden_def(utimensat)
 #else
 /* should add emulation with utimens() and /proc/self/fd/ ... */
 #endif
+
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..1e7cd58
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1,265 @@
+#
+# Never ignore these
+#
+!.gitignore
+#
+# Generated files
+#
+*.out
+#
+# Executable test
+#
+*_glibc
+argp/argp-ex[1-4]
+argp/argp-test
+argp/bug-argp1
+argp/tst-argp[12]
+args/arg_test
+assert/assert
+crypt/crypt
+crypt/md5c-test
+ctype/ctype
+dlopen/dladdr
+dlopen/dlafk
+dlopen/dlstatic
+dlopen/dltest
+dlopen/dltest2
+dlopen/dlundef
+dlopen/libafk.so
+dlopen/libafk-temp.so
+dlopen/libstatic.so
+dlopen/libtest[123].so
+dlopen/libtest.so
+dlopen/libundef.so
+dlopen/test[1-3]
+inet/bug-if1
+inet/gethost_r-align
+inet/if_nameindex
+inet/tst-aton
+inet/tst-ethers
+inet/tst-ethers-line
+inet/tst-network
+inet/tst-ntoa
+librt/shmtest
+locale/bug-iconv-trans
+locale/collate-test
+locale/dump-ctype
+locale/gen-unicode-ctype
+locale-mbwc/tst_iswalnum
+locale-mbwc/tst_iswalpha
+locale-mbwc/tst_iswcntrl
+locale-mbwc/tst_iswctype
+locale-mbwc/tst_iswdigit
+locale-mbwc/tst_iswgraph
+locale-mbwc/tst_iswlower
+locale-mbwc/tst_iswprint
+locale-mbwc/tst_iswpunct
+locale-mbwc/tst_iswspace
+locale-mbwc/tst_iswupper
+locale-mbwc/tst_iswxdigit
+locale-mbwc/tst_mblen
+locale-mbwc/tst_mbrlen
+locale-mbwc/tst_mbrtowc
+locale-mbwc/tst_mbsrtowcs
+locale-mbwc/tst_mbstowcs
+locale-mbwc/tst_mbtowc
+locale-mbwc/tst_strcoll
+locale-mbwc/tst_strxfrm
+locale-mbwc/tst_swscanf
+locale-mbwc/tst_towctrans
+locale-mbwc/tst_towlower
+locale-mbwc/tst_towupper
+locale-mbwc/tst_wcrtomb
+locale-mbwc/tst_wcscat
+locale-mbwc/tst_wcschr
+locale-mbwc/tst_wcscmp
+locale-mbwc/tst_wcscoll
+locale-mbwc/tst_wcscpy
+locale-mbwc/tst_wcscspn
+locale-mbwc/tst_wcslen
+locale-mbwc/tst_wcsncat
+locale-mbwc/tst_wcsncmp
+locale-mbwc/tst_wcsncpy
+locale-mbwc/tst_wcspbrk
+locale-mbwc/tst_wcsrtombs
+locale-mbwc/tst_wcsspn
+locale-mbwc/tst_wcsstr
+locale-mbwc/tst_wcstod
+locale-mbwc/tst_wcstok
+locale-mbwc/tst_wcstombs
+locale-mbwc/tst_wcswidth
+locale-mbwc/tst_wcsxfrm
+locale-mbwc/tst_wctob
+locale-mbwc/tst_wctomb
+locale-mbwc/tst_wctrans
+locale-mbwc/tst_wctype
+locale-mbwc/tst_wcwidth
+locale/show-ucs-data
+locale/tst-digits
+locale/tst-langinfo
+locale/tst-mbswcs[1-6]
+locale/tst_nl_langinfo
+locale/tst-numeric
+locale/tst-setlocale
+locale/tst-sscanf
+locale/tst-trans
+locale/tst-wctype
+malloc/malloc
+malloc/mallocbug
+malloc/malloc-standard-alignment
+malloc/realloc0
+malloc/realloc-can-shrink
+malloc/testmalloc
+malloc/tst-[cmv]alloc
+malloc/tst-mallocfork
+malloc/tst-mcheck
+malloc/tst-obstack
+math/libm-test-ulps.h
+math/libm-test.c
+math/test-fpucw
+math/tst-definitions
+misc/bug-glob2
+misc/bug-readdir1
+misc/dirent
+misc/dirent64
+misc/fdopen
+misc/opendir-tst1
+misc/popen
+misc/seek
+misc/sem
+misc/stdarg
+misc/tst-scandir
+misc/tst-seekdir
+misc/tst-utmp
+mmap/mmap
+mmap/mmap2
+mmap/mmap64
+nptl/tst-align
+nptl/tst-align2
+nptl/tst-atfork1
+nptl/tst-attr[1-3]
+nptl/tst-barrier[1-4]
+nptl/tst-basic[1-6]
+nptl/tst-cancel[1-9]
+nptl/tst-cancel[1-3][0-9]
+nptl/tst-cleanup[0-4]
+nptl/tst-clock
+nptl/tst-clock[12]
+nptl/tst-clock_nanosleep
+nptl/tst-cond[1-9]
+nptl/tst-cond[1-2][0-9]
+nptl/tst-cpuclock[12]
+nptl/tst-cputimer[1-3]
+nptl/tst-detach1
+nptl/tst-eintr[1-5]
+nptl/tst-exec[2-4]
+nptl/tst-exit[1-3]
+nptl/tst-flock1
+nptl/tst-fork[1-4]
+nptl/tst-initializers1
+nptl/tst-join[1-5]
+nptl/tst-key[1-4]
+nptl/tst-kill[1-6]
+nptl/tst-mqueue[1-9]
+nptl/tst-mutex[1-9]
+nptl/tst-mutex[57]a
+nptl/tst-once[1-4]
+nptl/tst-popen1
+nptl/tst-raise1
+nptl/tst-rwlock[1-9]
+nptl/tst-rwlock1[0-4]
+nptl/tst-sched1
+nptl/tst-sem[1-9]
+nptl/tst-signal[1-6]
+nptl/tst-spin[1-3]
+nptl/tst-stack[12]
+nptl/tst-stdio[12]
+nptl/tst-sysconf
+nptl/tst-timer[2-5]
+nptl/tst-tls[1-5]
+nptl/tst-tls4mod.so
+nptl/tst-tls?mod[a-f].so
+nptl/tst-tls4modb.so
+nptl/tst-tls[35]mod.so
+nptl/tst-tls6.sh
+nptl/tst-tsd[1-5]
+nptl/tst-umask1
+pthread/ex[1-7]
+pthread/tst-too-many-cleanups
+pwd_grp/getgroups
+pwd_grp/grcat
+pwd_grp/pwcat
+pwd_grp/test_grp
+pwd_grp/test_pwd
+regex/testregex
+regex/tst-regex2
+regex/tst-regexloc
+rpc/getrpcent
+rpc/getrpcent_r
+setjmp/bug269-setjmp
+setjmp/jmpbug
+setjmp/sigjmpbug
+setjmp/tst-setjmp
+setjmp/tst-vfork-longjmp
+signal/sigchld
+signal/signal
+signal/tst-raise
+signal/tst-signal
+signal/tst-sigset
+signal/tst-sigsimple
+silly/hello
+silly/tiny
+stat/memcmp-stat
+stat/stat
+stat/stat64
+stdio/64bit
+stdio/fclose-loop
+stdlib/ptytest
+stdlib/qsort
+stdlib/testatexit
+stdlib/test-canon
+stdlib/test-canon2
+stdlib/teston_exit
+stdlib/teststrtol
+string/bug-strcoll1
+string/bug-strncat1
+string/bug-strpbrk1
+string/bug-strspn1
+string/stratcliff
+string/testcopy
+string/tester
+string/test-ffs
+string/tst-bswap
+string/tst-inlcall
+string/tst-strlen
+string/tst-strtok
+string/tst-strxfrm
+termios/termios
+time/clocktest
+time/test_time
+time/tst-ftime_l
+time/tst-futimens1
+time/tst-mktime
+time/tst-mktime3
+time/tst-strptime2
+time/tst_wcsftime
+tls/tst-tls[1-9]
+tls/tst-tls1[0-8]
+tls/tst-tls-at-ctor
+tls/tst-tlsmod[1-9].so
+tls/tst-tlsmod1[0-9].so
+tls/tst-tlsmod1[0-9][ab].so
+tls/tst-tlsmod1[78]a[0-9].so
+tls/tst-tlsmod1[78]a1[0-9].so
+tls/tst-tlsmod-at-ctor.so
+unistd/clone
+unistd/errno
+unistd/exec-null
+unistd/fork
+unistd/getcwd
+unistd/getopt
+unistd/getopt_long
+unistd/tstgetopt
+unistd/tst-preadwrite
+unistd/tst-preadwrite64
+unistd/vfork
diff --git a/test/time/tst-futimens1.c b/test/time/tst-futimens1.c
new file mode 100644
index 0000000..a452de2
--- /dev/null
+++ b/test/time/tst-futimens1.c
@@ -0,0 +1,90 @@
+/* vi: set sw=4 ts=4: */
+/* testcase
+ * Copyright (C) 2009 Bernhard Reutner-Fischer <uClibc at uClibc.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+struct
+{
+	char *name; /* name of file to open */
+	int flags; /* flags for file descriptor */
+	const struct timespec ts[2];
+	int err; /* expected errno */
+} tests [] =
+{
+	{"futimens.tst", (O_CREAT|O_TRUNC), {{0,0},{0,0}}, 0},
+	{"futimens.tst", (O_CREAT|O_TRUNC), {{99,0},{0,0}}, 0},
+	{"futimens.tst", (O_CREAT|O_TRUNC), {{0,99},{0,0}}, 0},
+	{"futimens.tst", (O_CREAT|O_TRUNC), {{0,0},{99,0}}, 0},
+	{"futimens.tst", (O_CREAT|O_TRUNC), {{0,0},{0,99}}, 0},
+	{"futimens.tst", (O_CREAT|O_TRUNC), {{11,2},{3,4}}, 0},
+};
+int do_test(int argc, char **argv) {
+	char *name;
+	int i, errors;
+	errors = argc - argc + 0;
+
+	for (i=0; i < (int) (sizeof(tests)/sizeof(tests[0])); ++i) {
+		int err, fd;
+		struct stat sb;
+		name = tests[i].name;
+		if (*name != '.')
+			unlink(name);
+		fd = open(name, tests[i].flags);
+		if (fd < 0)
+			abort();
+		errno = 0;
+		err = futimens(fd, tests[i].ts);
+		if ((errno && !err) || (!errno && err)) {
+			err = errno;
+			printf("%s: FAILED test %d (errno and return value disagree)\n",
+				argv[0], i);
+			++errors;
+		} else
+			err = errno;
+		if (err != tests[i].err) {
+			printf("%s: FAILED test %d (expected errno %d, got %d)\n",
+				argv[0], i, tests[i].err, err);
+			++errors;
+			continue;
+		}
+		if (stat(name, &sb) < 0) {
+			printf("%s: FAILED test %d (verification)\n", argv[0], i);
+			++errors;
+			continue;
+		} else {
+			unsigned wrong = tests[i].ts[0].tv_sec != sb.st_atim.tv_sec ||
+						tests[i].ts[0].tv_nsec != sb.st_atim.tv_nsec ||
+						tests[i].ts[1].tv_sec != sb.st_mtim.tv_sec ||
+						tests[i].ts[1].tv_nsec != sb.st_mtim.tv_nsec;
+			if (wrong) {
+				++errors;
+				if (tests[i].ts[0].tv_sec != sb.st_atim.tv_sec)
+					printf("%s: FAILED test %d (access time, sec: expected %ld, got %ld)\n",
+						argv[0], i, tests[i].ts[0].tv_sec, sb.st_atim.tv_sec);
+				if (tests[i].ts[0].tv_nsec != sb.st_atim.tv_nsec)
+					printf("%s: FAILED test %d (access time, nsec: expected %ld, got %ld)\n",
+						argv[0], i, tests[i].ts[0].tv_nsec, sb.st_atim.tv_nsec);
+
+				if (tests[i].ts[1].tv_sec != sb.st_mtim.tv_sec)
+					printf("%s: FAILED test %d (modification time, sec: expected %ld, got %ld)\n",
+						argv[0], i, tests[i].ts[1].tv_sec, sb.st_mtim.tv_sec);
+				if (tests[i].ts[1].tv_nsec != sb.st_mtim.tv_nsec)
+					printf("%s: FAILED test %d (modification time, nsec: expected %ld, got %ld)\n",
+						argv[0], i, tests[i].ts[1].tv_nsec, sb.st_mtim.tv_nsec);
+			}
+		}
+	}
+	if (*name != '.')
+		unlink(name);
+	printf("%d errors.\n", errors);
+	return (!errors) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+#include <test-skeleton.c>
-- 
1.6.3.3



More information about the uClibc-cvs mailing list