Files
libite/test/tempfile.c
T
Joachim Wiberg ef4a8691d3 test: fix build warnings for most tests
Let rsync.c continue to warn, it's not complete ...

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00

36 lines
760 B
C

#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include "check.h"
#ifndef O_TMPFILE
#warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system
#endif
#define READBACK "Reality is frequently inaccurate.\n"
int main(void)
{
char buf[80] = "";
FILE *fp;
printf("Before tempfile():\n");
system("ls -lrt " _PATH_TMP " | tail -3");
fp = tempfile();
fail_unless(fp != NULL);
fputs(READBACK, fp);
rewind(fp);
if (fgets(buf, sizeof(buf), fp))
fprintf(stderr, "\nRead-back from tempfile: %s", buf);
fail_unless(!strcmp(buf, READBACK));
printf("\nAfter tempfile(), should be same list:\n");
system("ls -lrt " _PATH_TMP " | tail -3");
return fclose(fp);
}