blob: b3dfd092f7a03ecffc2c6aaea83542d878176cba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#define NEW_CURR_DIR "./chdir_test"
static int chdir_entry(void)
{
__attribute__((unused)) long path_max;
size_t size;
char *buf;
char *ptr;
__attribute__((unused)) char *old_dir;
size = 1024;
for (buf = ptr = NULL; ptr == NULL; size *= 2)
{
if ((buf = realloc(buf, size)) == NULL)
{
printf("error\n");
}
ptr = getcwd(buf, size);
printf("ptr %s\n",ptr);
if (ptr == NULL)
{
printf("error\n");
}
printf("old curr dir is %s\n", ptr);
mkdir(NEW_CURR_DIR, 0x777);
chdir(NEW_CURR_DIR);
ptr = getcwd(buf, size);
if (ptr == NULL)
{
printf("error\n");
}
printf("new curr dir is %s\n", ptr);
}
free(buf);
return 0;
}
#include <utest.h>
static void test_chdir(void)
{
uassert_int_equal(chdir_entry(), 0);
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_chdir);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.chdir_tc.c", RT_NULL, RT_NULL, 10);
|