Blame src/functional/fdopen.c

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)) \
Szabolcs Nagy cfa23c
		t_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)
Szabolcs Nagy cfa23c
			t_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);
Szabolcs Nagy cfa23c
	return t_status;
nsz 7308b3
}