Question about function "settimeofday"

M

Martin.Dong

Hi,

Which standard does the function "settimeofday" belong to, ISO C or
POSIX, or .... ??

I have checked that the header <sys/time.h> needs to be included to
use above function, and this header is not part of ISO C, but the XSI
extension part of POSIX.

But in GNU C library, it really declares above function, and what's
more strange, the implementation of this function looks like this:

--------------------------------------------------------------------------------------------------
/* Set the current time of day and timezone information.
This call is restricted to the super-user. */
int
__settimeofday (tv, tz)
const struct timeval *tv;
const struct timezone *tz;
{
__set_errno (ENOSYS);
return -1;
}
-----------------------------------------------------------------------------------------------------

Obviously, this function can't be used by normal user, but what if I'm
root? If a root user writes some code of calling this function, what
will happen? Which function will be exactly invoked, above one, or
other inside OS?

Appreciate your help!

- Martin
 
W

WANG Cong

Martin.Dong said:
Hi,

Which standard does the function "settimeofday" belong to, ISO C or
POSIX, or .... ??

AFAIK, neither. See below.
I have checked that the header <sys/time.h> needs to be included to
use above function, and this header is not part of ISO C, but the XSI
extension part of POSIX.

Checking its header won't help much. READ its documents please.

The man page of settimeofday(2) in Linux said "POSIX.1-2001 describes
gettimeofday() but not settimeofday()."

That's all.

Obviously, this function can't be used by normal user, but what if I'm
root? If a root user writes some code of calling this function, what
will happen? Which function will be exactly invoked, above one, or
other inside OS?

Yes, of course.
I see no reasons to stop you to do that if you are root.
 
W

Walter Roberson

Martin.Dong said:
Which standard does the function "settimeofday" belong to, ISO C or
POSIX, or .... ??
I have checked that the header <sys/time.h> needs to be included to
use above function, and this header is not part of ISO C, but the XSI
extension part of POSIX.

There are no standard headers for ISO C that have directory paths
in them, so any time you see a header <sys/SOMETHING.h> you
know that the header is for a non-C routine (unless, of course,
the header is being included by one of the C standard headers, in
which case it should be considered implementation magic.)

But in GNU C library, it really declares above function, and what's

Questions about GNU routines are better put to one of the gnu
resources (e.g., a gnu.* newsgroup.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,829
Latest member
KimberAlli

Latest Threads

Top