1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/uname.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,107 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Name : uname.cpp
1.18 +// Part of : LIBC
1.19 +// Contains the source for fchdir
1.20 +// Version : 1.0
1.21 +//
1.22 +
1.23 +
1.24 +
1.25 +#include <stdlib.h>
1.26 +#include <stdio.h>
1.27 +#include <unistd.h>
1.28 +#include <sys/utsname.h>
1.29 +#include <e32std.h>
1.30 +#include <e32cmn.h>
1.31 +#include <string.h>
1.32 +#include <errno.h>
1.33 +
1.34 +#define KValBuf 15
1.35 +
1.36 +/*
1.37 +The uname function stores NUL -terminated strings of information
1.38 +identifying the current system into the structure referenced by buf.
1.39 +
1.40 +The utsname structure is defined in the
1.41 +
1.42 +#include <sys/utsname.h> header file, and contains the following members:
1.43 +sysname Name of the operating system implementation.
1.44 +nodename Network name of this machine.
1.45 +release Release level of the operating system.
1.46 +version Version level of the operating system.
1.47 +machine Machine hardware platform.
1.48 +
1.49 +Upon successful completion, a non-negative value shall be returned.
1.50 +Otherwise, -1 shall be returned and errno set to indicate the error.
1.51 +
1.52 +*/
1.53 +extern "C" {
1.54 +EXPORT_C int uname(struct utsname *buf)
1.55 + {
1.56 +
1.57 + char name[KMaxFileName], buffer[KValBuf];
1.58 + size_t len = KMaxFileName;
1.59 + char* retDest2 = NULL;
1.60 + char* retDest4 = NULL;
1.61 +
1.62 + if(buf)
1.63 + {
1.64 + //sysname
1.65 + char* retDest1 = strcpy(buf->sysname, "Symbian");
1.66 +
1.67 + //nodename
1.68 + int retGetHostName = gethostname(name, len);
1.69 +
1.70 + if( !retGetHostName )
1.71 + {
1.72 + retDest2 = strncpy (buf->nodename , name, SYS_NMLN);
1.73 + buf->nodename[SYS_NMLN-1] = '\0';
1.74 + }
1.75 +
1.76 +
1.77 + //Release
1.78 + char* retDest3 = strcpy (buf->release , "\0");
1.79 +
1.80 + //Version
1.81 + TVersion rett = User::Version();
1.82 + int retNoOfBytes = sprintf(buffer, "%d:%d:%d", rett.iMajor, rett.iMinor, rett.iBuild);
1.83 + if(retNoOfBytes)
1.84 + {
1.85 + retDest4 = strcpy (buf->version , buffer);
1.86 + }
1.87 +
1.88 +
1.89 + //Machine
1.90 + char* retDest5 = strcpy (buf->machine , "\0");
1.91 +
1.92 +
1.93 + if((retDest1!=NULL)&&(retDest2!=NULL)&&(retDest3!=NULL)&&(retDest4!=NULL)&&(retDest5!=NULL))
1.94 + {
1.95 + return 0;
1.96 + }
1.97 + else
1.98 + {
1.99 + errno = EINVAL;
1.100 + return -1;
1.101 + }
1.102 +
1.103 + }
1.104 + else
1.105 + {
1.106 + errno = EINVAL;
1.107 + return -1;
1.108 + }
1.109 + }
1.110 +} //extern "C"