OSDN Git Service

c2wiki:複数ファイルに対応。
[chnosproject/CHNOSProject.git] / CHNOSProject / chn / chnlib03.c
index 3eb6b5c..1884a6e 100644 (file)
@@ -17,6 +17,7 @@
 #include <unistd.h>\r
 //+---int chdir(const char *path);  カレントディレクトリの変更\r
 //+---char *getcwd(char *buf, size_t size); 現在のカレントディレクトリを取得\r
+#define CHNLIB_PATH_SEPARATOR   '/'\r
 #endif\r
 \r
 \r
@@ -25,6 +26,7 @@
 #define getcwd(a,b)    _getcwd(a,b)\r
 //+---int _chdir(const char *dirname);\r
 //+---char *_getcwd(char *buffer, int maxlen);\r
+#define CHNLIB_PATH_SEPARATOR   '\'\r
 #endif\r
 \r
 \r
 \r
 void CHNLIB_Environment_SetCurrentWorkingDirectory(const char apppath[])\r
 {\r
+    //カレントディレクトリを実行ファイルのディレクトリに変更\r
     char path[FILENAME_MAX];\r
     int i, last;\r
-    \r
-    //カレントディレクトリを実行ファイルのディレクトリに変更\r
+\r
     snprintf(path, sizeof(path), "%s", apppath);\r
     last = 0;\r
     for(i = 0; i < FILENAME_MAX; i++){\r
@@ -56,3 +58,22 @@ void CHNLIB_Environment_SetCurrentWorkingDirectory(const char apppath[])
     \r
     return;\r
 }\r
+\r
+const char *CHNLIB_Environment_GetFilenameFromPath(const char path[])\r
+{\r
+    //path文字列から、ファイル名を指し示す文字列の先頭部分のポインタを返す。\r
+    int i, p;\r
+    \r
+    if(path == NULL){\r
+        return NULL;\r
+    }\r
+    \r
+    p = 0;\r
+    for(i = 0; path[i] != '\0'; i++){\r
+        if(path[i] == CHNLIB_PATH_SEPARATOR){\r
+            p = i + 1;\r
+        }\r
+    }\r
+    \r
+    return &path[p];\r
+}\r