secureswitools/swisistools/source/sisxlibrary/utility_linux.cpp
changeset 50 c6e8afe0ba85
parent 25 98b66e4fb0be
child 77 d1838696558c
equal deleted inserted replaced
46:bb1748e0dd9b 50:c6e8afe0ba85
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   173 	}
   173 	}
   174 
   174 
   175 int _wunlink(const wchar_t* wc)
   175 int _wunlink(const wchar_t* wc)
   176 	{
   176 	{
   177 	  int ret = 0;
   177 	  int ret = 0;
   178 	  int len = wcstombs(0,wc,-1);
   178 	  const int len = wcstombs(0,wc,-1);
   179 	  char *tmp = new char[len];
   179 	  
       
   180 	  char* tmp = new char[len+1];
   180 	  ret = wcstombs(tmp, wc, len);
   181 	  ret = wcstombs(tmp, wc, len);
       
   182 
   181 	  if(ret == -1) {
   183 	  if(ret == -1) {
   182 		printf("wunlink: wcstombs error\n");
   184 		printf("wunlink: wcstombs error\n");
   183 		delete[] tmp;
   185 		delete [] tmp;
   184 		return ret;
   186 		return ret;
   185 		}
   187 		}
       
   188 
   186 	  tmp[ret] = '\0';
   189 	  tmp[ret] = '\0';
   187 	  ret = unlink(tmp);
   190 	  ret = unlink(tmp);
       
   191 
   188 	  if(ret != 0)
   192 	  if(ret != 0)
   189 		printf("wunlink: %s: %s\n", tmp, strerror(ret));
   193 		printf("wunlink: %s: %s\n", tmp, strerror(ret));
       
   194 
       
   195 	  delete [] tmp;
   190 	  return ret;
   196 	  return ret;
   191 	}
   197 	}
   192 
   198 
   193 int GetTempPathW(unsigned int maxlen, const wchar_t *ptr)
   199 int GetTempPathW(unsigned int maxlen, const wchar_t *ptr)
   194 	{
   200 	{
   619 		}
   625 		}
   620 	return retValue;
   626 	return retValue;
   621 	}
   627 	}
   622 
   628 
   623 
   629 
   624 int FileCopyA(const char* aSrc, const char* aDest, size_t aFlag)
   630 int FileCopyA(const char* aSrc, const char* aDest, bool aFailIfExistsFlag)
   625 	{
   631 	{
   626 		int err= 0;
   632 		int err= 0;
       
   633 
       
   634 		char cmd[ commandLength ] = "";
       
   635 		if( aFailIfExistsFlag )
       
   636 		{
       
   637 			strcpy(cmd, "cp ");
       
   638 		}
       
   639 		else
       
   640 		{
       
   641 			strcpy(cmd, "cp -f ");
       
   642 		}
       
   643 		strcat(cmd, aSrc);
       
   644 		strcat(cmd, " ");
       
   645 		strcat(cmd, aDest);
       
   646 		strcat(cmd, " 2> /dev/null");
       
   647 
       
   648         err = system(cmd);
       
   649 
   627 		return err;
   650 		return err;
   628 	}
   651 	}
   629 int FileMoveA(const char* aSrc, const char* aDest)
   652 int FileMoveA(const char* aSrc, const char* aDest)
   630 	{
   653 	{
   631 		int err= 0;
   654 		int err= 0;
       
   655 
       
   656 		// Overwrites the orphaned file(if any).
       
   657 		char cmd[ commandLength ] = "mv -f ";
       
   658 		strcat(cmd, aSrc);
       
   659 		strcat(cmd, " ");
       
   660 		strcat(cmd, aDest);
       
   661 		strcat(cmd, " 2> /dev/null");
       
   662 
       
   663 		err = system(cmd);
       
   664 
   632 		return err;
   665 		return err;
   633 	}
   666 	}
   634 
   667