diff options
author | Steve Bennett <steveb@workware.net.au> | 2014-11-28 09:57:01 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2014-11-28 15:37:58 +1000 |
commit | 4a1c716c9db7f4348513168febc1ea1266bf4b3a (patch) | |
tree | 32ec0660eed270b7d8c9e2a887a08b852a57141f /jim-file.c | |
parent | 4a7c05835e2cf52526a6d8de5b3fc446fb3dbbf9 (diff) | |
download | jimtcl-4a1c716c9db7f4348513168febc1ea1266bf4b3a.zip jimtcl-4a1c716c9db7f4348513168febc1ea1266bf4b3a.tar.gz jimtcl-4a1c716c9db7f4348513168febc1ea1266bf4b3a.tar.bz2 |
file: add support for file link
Currently only on systems that support both hard and symbolic links.
Update docs for 'file link' and some other [file] commands
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-file.c')
-rw-r--r-- | jim-file.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -528,6 +528,44 @@ static int file_cmd_rename(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } +#if defined(HAVE_LINK) && defined(HAVE_SYMLINK) +static int file_cmd_link(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + int ret; + const char *source; + const char *dest; + static const char * const options[] = { "-hard", "-symbolic", NULL }; + enum { OPT_HARD, OPT_SYMBOLIC, }; + int option = OPT_HARD; + + if (argc == 3) { + if (Jim_GetEnum(interp, argv[0], options, &option, NULL, JIM_ENUM_ABBREV | JIM_ERRMSG) != JIM_OK) { + return JIM_ERR; + } + argv++; + argc--; + } + + dest = Jim_String(argv[0]); + source = Jim_String(argv[1]); + + if (option == OPT_HARD) { + ret = link(source, dest); + } + else { + ret = symlink(source, dest); + } + + if (ret != 0) { + Jim_SetResultFormatted(interp, "error linking \"%#s\" to \"%#s\": %s", argv[0], argv[1], + strerror(errno)); + return JIM_ERR; + } + + return JIM_OK; +} +#endif + static int file_stat(Jim_Interp *interp, Jim_Obj *filename, struct stat *sb) { const char *path = Jim_String(filename); @@ -825,6 +863,15 @@ static const jim_subcmd_type file_command_table[] = { 3, /* Description: Renames a file */ }, +#if defined(HAVE_LINK) && defined(HAVE_SYMLINK) + { "link", + "?-symbolic|-hard? newname target", + file_cmd_link, + 2, + 3, + /* Description: Creates a hard or soft link */ + }, +#endif #if defined(HAVE_READLINK) { "readlink", "name", |