Blame src/general/fdopen.c

nsz 462b4f
#ifndef _XOPEN_SOURCE
nsz 7308b3
#define _XOPEN_SOURCE 700
nsz 462b4f
#endif
nsz 7308b3
#include <errno.h>
nsz 462b4f
#include <stdio.h>
nsz 462b4f
#include <stdlib.h>
nsz 7308b3
#include <string.h>
nsz 462b4f
#include <unistd.h>
nsz 462b4f
#include "test.h"
nsz 7308b3
nsz 7308b3
#define TEST(c) do { \
nsz 7308b3
	errno = 0; \
nsz 7308b3
	if (!(c)) \
nsz 7308b3
		error("%s failed (errno = %d)\n", #c, errno); \
nsz 7308b3
} while(0)
nsz 7308b3
nsz 462b4f
int main(void)
nsz 7308b3
{
nsz 7308b3
	char tmp[] = "/tmp/testsuite-XXXXXX";
nsz 7308b3
	char foo[6];
nsz 7308b3
	int fd;
nsz 7308b3
	FILE *f;
nsz 7308b3
nsz 7308b3
	TEST((fd = mkstemp(tmp)) > 2);
nsz 7308b3
	TEST(write(fd, "hello", 6)==6);
nsz 7308b3
	TEST(f = fdopen(fd, "rb"));
nsz 7308b3
	if (f) {
nsz 7308b3
		TEST(ftello(f)==6);
nsz 7308b3
		TEST(fseeko(f, 0, SEEK_SET)==0);
nsz 7308b3
		TEST(fgets(foo, sizeof foo, f));
nsz 7308b3
		if (strcmp(foo,"hello") != 0)
nsz 49b23c
			error("fgets read back: \"%s\"; wanted: \"hello\"\n", foo);
nsz 7308b3
		fclose(f);
nsz 7308b3
	}
nsz 7308b3
	if (fd > 2)
nsz 7308b3
		TEST(unlink(tmp) != -1);
nsz 462b4f
	return test_status;
nsz 7308b3
}