aboutsummaryrefslogtreecommitdiff
path: root/jim-posix.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-01-24 11:32:03 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:41 +1000
commitc5bf0eb2d41b437999394486dc4d7eace5dc0c27 (patch)
tree25a42d2f8a8e2419be8503c2fece94ff917e7a9d /jim-posix.c
parentb0950211281e786a633692eee2a4096e8457ed82 (diff)
downloadjimtcl-c5bf0eb2d41b437999394486dc4d7eace5dc0c27.zip
jimtcl-c5bf0eb2d41b437999394486dc4d7eace5dc0c27.tar.gz
jimtcl-c5bf0eb2d41b437999394486dc4d7eace5dc0c27.tar.bz2
Bug fixes, documentation updates
jimsh - retry on EINTR from fgets() Fix 0 -> NULL for 64 bit systems Fix overlapping memcpy Fix jim array dereferencing bug *: Counting of parentheses was incorrect with nested array references *: The result for array dereference wasn't being used properly Add os.uptime command Documentation: autogenerated command index Fix gets when last line has no newline
Diffstat (limited to 'jim-posix.c')
-rw-r--r--jim-posix.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/jim-posix.c b/jim-posix.c
index e199848..a4eb069 100644
--- a/jim-posix.c
+++ b/jim-posix.c
@@ -20,6 +20,9 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
+#ifdef HAVE_SYSINFO
+#include <sys/sysinfo.h>
+#endif
#include <unistd.h>
#include <string.h>
#include <signal.h>
@@ -177,6 +180,28 @@ static int Jim_PosixGethostnameCommand(Jim_Interp *interp, int argc,
return JIM_OK;
}
+static int Jim_PosixUptimeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+{
+#ifdef HAVE_SYSINFO
+ struct sysinfo info;
+
+ if (argc != 1) {
+ Jim_WrongNumArgs(interp, 1, argv, "");
+ return JIM_ERR;
+ }
+
+ if (sysinfo(&info) == -1) {
+ Jim_PosixSetError(interp);
+ return JIM_ERR;
+ }
+
+ Jim_SetResultInt(interp, info.uptime);
+#else
+ Jim_SetResultInt(interp, (long)time(NULL));
+#endif
+ return JIM_OK;
+}
+
static int Jim_PosixPidCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 1) {
@@ -196,6 +221,7 @@ int Jim_posixInit(Jim_Interp *interp)
Jim_CreateCommand(interp, "os.wait", Jim_PosixWaitCommand, NULL, NULL);
Jim_CreateCommand(interp, "os.getids", Jim_PosixGetidsCommand, NULL, NULL);
Jim_CreateCommand(interp, "os.gethostname", Jim_PosixGethostnameCommand, NULL, NULL);
+ Jim_CreateCommand(interp, "os.uptime", Jim_PosixUptimeCommand, NULL, NULL);
Jim_CreateCommand(interp, "pid", Jim_PosixPidCommand, NULL, NULL);
return JIM_OK;
}