imgtools/romtools/rofsbuild/r_driveutl.cpp
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * @internalComponent * @released
       
    16 * Driveimage general utilities.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <string.h>
       
    22 #include <stdlib.h>
       
    23 #include <time.h>
       
    24 
       
    25 #include <e32err.h>
       
    26 #include "h_utl.h"
       
    27 #include "r_driveutl.h"
       
    28 
       
    29 /**
       
    30 Derive log file name from the given driveobey file name(it could be absolute path)
       
    31         and update with .log extn.
       
    32 Checks the validity of driveobey file name before creating the log file name.
       
    33 
       
    34 @param adriveobeyFileName - Drive obey file.
       
    35 @param &apadlogfile       - Reference to log file name.
       
    36   
       
    37 @return - returns 'ErrorNone' if log file created, otherwise returns Error.
       
    38 */ 
       
    39 TInt Getlogfile(TText *aDriveObeyFileName,TText* &aPadLogFile)
       
    40 	{
       
    41 
       
    42 	if(!(*aDriveObeyFileName))
       
    43 		return KErrGeneral;
       
    44 
       
    45 	// Validate the user entered driveoby file name.
       
    46 	char* logFile = (char*)aDriveObeyFileName;
       
    47 
       
    48 #ifdef __LINUX__
       
    49 	logFile = strrchr(logFile,'/');
       
    50 #else
       
    51 	while(*logFile)
       
    52 		{
       
    53 		if(*logFile == '/')
       
    54 			*logFile = '\\';
       
    55 		logFile++;
       
    56 		}
       
    57 	logFile = (char*)aDriveObeyFileName;
       
    58 	logFile = strrchr(logFile,'\\');
       
    59 #endif
       
    60 	
       
    61 	if(logFile)
       
    62 		++logFile;
       
    63 	else
       
    64 		logFile = (char*)aDriveObeyFileName;
       
    65 
       
    66 	TInt len = strlen(logFile);
       
    67 	if(!len)
       
    68 		return KErrGeneral;
       
    69 
       
    70 	// Allocates the memory for log file name.
       
    71 	aPadLogFile = new TText[(len)+5]; 
       
    72 	if(!aPadLogFile)
       
    73 		return KErrNoMemory;
       
    74 
       
    75 	// Create the log file name.
       
    76 	strcpy((char*)aPadLogFile,logFile);
       
    77 	strcat((char*)aPadLogFile,".LOG");
       
    78 				
       
    79 	return  KErrNone;
       
    80 	}
       
    81 
       
    82 /**
       
    83 Time Stamp for Log file.
       
    84 */ 
       
    85 TAny GetLocalTime(TAny)
       
    86 	{
       
    87 	struct tm *aNewTime = NULL;
       
    88 	time_t aTime = 0;
       
    89 
       
    90 	time(&aTime);
       
    91 	aNewTime = localtime(&aTime);
       
    92 
       
    93 	/* Print the local time as a string */
       
    94 	if(aNewTime)
       
    95 		Print(ELog,"%s\n", asctime(aNewTime));
       
    96 	else
       
    97 		Print(ELog,"Error : Getting Local Time\n");
       
    98 	}