diff options
| author | Reuben Thomas <rrt@sc3d.org> | 2011-06-09 19:49:29 +0100 |
|---|---|---|
| committer | Reuben Thomas <rrt@sc3d.org> | 2011-06-09 19:53:41 +0100 |
| commit | 3cea6c6e9612ca2b04b4742c04721d24f4b316be (patch) | |
| tree | a3ad538475091c20bf9e4766afb6064a72c855fb /src | |
| parent | 7e979318bd3d237b4fbf8da17b3ece75ac0343ba (diff) | |
| download | luafilesystem-3cea6c6e9612ca2b04b4742c04721d24f4b316be.tar.gz luafilesystem-3cea6c6e9612ca2b04b4742c04721d24f4b316be.tar.bz2 luafilesystem-3cea6c6e9612ca2b04b4742c04721d24f4b316be.zip | |
Add lfs.link.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lfs.c | 43 |
1 files changed, 43 insertions, 0 deletions
| @@ -107,6 +107,29 @@ typedef struct dir_data { | |||
| 107 | #endif | 107 | #endif |
| 108 | 108 | ||
| 109 | /* | 109 | /* |
| 110 | ** Utility functions | ||
| 111 | */ | ||
| 112 | static int pusherror(lua_State *L, const char *info) | ||
| 113 | { | ||
| 114 | lua_pushnil(L); | ||
| 115 | if (info==NULL) | ||
| 116 | lua_pushstring(L, strerror(errno)); | ||
| 117 | else | ||
| 118 | lua_pushfstring(L, "%s: %s", info, strerror(errno)); | ||
| 119 | lua_pushinteger(L, errno); | ||
| 120 | return 3; | ||
| 121 | } | ||
| 122 | |||
| 123 | static int pushresult(lua_State *L, int i, const char *info) | ||
| 124 | { | ||
| 125 | if (i==-1) | ||
| 126 | return pusherror(L, info); | ||
| 127 | lua_pushinteger(L, i); | ||
| 128 | return 1; | ||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | /* | ||
| 110 | ** This function changes the working (current) directory | 133 | ** This function changes the working (current) directory |
| 111 | */ | 134 | */ |
| 112 | static int change_dir (lua_State *L) { | 135 | static int change_dir (lua_State *L) { |
| @@ -355,6 +378,25 @@ static int file_unlock (lua_State *L) { | |||
| 355 | 378 | ||
| 356 | 379 | ||
| 357 | /* | 380 | /* |
| 381 | ** Creates a link. | ||
| 382 | ** @param #1 Object to link to. | ||
| 383 | ** @param #2 Name of link. | ||
| 384 | ** @param #3 True if link is symbolic (optional). | ||
| 385 | */ | ||
| 386 | static int make_link(lua_State *L) | ||
| 387 | { | ||
| 388 | #ifndef _WIN32 | ||
| 389 | const char *oldpath = luaL_checkstring(L, 1); | ||
| 390 | const char *newpath = luaL_checkstring(L, 2); | ||
| 391 | return pushresult(L, | ||
| 392 | (lua_toboolean(L,3) ? symlink : link)(oldpath, newpath), NULL); | ||
| 393 | #else | ||
| 394 | pusherror(L, "make_link is not supported on Windows"); | ||
| 395 | #endif | ||
| 396 | } | ||
| 397 | |||
| 398 | |||
| 399 | /* | ||
| 358 | ** Creates a directory. | 400 | ** Creates a directory. |
| 359 | ** @param #1 Directory path. | 401 | ** @param #1 Directory path. |
| 360 | */ | 402 | */ |
| @@ -763,6 +805,7 @@ static const struct luaL_Reg fslib[] = { | |||
| 763 | {"chdir", change_dir}, | 805 | {"chdir", change_dir}, |
| 764 | {"currentdir", get_dir}, | 806 | {"currentdir", get_dir}, |
| 765 | {"dir", dir_iter_factory}, | 807 | {"dir", dir_iter_factory}, |
| 808 | {"link", make_link}, | ||
| 766 | {"lock", file_lock}, | 809 | {"lock", file_lock}, |
| 767 | {"mkdir", make_dir}, | 810 | {"mkdir", make_dir}, |
| 768 | {"rmdir", remove_dir}, | 811 | {"rmdir", remove_dir}, |
