sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : system.cpp sl@0: // Part of : libc library sl@0: // executes a given command/executable. sl@0: // sl@0: sl@0: sl@0: sl@0: #include //mbstowcs sl@0: #include "sysreent.h" //_wsystem_r sl@0: #include sl@0: #include sl@0: sl@0: extern "C" { sl@0: sl@0: #define MAXPATHLEN 260 /* E32STD.H: KMaxFullName + 4 to avoid data loss */ sl@0: sl@0: int _system_r (struct _reent *r, const char* cmd); sl@0: sl@0: /* sl@0: Execute command. sl@0: */ sl@0: sl@0: EXPORT_C int system (const char* cmd) sl@0: { sl@0: return _system_r (_REENT,cmd); sl@0: } sl@0: sl@0: /* sl@0: A reentrant version of system(). sl@0: */ sl@0: int _system_r (struct _reent *r, const char* cmd) sl@0: { sl@0: wchar_t wcmd[MAXPATHLEN+1]; sl@0: sl@0: if (cmd==0) sl@0: { sl@0: return 1; // special case, says that we do support system(). sl@0: } sl@0: sl@0: if(strlen(cmd) > MAXPATHLEN) sl@0: { sl@0: errno = ENAMETOOLONG; sl@0: return -1; sl@0: } sl@0: sl@0: if (((size_t)-1 != mbstowcs(wcmd, cmd, MAXPATHLEN))) sl@0: return _wsystem_r(&r->_errno, wcmd); sl@0: r->_errno = EILSEQ; sl@0: return -1; sl@0: } sl@0: sl@0: } // extern "C"