1 /* $Id: mkstemp-t.c 5329 2002-03-17 07:39:14Z rra $ */
2 /* mkstemp test suite */
11 int test_mkstemp(char *template);
17 char template[] = "tsXXXXXXX";
18 char tooshort[] = "XXXXX";
19 char bad1[] = "/foo/barXXXXX";
20 char bad2[] = "/foo/barXXXXXX.out";
27 /* First, test a few error messages. */
29 ok_int(1, -1, test_mkstemp(tooshort));
30 ok(2, errno == EINVAL);
31 ok_string(3, "XXXXX", tooshort);
33 ok_int(4, -1, test_mkstemp(bad1));
34 ok(5, errno == EINVAL);
35 ok_string(6, "/foo/barXXXXX", bad1);
37 ok_int(7, -1, test_mkstemp(bad2));
38 ok(8, errno == EINVAL);
39 ok_string(9, "/foo/barXXXXXX.out", bad2);
42 /* Now try creating a real file. */
43 fd = test_mkstemp(template);
45 ok(11, strcmp(template, "tsXXXXXXX") != 0);
46 ok(12, strncmp(template, "tsX", 3) == 0);
47 ok(13, access(template, F_OK) == 0);
49 /* Make sure that it's the same file as template refers to now. */
50 ok(14, stat(template, &st1) == 0);
51 ok(15, fstat(fd, &st2) == 0);
52 ok(16, st1.st_ino == st2.st_ino);
55 /* Make sure the open mode is correct. */
56 length = strlen(template);
57 ok(17, write(fd, template, length) == length);
58 ok(18, lseek(fd, 0, SEEK_SET) == 0);
59 ok(19, read(fd, buffer, length) == length);
60 buffer[length] = '\0';
61 ok_string(20, template, buffer);