Openwall Project   /home  Owl  JtR  Pro  crypt  pam_passwdqc  tcb  phpass  scanlogd  popa3d  msulogin  /  Linux  BIND  /  advisories  presentations  /  services  donations  /  wordlists  passwords  /  community  lists  wiki  CVSweb  mirrors  signatures
bringing security into open environments
 
Order Openwall GNU/*/Linux 2.0 on a CD with delivery worldwide
[<prev] [next>] [month] [year] [list]
Date: Mon, 17 Apr 2006 08:16:24 +0400
From: Solar Designer <solar@...nwall.com>
To: xvendor@...ts.openwall.com
Subject: CLK_TCK

Hi,

CLK_TCK has been obsolescent for years, yet many programs (including
some of mine) continued to use it - until very recently.  glibc 2.4 no
longer defines CLK_TCK by default.

Unfortunately, what most package maintainers appear to be doing is
replace uses of CLK_TCK with CLOCKS_PER_SEC.  This is wrong.  CLK_TCK is
for times(), whereas CLOCKS_PER_SEC is for clock().  These can
actually be different values (100 vs. 1000000 is a practical example) -
although often they're the same, meaning that the problem might not be
noticed on the maintainer's system.

The fix I've used for my own programs is as follows:

#include <unistd.h>

long clk_tck;

#if defined(_SC_CLK_TCK) || !defined(CLK_TCK)
	clk_tck = sysconf(_SC_CLK_TCK);
#else
	clk_tck = CLK_TCK;
#endif

...then replace all uses of CLK_TCK with clk_tck.  This takes into
consideration the fact that _SC_CLK_TCK or CLK_TCK might be an enum
rather than a cpp macro (although many systems define these in both
ways, which is fine).  If neither is defined as a cpp macro,
_SC_CLK_TCK is preferred.

I've introduced the above code over a month ago and had no complaints
about it.

Programs which don't need to be portable to ancient systems or packages
being made for a particular system may just use sysconf(_SC_CLK_TCK).

-- 
/sd

Please check out the xvendor mailing list charter.

Hosted by DataForce ISP - Powered by Openwall GNU/*/Linux