uname.c 3.5 KB
Newer Older
1
/*****************************************************************************\
S
Shengliang Guan 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                             *
*   Filename:	    uname.c						      *
*                                                                             *
*   Description:    Get the name of the current system.			      *
*                                                                             *
*   Notes:	    TO DO: Fix the Win32 windows version for Windows >= 8.1,  *
*                          as explained in MSDN's GetVersion function page.   *
*                                                                             *
*                   TO DO: Do not rely on PROCESSOR_ARCHITECTURE to get the   *
*                          processor architecture, because the WIN32 version  *
*			   always sees "x86", even on "AMD64" systems.        *
*                                                                             *
*                   TO DO: Implement sysinfo.c, moving some of the code from  *
*			   here to there, and use it.                         *
*                                                                             *
*   History:								      *
*    2014-05-30 JFL Created this file.                    		      *
*									      *
20
*         Copyright 2016 Hewlett Packard Enterprise Development LP          *
S
Shengliang Guan 已提交
21 22 23
* Licensed under the Apache 2.0 license - www.apache.org/licenses/LICENSE-2.0 *
\*****************************************************************************/

S
TD-1057  
Shengliang Guan 已提交
24
#include "sys/msvcTsname.h"
S
Shengliang Guan 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#include <stdlib.h>	/* For itoa() */

static char major[4] = {0};
static char minor[4] = {0};

#ifdef _MSDOS

#include <dos.h>

static char name[16] = {0};

int uname(struct utsname *pun) {
  unsigned int wVersion = _bdos(0x30, 0, 0); /* int 21H ah=30H Get DOS version */

  _itoa((int)(wVersion & 0x0F), major, 10);
  _itoa((int)((wVersion >> 8) & 0x0F), minor, 10);

  /* Use _bdos instead of _intdosx, because even in large memory mode, static variables will be allocated in the default data segment */ 
  _bdos(0x5E, (unsigned short)(unsigned long)(char far *)name, 0); /* int 21H ax=5E00H ds:dx=&buf Get Machine Name */

  pun->sysname = "MS-DOS"; /* Name of this operating system */
  pun->nodename = name; /* Name of this node on the network */ /* TO DO: Get it from LAN Manager */
  pun->release = major;  /* Current release level of this implementation */
  pun->version = minor;  /* Current version level of this release */
  pun->machine = "x86"; /* Name of the hardware type on which the system is running */

  return 0;
}

#endif /* defined(_MSDOS) */

/*---------------------------------------------------------------------------*/

#ifdef _WIN32

#include <windows.h>

#pragma warning(disable:4996) /* Ignore the "This function or variable may be unsafe" warning for itoa() and getenv() */

int uname(struct utsname *pun) {
  DWORD dwVersion = GetVersion();

  _itoa((int)(dwVersion & 0x0F), major, 10);
  _itoa((int)((dwVersion >> 8) & 0x0F), minor, 10);

  pun->sysname = getenv("OS"); /* Name of this operating system */
  pun->nodename = getenv("COMPUTERNAME"); /* Name of this node on the network */
  pun->release = major;  /* Current release level of this implementation */
  pun->version = minor;  /* Current version level of this release */
  pun->machine = getenv("PROCESSOR_ARCHITECTURE"); /* Name of the hardware type on which the system is running */

  return 0;
}

#endif /* defined(_WIN32) */