Obtain the current date and time in an RFC 822 and RFC 1123 complaint format.
const char *mtaDateTime(char *date, size_t *date_len, size_t date_len_max, time_t time); |
Arguments |
Description |
---|---|
date |
A pointer to a buffer to receive the NULL terminated date and time string. To avoid possible truncation of the string, this buffer should be at least 81 bytes long. |
date_len |
An optional pointer to a size_t to receive the length in bytes of the returned date and time string. This length does not include the NULL terminator that terminates the host name. A value of NULL can be passed for this call argument. |
date_len_max |
The maximum size in bytes of the buffer pointed at by the date argument. |
time |
The date and time for which to generate the string representation. To use the current local time, pass a value of zero for this argument. |
This routine generates an RFC 2822 compliant date and time string suitable for use in an RFC 822 Date: header line. To generate a date and time string for a specific time, supply the time as the time argument. Otherwise, supply a value of 0 for the time argument and a date and time string will be generated for the current local time.
On successful completion, the date and time string is stored in the buffer pointed at by the date argument, and the value of the date argument is returned.
In the event of an error, mtaDateTime() will return NULL. It will set the error status code in mta_errno.
Error Status Codes |
Description |
---|---|
MTA_BADARGS |
A value of NULL was supplied for the date argument. |
MTA_STRTRU |
The date buffer is too small; the returned value has been truncated to fit. |
char buf[80+1]; printf("The current date and time is %s\n", mtaDateTime(buf, NULL, sizeof(buf), (time_t)0); |