os/ossrv/genericopenlibs/openenvcore/libc/src/system.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        : system.cpp
    15 // Part of     : libc library
    16 // executes a given command/executable.
    17 //
    18 
    19 
    20 
    21 #include <stdlib_r.h> //mbstowcs
    22 #include "sysreent.h" //_wsystem_r
    23 #include <errno.h>
    24 #include <string.h>
    25 
    26 extern "C" {
    27 
    28 #define	MAXPATHLEN	260	/* E32STD.H: KMaxFullName + 4 to avoid data loss */
    29 
    30 int _system_r (struct _reent *r, const char* cmd);
    31 
    32 /*
    33 Execute command.
    34 */
    35 
    36 EXPORT_C int system (const char* cmd)
    37 	{
    38 	return _system_r (_REENT,cmd);
    39 	}
    40 
    41 /*
    42 A reentrant version of system().
    43 */
    44 int _system_r (struct _reent *r, const char* cmd)
    45 	{
    46 	wchar_t wcmd[MAXPATHLEN+1];
    47 	
    48 	if (cmd==0)
    49 		{
    50 		return 1;	// special case, says that we do support system().	
    51 		}
    52 
    53 	if(strlen(cmd) > MAXPATHLEN)
    54 		{
    55 		errno = ENAMETOOLONG;
    56 		return -1;	
    57 		}
    58 		
    59 	if (((size_t)-1 != mbstowcs(wcmd, cmd, MAXPATHLEN)))
    60 		return _wsystem_r(&r->_errno, wcmd);
    61 		r->_errno = EILSEQ;
    62 	return -1;
    63 	}
    64 
    65 } // extern "C"