OSDN Git Service

現在までのソースをコミット。
[chnosproject/CHNOSProject.git] / CHNOSProject / chn / chnlib03.c
1 //\r
2 //  chnlib03.c\r
3 //  AI003\r
4 //\r
5 //  Created by 西田 耀 on 13/02/09.\r
6 //  Copyright (c) 2013年 Hikaru Nishida. All rights reserved.\r
7 //\r
8 \r
9 //\r
10 //Include headers\r
11 //\r
12 \r
13 #include <stdio.h>\r
14 #include "chnlib.h"\r
15 \r
16 #ifdef CHNLIB_MAKE_GCC_MAC\r
17 #include <unistd.h>\r
18 //+---int chdir(const char *path);  カレントディレクトリの変更\r
19 //+---char *getcwd(char *buf, size_t size); 現在のカレントディレクトリを取得\r
20 #endif\r
21 \r
22 \r
23 #ifdef CHNLIB_MAKE_BCC_WIN\r
24 #include <direct.h>\r
25 #define getcwd(a,b)     _getcwd(a,b)\r
26 //+---int _chdir(const char *dirname);\r
27 //+---char *_getcwd(char *buffer, int maxlen);\r
28 #endif\r
29 \r
30 \r
31 //\r
32 //Functions\r
33 //\r
34 \r
35 void CHNLIB_Environment_SetCurrentWorkingDirectory(const char apppath[])\r
36 {\r
37     char path[FILENAME_MAX];\r
38     int i, last;\r
39     \r
40     //カレントディレクトリを実行ファイルのディレクトリに変更\r
41     snprintf(path, sizeof(path), "%s", apppath);\r
42     last = 0;\r
43     for(i = 0; i < FILENAME_MAX; i++){\r
44         if(path[i] == '\0'){\r
45             break;\r
46         }\r
47         if(path[i] == '/'){\r
48             last = i;\r
49         }\r
50     }\r
51     path[last + 1] = '\0';\r
52     printf("%s\n", path);\r
53     chdir(path);\r
54     getcwd(path, sizeof(path));\r
55     printf("%s\n", path);\r
56     \r
57     return;\r
58 }\r