// test for uname // mkoctfile myuname.cc -lws2_32 #include #include #include #include #include #include #include /* Length of the entries in 'struct utsname' is 256. */ # define _UTSNAME_LENGTH 256 # ifndef _UTSNAME_NODENAME_LENGTH # define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH # endif # ifndef _UTSNAME_SYSNAME_LENGTH # define _UTSNAME_SYSNAME_LENGTH _UTSNAME_LENGTH # endif # ifndef _UTSNAME_RELEASE_LENGTH # define _UTSNAME_RELEASE_LENGTH _UTSNAME_LENGTH # endif # ifndef _UTSNAME_VERSION_LENGTH # define _UTSNAME_VERSION_LENGTH _UTSNAME_LENGTH # endif # ifndef _UTSNAME_MACHINE_LENGTH # define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH # endif /* Structure describing the system and machine. */ struct utsname { /* Name of this node on the network. */ char nodename[_UTSNAME_NODENAME_LENGTH]; /* Name of the implementation of the operating system. */ char sysname[_UTSNAME_SYSNAME_LENGTH]; /* Current release level of this implementation. */ char release[_UTSNAME_RELEASE_LENGTH]; /* Current version level of this release. */ char version[_UTSNAME_VERSION_LENGTH]; /* Name of the hardware type the system is running on. */ char machine[_UTSNAME_MACHINE_LENGTH]; }; int uname (struct utsname *buf) { WSADATA data; int err; #define SOCKETS_1_1 0x0101 int version = SOCKETS_1_1; err = WSAStartup (version, &data); if (err != 0) return -1; if (data.wVersion != version) { WSACleanup (); return -2; } if (gethostname (buf->nodename, sizeof(buf->nodename)) < 0) strcpy(buf->nodename, "localhost"); return 0; } DEFUN_DLD (myuname, args, nargout, "Test") { utsname info; octave_map ret; int err = uname(&info); std::string msg = ""; std::string name = ""; if (err < 0) { msg = std::strerror(errno); } else { name = info.nodename; } ret.assign("msg", octave_value(msg)); ret.assign("err", octave_value(err)); ret.assign("name", octave_value(name)); return octave_value_list(ret); }