+2008-10-28 Simon Josefsson <simon@josefsson.org>
+
+ * MODULES.html.sh (Support for systems lacking POSIX:2001):
+ Mention times and sys_times.
+ * modules/sys_times, modules/sys_times-tests: New modules.
+ * modules/times, modules/times-tests: Likewise
+ * m4/sys_times_h.m4: New file.
+ * lib/sys_times.in.h: Likewise
+ * lib/times.c: Likewise.
+ * tests/test-sys_times.c: Likewise.
+ * tests/test-times.c: Likewise.
+ * doc/posix-headers/sys_times.texi: Update.
+ * doc/posix-functions/times.texi: Update.
+
2008-10-28 Jim Meyering <meyering@redhat.com>
* modules/tempname (Depends-on): Add lstat.
func_module tempname
func_module time
func_module time_r
+ func_module times
func_module timespec
func_module nanosleep
func_module regex
func_module sys_socket
func_module sys_stat
func_module sys_time
+ func_module sys_times
func_module tsearch
func_module unistd
func_module utime
POSIX specification: @url{http://www.opengroup.org/susv3xsh/times.html}
-Gnulib module: ---
+Gnulib module: times
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+mingw.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
-This function is missing on some platforms:
-mingw.
+There is no function on Windows to measure consumed process child
+times, thus the @code{tms_cutime} and @code{tms_cstime} will always be
+0 when the module is used.
@end itemize
POSIX specification: @url{http://www.opengroup.org/susv3xbd/sys/times.h.html}
-Gnulib module: ---
+Gnulib module: sys_times
Portability problems fixed by Gnulib:
@itemize
+@item
+This header file is missing on some platforms:
+mingw.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This header file is missing on some platforms:
-mingw.
@end itemize
--- /dev/null
+/* Provide a sys/times.h header file.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Simon Josefsson <simon@josefsson.org>, 2008. */
+
+/* This file is supposed to be used on platforms where <sys/times.h>
+ is missing. */
+
+#ifndef _GL_SYS_TIMES_H
+# define _GL_SYS_TIMES_H
+
+/* Get clock_t. */
+# include <time.h>
+
+/* The definition of GL_LINK_WARNING is copied here. */
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+ /* Structure describing CPU time used by a process and its children. */
+ struct tms
+ {
+ clock_t tms_utime; /* User CPU time. */
+ clock_t tms_stime; /* System CPU time. */
+
+ clock_t tms_cutime; /* User CPU time of dead children. */
+ clock_t tms_cstime; /* System CPU time of dead children. */
+ };
+
+# if @GNULIB_TIMES@
+ extern clock_t times (struct tms *buffer);
+# elif defined GNULIB_POSIXCHECK
+# undef times
+# define times(s) \
+ (GL_LINK_WARNING ("times is unportable - " \
+ "use gnulib module times for portability"), \
+ times (s))
+# endif
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif /* _GL_SYS_TIMES_H */
--- /dev/null
+/* Get process times
+
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Simon Josefsson <simon@josefsson.org>, 2008. */
+
+#include <config.h>
+
+/* Get times prototype. */
+#include <sys/times.h>
+
+/* Get round. */
+#include <math.h>
+
+/* Get GetProcessTimes etc. */
+#include <windows.h>
+
+static clock_t
+filetime2clock (FILETIME time)
+{
+ float f;
+
+ /* We have a 64-bit value, in the form of two DWORDS aka unsigned
+ int, counting the number of 100-nanosecond intervals. We need to
+ convert these to clock ticks. Older POSIX uses CLK_TCK to
+ indicate the number of clock ticks per second while modern POSIX
+ uses sysconf(_SC_CLK_TCK). Mingw32 does not appear to have
+ sysconf(_SC_CLK_TCK), but appears to have CLK_TCK = 1000 so we
+ use it. Note that CLOCKS_PER_SEC constant does not apply here,
+ it is for use with the clock function. */
+
+ f = (unsigned long long) time.dwHighDateTime << 32;
+ f += time.dwLowDateTime;
+ f = f * CLK_TCK / 10000000;
+ return (clock_t) round (f);
+}
+
+clock_t
+times (struct tms * buffer)
+{
+ FILETIME creation_time, exit_time, kernel_time, user_time;
+
+ if (GetProcessTimes (GetCurrentProcess (), &creation_time, &exit_time,
+ &kernel_time, &user_time) == 0)
+ return (clock_t) -1;
+
+ buffer->tms_utime = filetime2clock (user_time);
+ buffer->tms_stime = filetime2clock (kernel_time);
+ buffer->tms_cutime = 0;
+ buffer->tms_cstime = 0;
+
+ return filetime2clock (creation_time);
+}
--- /dev/null
+# Configure a replacement for <sys/times.h>.
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# Written by Simon Josefsson.
+
+AC_DEFUN([gl_SYS_TIMES_H],
+[
+ AC_REQUIRE([gl_SYS_TIMES_H_DEFAULTS])
+
+ AC_CHECK_HEADERS_ONCE([sys/times.h])
+ if test $ac_cv_header_sys_times_h = yes; then
+ SYS_TIMES_H=
+ else
+ SYS_TIMES_H=sys/times.h
+ fi
+ AC_SUBST([SYS_TIMES_H])
+])
+
+AC_DEFUN([gl_SYS_TIMES_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_SYS_TIMES_H_DEFAULTS])
+ GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_SYS_TIMES_H_DEFAULTS],
+[
+ GNULIB_TIMES=0; AC_SUBST([GNULIB_TIMES])
+])
--- /dev/null
+Description:
+A <sys/times.h> for systems lacking it.
+
+Files:
+lib/sys_times.in.h
+m4/sys_times_h.m4
+
+Depends-on:
+link-warning
+
+configure.ac:
+gl_SYS_TIMES_H
+AC_PROG_MKDIR_P
+
+Makefile.am:
+BUILT_SOURCES += $(SYS_TIMES_H)
+
+# We need the following in order to create <sys/times.h> when the system
+# doesn't have one that works with the given compiler.
+sys/times.h: sys_times.in.h
+ @MKDIR_P@ sys
+ rm -f $@-t $@
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ sed -e 's|@''GNULIB_TIMES''@|$(GNULIB_TIMES)|g' \
+ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
+ < $(srcdir)/sys_times.in.h; \
+ } > $@-t
+ mv $@-t $@
+MOSTLYCLEANFILES += sys/times.h sys/times.h-t
+MOSTLYCLEANDIRS += sys
+
+Include:
+#include <sys/times.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Simon Josefsson
--- /dev/null
+Files:
+tests/test-sys_times.c
+
+Makefile.am:
+TESTS += test-sys_times
+check_PROGRAMS += test-sys_times
--- /dev/null
+Description:
+times() function: get process times
+
+Files:
+lib/times.c
+
+Depends-on:
+sys_times
+
+configure.ac:
+AC_CHECK_FUNCS_ONCE([times])
+if test $ac_cv_func_times = no; then
+ AC_LIBOBJ([times])
+fi
+gl_SYS_TIMES_MODULE_INDICATOR([times])
+
+Makefile.am:
+
+Include:
+#include <sys/times.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Simon Josefsson
--- /dev/null
+Files:
+tests/test-times.c
+
+Makefile.am:
+TESTS += test-times
+check_PROGRAMS += test-times