Jim Tcl
Diff
Not logged in

Differences From Artifact [865bd68398fd4932]:

To Artifact [9d6f3ffaba6b32b2]:


47 47 #include <stdlib.h> 48 48 #include <string.h> 49 49 #include <stdio.h> 50 50 #include <unistd.h> 51 51 #include <errno.h> 52 52 #include <sys/stat.h> 53 53 #include <sys/param.h> 54 +#include <sys/time.h> 54 55 55 56 #include "jim.h" 56 57 #include "jimautoconf.h" 57 58 #include "jim-subcmd.h" 58 59 59 60 # ifndef MAXPATHLEN 60 61 # define MAXPATHLEN JIM_PATH_LEN ................................................................................ 549 550 return JIM_OK; 550 551 } 551 552 552 553 static int file_cmd_mtime(Jim_Interp *interp, int argc, Jim_Obj *const *argv) 553 554 { 554 555 struct stat sb; 555 556 557 + if (argc == 2) { 558 +#ifdef HAVE_UTIMES 559 + jim_wide newtime; 560 + struct timeval times[2]; 561 + 562 + if (Jim_GetWide(interp, argv[1], &newtime) != JIM_OK) { 563 + return JIM_ERR; 564 + } 565 + 566 + times[1].tv_sec = times[0].tv_sec = newtime; 567 + times[1].tv_usec = times[0].tv_usec = 0; 568 + 569 + if (utimes(Jim_String(argv[0]), times) != 0) { 570 + Jim_SetResultFormatted(interp, "can't set time on \"%#s\": %s", argv[0], strerror(errno)); 571 + return JIM_ERR; 572 + } 573 +#else 574 + Jim_SetResultString(interp, "Not implemented", -1); 575 + return JIM_ERR; 576 +#endif 577 + } 556 578 if (file_stat(interp, argv[0], &sb) != JIM_OK) { 557 579 return JIM_ERR; 558 580 } 559 581 Jim_SetResultInt(interp, sb.st_mtime); 560 582 return JIM_OK; 561 583 } 562 584 ................................................................................ 620 642 const char *path = Jim_String(argv[0]); 621 643 char *linkValue = Jim_Alloc(MAXPATHLEN + 1); 622 644 623 645 int linkLength = readlink(path, linkValue, MAXPATHLEN); 624 646 625 647 if (linkLength == -1) { 626 648 Jim_Free(linkValue); 627 - Jim_SetResultFormatted(interp, "couldn't readlink \"%s\": %s", argv[0], strerror(errno)); 649 + Jim_SetResultFormatted(interp, "couldn't readlink \"%#s\": %s", argv[0], strerror(errno)); 628 650 return JIM_ERR; 629 651 } 630 652 linkValue[linkLength] = 0; 631 653 Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, linkValue, linkLength)); 632 654 return JIM_OK; 633 655 } 634 656 #endif ................................................................................ 669 691 .args = "name", 670 692 .function = file_cmd_atime, 671 693 .minargs = 1, 672 694 .maxargs = 1, 673 695 .description = "Last access time" 674 696 }, 675 697 { .cmd = "mtime", 676 - .args = "name", 698 + .args = "name ?time?", 677 699 .function = file_cmd_mtime, 678 700 .minargs = 1, 679 - .maxargs = 1, 680 - .description = "Last modification time" 701 + .maxargs = 2, 702 + .description = "Get or set last modification time" 681 703 }, 682 704 { .cmd = "copy", 683 705 .args = "?-force? source dest", 684 706 .function = file_cmd_copy, 685 707 .minargs = 2, 686 708 .maxargs = 3, 687 709 .description = "Copy source file to destination file"