adjtime()--Adjust System Clock


  Syntax
 #include <sys/time.h>

 int adjtime (struct timeval *delta,
              struct timeval *olddelta);

  Service Program Name: QWCTZUTC

  Default Public Authority: *USE

  Threadsafe: Yes

The adjtime() function makes small adjustments to the system clock, either slowing it down or speeding it up by the time specified in the delta parameter up to a maximum of two hours. If delta is negative, the clock is slowed down by incrementing it more slowly than normal until the correction is complete. If delta is positive, the clock is sped up by incrementing it more quickly than normal until the correction is complete. If olddelta is not NULL, the amount of time still to be corrected from a previous adjtime() call is returned in the structure it points to.


Parameters

delta
(Input)

A pointer to a timeval structure that contains the amount of time for adjusting the clock.

olddelta
(Output)

A pointer to a timeval structure that contains the amount of time still to be corrected from a previous call to adjtime().


Authorities and Locks

Special Authority
*ALLOBJ


Return Value

0 adjtime() was successful. The requested adjustment was initiated and the value returned in the structure pointed to by the olddelta parameter is the amount of time still to be corrected from a previous adjtime().
-1 adjtime() was not successful. The errno variable is set to indicate the error.


Error Conditions

If adjtime() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

[EACCES] Permission denied.

An attempt was made to access an object in a way forbidden by its object access permissions.

[EINVAL] An invalid parameter was found.

A parameter passed to this function is not valid.

[EFAULT] The address used for an argument is not correct.

In attempting to use an argument in a call, the system detected an address that is not valid.

While attempting to access a parameter passed to this function, the system detected an address that is not valid.

[EPERM] Operation not permitted.

You must have appropriate privileges or be the owner of the object or other resource to do the requested operation.

[ENOTSUP] Operation not supported.

The operation is not supported.

[EUNKNOWN] Unknown system state.

The operation failed because of an unknown system state. See any messages in the job log and correct any errors that are indicated, then retry the operation.


Error Messages

None.


Related Information


Example

See Code disclaimer information for information pertaining to code examples.

The following example initiates a system clock adjustment:

#include <sys/time.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char *argv[])
{
    struct timeval adj, old;
    int rc;

    /* Speed up the clock by 1.5 seconds. */
    adj.tv_sec=1;
    adj.tv_usec=500000;

    rc=adjtime(&adj, &old);
    if(rc==0) {
        printf("adjtime() successful. "
               "Olddelta = %u.%06u\n",
                old.tv_sec, old.tv_usec);
    }
    else {
        printf("adjtime() failed, errno = %d\n",errno);
        return -1;
    }

    return 0;
}
Example Output:
adjtime() successful. Olddelta = 0.000000


API introduced: V4R2
Top | UNIX-Type APIs | APIs by category