#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
static int status = EXIT_SUCCESS;
static const char expected_buf[] = "2024 04 23";
static int expected_ret = 10;
static void
check_results(const char *name, int ret, const char *buf)
{
if (ret == 0) {
fprintf(stderr, "TEST FAILED: %s returned 0\n", name);
status = EXIT_FAILURE;
}
if (ret != 10) {
fprintf(stderr, "TEST FAILED: %s length %d (expected %d)\n",
name, ret, expected_ret);
status = EXIT_FAILURE;
}
if (strcmp(buf, expected_buf) != 0) {
fprintf(stderr, "TEST FAILED: %s contents [%s]"
" (expected [%s])\n", name, buf, expected_buf);
status = EXIT_FAILURE;
}
}
int
main(void)
{
int ret;
struct tm t;
char buf[1024];
memset(&t, 0, sizeof (t));
t.tm_year = 124;
t.tm_mon = 3;
t.tm_mday = 23;
ret = ascftime(buf, "%Y %m %d", &t);
check_results("ascftime", ret, buf);
ret = strftime(buf, ULONG_MAX, "%Y %m %d", &t);
check_results("strftime", ret, buf);
if (status == EXIT_SUCCESS) {
(void) printf("TEST PASSED: observed expected output\n");
}
printf("NOTE: buffer is %p\n", buf);
return (status);
}