os/ossrv/genericopenlibs/openenvcore/libc/src/uname.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Name        : uname.cpp
    15 // Part of     : LIBC
    16 // Contains the source for fchdir
    17 // Version     : 1.0
    18 //
    19 
    20 
    21 
    22 #include <stdlib.h>
    23 #include <stdio.h>
    24 #include <unistd.h>
    25 #include <sys/utsname.h>
    26 #include <e32std.h>
    27 #include <e32cmn.h>
    28 #include <string.h>
    29 #include <errno.h>
    30 
    31 #define KValBuf	15
    32 
    33 /*
    34 The  uname function stores  NUL -terminated strings of information
    35 identifying the current system into the structure referenced by buf.
    36 
    37 The utsname structure is defined in the 
    38 
    39 #include <sys/utsname.h> header file, and contains the following members:
    40 sysname 	Name of the operating system implementation.
    41 nodename 	Network name of this machine.
    42 release 	Release level of the operating system.
    43 version 	Version level of the operating system.
    44 machine 	Machine hardware platform.
    45 
    46 Upon successful completion, a non-negative value shall be returned. 
    47 Otherwise, -1 shall be returned and errno set to indicate the error.
    48 
    49 */
    50 extern "C" {
    51 EXPORT_C int uname(struct utsname *buf)
    52 	{
    53 	
    54 	char name[KMaxFileName], buffer[KValBuf];
    55 	size_t len = KMaxFileName;
    56 	char* retDest2 = NULL;
    57 	char* retDest4 = NULL;
    58 	
    59 	if(buf)
    60 		{
    61 		//sysname
    62 		char* retDest1 = strcpy(buf->sysname, "Symbian");
    63 		
    64 		//nodename
    65 		int retGetHostName = gethostname(name, len);
    66 		
    67 		if( !retGetHostName )
    68 			{
    69 			 retDest2 = strncpy (buf->nodename , name, SYS_NMLN);
    70 			 buf->nodename[SYS_NMLN-1] = '\0';
    71 			}
    72 		
    73 		
    74 		//Release
    75 		char* retDest3 = strcpy (buf->release , "\0");
    76 		
    77 		//Version
    78 		TVersion rett = User::Version();
    79 		int retNoOfBytes = sprintf(buffer, "%d:%d:%d", rett.iMajor, rett.iMinor, rett.iBuild);
    80 		if(retNoOfBytes)
    81 			{
    82 			retDest4 = strcpy (buf->version , buffer);	
    83 			}
    84 		
    85 		
    86 		//Machine
    87 		char* retDest5 = strcpy (buf->machine , "\0");
    88 		
    89 		
    90 		if((retDest1!=NULL)&&(retDest2!=NULL)&&(retDest3!=NULL)&&(retDest4!=NULL)&&(retDest5!=NULL))
    91 			{
    92 			return 0;	
    93 			}
    94 		else
    95 			{
    96 			errno = EINVAL;
    97 			return -1;
    98 			}
    99 			
   100 		}
   101 	else
   102 		{
   103 		errno = EINVAL;
   104 		return -1;
   105 		}
   106 	}
   107 } //extern "C"