genericopenlibs/openenvcore/libc/test/testsyscalls/src/tsyscallsblocks.cpp
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tsyscalls.h"
       
    20 #include <unistd.h>
       
    21 #include <fcntl.h>
       
    22 #include <stdio.h>
       
    23 #include <errno.h>
       
    24 #include <dirent.h>
       
    25 #include <sys/stat.h>
       
    26 #include <stdlib.h>
       
    27 #include <string.h>
       
    28 #include <utime.h>
       
    29 #include <time.h>
       
    30 #include <sys/wait.h>
       
    31 #include <sys/uio.h>
       
    32 #include <sys/syslimits.h>
       
    33 #include <pthread.h>
       
    34 #include <sys/types.h>  
       
    35 #include <sys/utsname.h>
       
    36 
       
    37 #define CLOCKS_PER_SEC 128
       
    38 
       
    39 /*******************************************************************************
       
    40 
       
    41   Test case : open1 creates a file Prog1.txt  in cdrive
       
    42               opens the file file in read-write mode 
       
    43               
       
    44        return : 0 on success 
       
    45 
       
    46                 
       
    47 *******************************************************************************/                           
       
    48 
       
    49 TInt CTestSyscalls :: Creat(  )
       
    50 	{
       
    51     int fd ;
       
    52     TPtrC String ;
       
    53     mkdir("C:\\Test" , S_IWUSR);
       
    54     _LIT( KString, "String" );
       
    55     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
    56     if(!res)  
       
    57 		{
       
    58      	_LIT(Kerr , "Failed to read input file name") ;
       
    59      	INFO_PRINTF1(Kerr) ;
       
    60 		return KErrGeneral ;
       
    61 		}
       
    62     TBuf8<100> string1;
       
    63 	string1.Copy(String);
       
    64 	char* file = (char*) string1.Ptr();
       
    65 	file[string1.Length()]='\0';
       
    66 	 	 
       
    67 		
       
    68     // Print to UI
       
    69    
       
    70     _LIT( KOpen1, "In create" );
       
    71   
       
    72     unlink(file) ; 
       
    73     INFO_PRINTF1( KOpen1 );
       
    74    
       
    75     if((fd = creat(file ,  0666))  < 0) 
       
    76 		{
       
    77         _LIT(Kerr , "failed to open the file ") ;
       
    78         INFO_PRINTF1(Kerr) ;
       
    79     	return KErrGeneral ;
       
    80 		}
       
    81     close(fd) ;
       
    82     return KErrNone ;
       
    83     
       
    84     }
       
    85 
       
    86 
       
    87 /*******************************************************************************
       
    88 
       
    89   Test case : open1 creates a file Prog1.txt  in cdrive
       
    90               opens the file file in read-write mode 
       
    91               
       
    92        return : 0 on success 
       
    93 
       
    94                 
       
    95 *******************************************************************************/                           
       
    96 
       
    97 TInt CTestSyscalls::open1(  )
       
    98     {
       
    99 	int fd ;
       
   100     TPtrC String ;
       
   101     TInt IsDirectory ;        // This variable is used to find wheather a directory is 
       
   102                               //is opened    
       
   103     TInt Expected ; 
       
   104      
       
   105     _LIT( KString, "String" );
       
   106     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   107     if(!res)  
       
   108 		{
       
   109      	_LIT(Kerr , "Failed to read input file name") ;
       
   110      	INFO_PRINTF1(Kerr) ;
       
   111      	return KErrGeneral ;
       
   112 		}
       
   113      
       
   114     TBuf8<100> string1;
       
   115 	string1.Copy(String);
       
   116 	char* file = (char*) string1.Ptr();
       
   117 	file[string1.Length()]='\0';
       
   118 	 
       
   119 	_LIT( KIsDirectory, "IsDirectory" );
       
   120 	res = GetIntFromConfig(ConfigSection(), KIsDirectory, IsDirectory);
       
   121 	 
       
   122 	if(!res)
       
   123 		{
       
   124 	 	_LIT(Kerr , "Failed to read directory flag") ;
       
   125 	 	INFO_PRINTF1(Kerr) ;
       
   126 	 	return KErrGeneral ;
       
   127 		}
       
   128 	 
       
   129 	_LIT( KExpected, "Expected" );
       
   130 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
   131 	if(!res)
       
   132 		{
       
   133 	 	_LIT(Kerr , "Failed to read directory flag") ;
       
   134 	 	INFO_PRINTF1(Kerr) ;
       
   135 	 	return KErrGeneral ;
       
   136 		}
       
   137 	 
       
   138 	if(Expected < 0 ) 
       
   139 		{
       
   140 		fd = open(NULL , O_CREAT | O_RDWR  , 0444) ;
       
   141 	   
       
   142 		if(fd < 0)  
       
   143 			{
       
   144 	   		if(errno != EFAULT) 
       
   145 	   			{
       
   146 	   			_LIT(Kerr , "Failed to set the errno value for open system call") ;
       
   147 	   			INFO_PRINTF1(Kerr) ;
       
   148 	   			return KErrGeneral ;
       
   149 	   			}
       
   150 	   		return KErrNone ; 
       
   151 			}
       
   152 		_LIT(Kerr , "open for NULL address should fail") ;
       
   153 		INFO_PRINTF1(Kerr) ;
       
   154 		return KErrGeneral ;
       
   155 		}
       
   156 	 
       
   157 		
       
   158     _LIT( KTsyscalls, "Tsyscalls" );
       
   159     INFO_PRINTF1(KTsyscalls) ;
       
   160     _LIT( KOpen1, "In open1" );
       
   161   
       
   162     unlink(file) ; 
       
   163     INFO_PRINTF1( KOpen1 );
       
   164    
       
   165     if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
   166 		{
       
   167         if(IsDirectory && (errno == EISDIR) )   
       
   168 			{
       
   169         	_LIT(Kerrnone , "Directory open test case passes ") ;
       
   170         	INFO_PRINTF1(Kerrnone) ;
       
   171         	return KErrNone ;
       
   172 			}
       
   173         else if(IsDirectory) 
       
   174 			{
       
   175         	_LIT(Kerr , "Directory open test case fails to set err value") ;
       
   176         	INFO_PRINTF1(Kerr) ;
       
   177         	return KErrGeneral ;
       
   178 			}
       
   179 		_LIT(Kerr , "failed to open the file ") ;
       
   180 		INFO_PRINTF1(Kerr) ;
       
   181     	return KErrGeneral ;
       
   182 		}
       
   183    
       
   184     close(fd) ;
       
   185     return KErrNone ;
       
   186     
       
   187     }
       
   188 
       
   189 
       
   190 //-------------------------------------------------------------------------------
       
   191 
       
   192 //  Test case : open2 creates a file
       
   193 //              opens in write only mode
       
   194 //              return : 0 on success 
       
   195 //              1 failure
       
   196 //--------------------------------------------------------------------------------                  
       
   197 TInt CTestSyscalls :: open2()
       
   198 	{
       
   199 	int fd ;
       
   200 	TPtrC String ;
       
   201     _LIT( KString, "String" );
       
   202      TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   203 	if(res)
       
   204 		{
       
   205 	    TBuf8<100> string1;
       
   206 		
       
   207 		string1.Copy(String);
       
   208 		char* file = (char*) string1.Ptr();
       
   209 		file[string1.Length()]='\0';
       
   210 	    _LIT( KOpen3, "In open3" );
       
   211 	  
       
   212 	    INFO_PRINTF1( KOpen3 );
       
   213 	    unlink(file);
       
   214 
       
   215 	    if((fd = open(file , O_CREAT | O_WRONLY , 0666))  < 0) 
       
   216 			{
       
   217 			return KErrGeneral ;
       
   218 			}
       
   219 	    close(fd) ;
       
   220 		}
       
   221     return KErrNone ;
       
   222     
       
   223 	}
       
   224 
       
   225 //-------------------------------------------------------------------------------
       
   226 
       
   227 //  Test case : open3 creates a file
       
   228 //              opens in readonly mode
       
   229 //              return : 0 on success 
       
   230 
       
   231 //--------------------------------------------------------------------------------                  
       
   232 TInt CTestSyscalls :: open3()
       
   233 	{
       
   234 	int fd ;
       
   235 	TPtrC String ;
       
   236      
       
   237 	_LIT( KString, "String" );
       
   238     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   239 	if(res)
       
   240 		{
       
   241 	    TBuf8<100> string1;
       
   242 		string1.Copy(String);
       
   243 		char* file = (char*) string1.Ptr();
       
   244 		file[string1.Length()]='\0';
       
   245 		
       
   246 		_LIT( KOpen3, "In open3" );
       
   247 	    INFO_PRINTF1( KOpen3 );
       
   248 	    
       
   249 	    unlink(file);
       
   250 	    if((fd = open(file ,  O_RDONLY | O_CREAT , 0666))  < 0) 
       
   251 			{
       
   252 	        return KErrGeneral ;
       
   253 			}
       
   254 	    close(fd) ;
       
   255 	    return KErrNone  ;
       
   256 		}
       
   257 	else
       
   258 		{
       
   259 		return KErrGeneral;
       
   260 		}
       
   261 	}
       
   262 
       
   263 
       
   264 
       
   265 //-------------------------------------------------------------------------------
       
   266 
       
   267 //  Test case : open4 creates a file  (Negative testcase )
       
   268 //   
       
   269 //  Tries to open a fails  in invalid  mode           
       
   270 //             
       
   271 // Create a file Exclusively
       
   272 //--------------------------------------------------------------------------------                  
       
   273 
       
   274 
       
   275 TInt CTestSyscalls :: open4()
       
   276 	{
       
   277 	int fd ;
       
   278    
       
   279 	TBuf8<100> string1;
       
   280 	TPtrC String ;
       
   281     
       
   282 	_LIT( KString, "String" );
       
   283 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   284 	if(!res)
       
   285 		{
       
   286 	    _LIT(Kerr , " Failed to  read input file name from ini file ") ;
       
   287 	    INFO_PRINTF1(Kerr) ;
       
   288 	    return KErrGeneral ;
       
   289 		}
       
   290 	    
       
   291 	string1.Copy(String);
       
   292 	char* file = (char*) string1.Ptr();
       
   293 	file[string1.Length()]='\0';
       
   294 	_LIT( KOpen4, "In open4" );
       
   295 	INFO_PRINTF1( KOpen4 );
       
   296     if((fd = open(file , O_CREAT | O_RDWR  , 0666))  < 0) 
       
   297 		{
       
   298         _LIT(Kerr , "Failed to o given file name") ;
       
   299         INFO_PRINTF1(Kerr) ;
       
   300         return  KErrGeneral  ;
       
   301 		}
       
   302     close(fd) ;
       
   303     
       
   304     //Now try to open the file exclusively , this open sustem call should fail
       
   305     
       
   306     fd = open(file , O_CREAT | O_EXCL | O_RDWR , 0666) ;
       
   307     if(fd < 0 )  
       
   308 		{
       
   309     	if(errno != EEXIST) 
       
   310     		{
       
   311     		_LIT(Kerr , "Failed to set errno value for open syscall") ;
       
   312     		INFO_PRINTF1(Kerr) ;
       
   313     		return KErrGeneral ;
       
   314     		}
       
   315     	return KErrNone ;
       
   316 		}
       
   317 	_LIT(Kerr , "Failed to open a file in O_EXCL mode ") ;
       
   318 	INFO_PRINTF1(Kerr) ;
       
   319 	return KErrGeneral ;
       
   320 	}
       
   321 
       
   322 
       
   323 //-------------------------------------------------------------------------------
       
   324 
       
   325 //  Test case : open5 creates a file  (Negative testcase )
       
   326 //   
       
   327 //  Tries to open a fails  in invalid  path
       
   328 //             
       
   329 // 
       
   330 //--------------------------------------------------------------------------------                  
       
   331 
       
   332 
       
   333 TInt CTestSyscalls :: open5()
       
   334 	{
       
   335 	int fd ;
       
   336 	
       
   337     TInt ret = KErrNone ;
       
   338 	TBuf8<100> string1;
       
   339     TPtrC String ;
       
   340     
       
   341 	_LIT( KString, "String" );
       
   342 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   343 
       
   344     if(!res)    
       
   345 		{
       
   346     	_LIT(Kerr , "Failed to read input file name from ini file") ;
       
   347     	INFO_PRINTF1(Kerr) ;
       
   348     	return KErrGeneral ;
       
   349 		}
       
   350 	string1.Copy(String);
       
   351 	char* file = (char*) string1.Ptr();
       
   352 	file[string1.Length()]='\0';
       
   353 	
       
   354 	_LIT( KOpen5, "In open5" );
       
   355    
       
   356     INFO_PRINTF1( KOpen5 );
       
   357     unlink(file);
       
   358 
       
   359     
       
   360     if((fd = open(file , O_CREAT | O_RDONLY , 0666))  < 0) 
       
   361 		{
       
   362         if(errno != ENOENT)   
       
   363 			{
       
   364         	_LIT(Kinvalidpath , "failed to  set errno value ") ;
       
   365         	INFO_PRINTF1(Kinvalidpath);
       
   366         	ret = KErrGeneral ;
       
   367 			}
       
   368         }
       
   369     else 
       
   370 		{
       
   371        _LIT(Kerr , "File opened in an invalid path test fails ") ;
       
   372 	   close(fd);
       
   373        INFO_PRINTF1(Kerr) ;
       
   374        ret = KErrGeneral ;
       
   375 		}
       
   376 	close(fd) ;
       
   377 	return ret ;    //This ret will be set to KErrNone if all test cases are though
       
   378 	}
       
   379 
       
   380 
       
   381 //-------------------------------------------------------------------------------
       
   382 
       
   383 //  Test case : open6 truncates the file //   
       
   384 //  
       
   385 //             
       
   386 // 
       
   387 //--------------------------------------------------------------------------------                  
       
   388 
       
   389 
       
   390 TInt CTestSyscalls :: open6()
       
   391 	{
       
   392 	int fd ;
       
   393 	TBuf8<100> string1;
       
   394     TPtrC String ;
       
   395     
       
   396     _LIT( KString, "String" );
       
   397 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   398 
       
   399     if(!res)   
       
   400 		{
       
   401     	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   402     	INFO_PRINTF1(Kerr) ;
       
   403     	return KErrGeneral ;
       
   404 		}
       
   405 	string1.Copy(String);
       
   406 	char* file = (char*) string1.Ptr();
       
   407 	file[string1.Length()]='\0';
       
   408 	
       
   409     _LIT( KOpen5, "In open6" );
       
   410     INFO_PRINTF1( KOpen5 );
       
   411   
       
   412     unlink(file);
       
   413 
       
   414     if((fd = open(file , O_CREAT|O_RDWR , 0666))  < 0) 
       
   415 		{
       
   416         _LIT(Kinvalidarg , "Failed to open specified file \n")  ;
       
   417         INFO_PRINTF1(Kinvalidarg) ;
       
   418         return KErrGeneral ;
       
   419 		}
       
   420     if(write(fd , "hELLO" ,6) < 0) 
       
   421 		{
       
   422 		_LIT(Kerr , "Failed to write to the file D:\\Prog1.txt") ;
       
   423 		INFO_PRINTF1(Kerr) ;
       
   424 		close(fd) ;
       
   425 		return KErrGeneral ;
       
   426 		}
       
   427     close(fd) ;
       
   428     if((fd = open(file , O_CREAT|O_RDWR|O_TRUNC , 0666))  < 0)  
       
   429 		{
       
   430     	_LIT(Kerr , "Failed to tuncate the specified file ") ;
       
   431     	INFO_PRINTF1(Kerr) ;
       
   432     	return KErrGeneral ;
       
   433 		}
       
   434     //seek  and find out the  size of the file
       
   435     
       
   436     if(lseek(fd , 0 , SEEK_END) != 0 )  
       
   437 		{
       
   438     	_LIT(Kerr , "file could not be truncated ") ;
       
   439     	INFO_PRINTF1(Kerr) ;
       
   440 		close(fd);
       
   441     	return  KErrGeneral ;
       
   442 		}
       
   443 	close(fd);
       
   444     return KErrNone ; 
       
   445     
       
   446 	}
       
   447 
       
   448 /**
       
   449  * Testcase 	:	OpenTruncate1
       
   450  * Description	: 	Open a file with O_CREAT | ORDWR flag
       
   451  * 					Re-open the same file with O_TRUNC
       
   452  * 					stat on the file to check whether the file is trunctaed or not
       
   453  * Return value	:	KErrNone
       
   454  */
       
   455 TInt CTestSyscalls :: OpenTruncate1()
       
   456 	{
       
   457 	int fd1, fd2, ret;
       
   458 	TBuf8<128> string1;
       
   459 	TPtrC String ;
       
   460 	struct stat fInfo;
       
   461 	
       
   462 	_LIT( KString, "String" );
       
   463 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   464 	
       
   465 	if(!res)   
       
   466 		{
       
   467 	   	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   468 	   	INFO_PRINTF1(Kerr);
       
   469 	   	return KErrGeneral;
       
   470 		}
       
   471 	string1.Copy(String);
       
   472 	char* file = (char*) string1.Ptr();
       
   473 	file[string1.Length()]='\0';
       
   474 	
       
   475 	if((fd1 = open(file, O_CREAT | O_RDWR)) < 0)
       
   476 		{
       
   477 		INFO_PRINTF2(_L("file open failed with error number %d"), errno);
       
   478 		return KErrGeneral;
       
   479 		}
       
   480 	
       
   481 	if ((write(fd1, "Symbian", 7)) != 7)
       
   482 		{
       
   483 		INFO_PRINTF2(_L("write failed with error number %d"), errno);
       
   484 		close(fd1);
       
   485 		unlink(file);
       
   486 		return KErrGeneral;
       
   487 		}
       
   488 	
       
   489 	// re-open the same file with O_CREAT
       
   490 	if((fd2 = open(file, O_TRUNC | O_WRONLY)) < 0)
       
   491 		{
       
   492 		INFO_PRINTF2(_L("file open with O_TRUNC failed with error number %d"), errno);
       
   493 		close(fd1);
       
   494 		unlink(file);
       
   495 		return KErrGeneral;
       
   496 		}
       
   497 	
       
   498 	ret = stat(file, &fInfo);
       
   499 	
       
   500 	if (ret == -1)
       
   501 		{
       
   502 		INFO_PRINTF2(_L("stat failed with error number %d"), errno);
       
   503 		close(fd1);
       
   504 		unlink(file);
       
   505 		return KErrGeneral;		
       
   506 		}
       
   507 	
       
   508 	if(fInfo.st_size != 0)
       
   509 		{
       
   510 		INFO_PRINTF1(_L("The file is not truncated. Testcase failed"));
       
   511 		close(fd1);
       
   512 		unlink(file);
       
   513 		return KErrGeneral;
       
   514 		}
       
   515 	
       
   516 	close(fd2);
       
   517 	unlink(file);
       
   518 	return KErrNone;
       
   519 	}
       
   520 
       
   521 /**
       
   522  * Testcase 	:	OpenTruncate2
       
   523  * Description	: 	open a non existing file with flag O_TRUNC
       
   524  * 					It should not create a new file 
       
   525  * Return value	:	KErrNone
       
   526  */
       
   527 TInt CTestSyscalls :: OpenTruncate2()
       
   528 	{
       
   529 	int fd1, ret;
       
   530 	TBuf8<128> string1;
       
   531 	TPtrC String ;
       
   532 		
       
   533 	_LIT( KString, "String" );
       
   534 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   535 	
       
   536 	if(!res)   
       
   537 		{
       
   538 	   	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   539 	   	INFO_PRINTF1(Kerr);
       
   540 	   	return KErrGeneral;
       
   541 		}
       
   542 	string1.Copy(String);
       
   543 	char* file = (char*) string1.Ptr();
       
   544 	file[string1.Length()]='\0';
       
   545 	
       
   546 	if((fd1 = open(file, O_TRUNC)) < 0)
       
   547 		{
       
   548 		INFO_PRINTF1(_L("Test case passed"));
       
   549 		ret = KErrNone;
       
   550 		}
       
   551 	else
       
   552 		{
       
   553 		INFO_PRINTF1(_L("open with only flag O_TRUNC should not creat a new file. Test case failed"));
       
   554 		close(fd1);
       
   555 		unlink(file);
       
   556 		ret = KErrGeneral;
       
   557 		}
       
   558 	
       
   559 	close(fd1);
       
   560 	unlink(file);
       
   561 	return ret;
       
   562 	}
       
   563 //-----------------------------------------------------------------------------
       
   564 //  Try to open a read only file in  Write only mode
       
   565 
       
   566 //---------------------------------------------------------------------------
       
   567 
       
   568 TInt CTestSyscalls :: open7()
       
   569 	{
       
   570 	int fd ;
       
   571 	TInt ret = KErrNone ;
       
   572 	TBuf8<100> string1;
       
   573     TPtrC String ;
       
   574     
       
   575     _LIT( KString, "String" );
       
   576 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   577 
       
   578     if(!res)   
       
   579 		{
       
   580     	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   581     	INFO_PRINTF1(Kerr) ;
       
   582     	return KErrGeneral ;
       
   583 		}
       
   584     
       
   585 	string1.Copy(String);
       
   586 	char* file = (char*) string1.Ptr();
       
   587 	file[string1.Length()]='\0';
       
   588 	
       
   589 	_LIT( KTsyscalls, "Tsyscalls" );
       
   590 	INFO_PRINTF1(KTsyscalls) ;
       
   591 	
       
   592     _LIT( KOpen7 , "In open7" );
       
   593     INFO_PRINTF1( KOpen7 );
       
   594     
       
   595     unlink(file) ;
       
   596     
       
   597     //First create read only file , close it and they try to 
       
   598     //open in W_ONLY mode 
       
   599     
       
   600     if((fd = open(file , O_CREAT|O_RDWR , 0444))  < 0) 
       
   601 		{
       
   602         _LIT(Kinvalidarg , "Failed to open specified file \n")  ;
       
   603         INFO_PRINTF1(Kinvalidarg) ;
       
   604         return KErrGeneral ;
       
   605 		}
       
   606     
       
   607     close(fd) ;
       
   608     
       
   609     if((fd = open(file , O_CREAT|O_WRONLY ) ) < 0) 
       
   610 		{
       
   611          if(errno !=EACCES)  
       
   612 			{
       
   613          	_LIT(Kerr , "Failed to set errno value ") ;
       
   614          	INFO_PRINTF1(Kerr);
       
   615          	ret = KErrGeneral ;
       
   616 			}        
       
   617 		}
       
   618     else
       
   619 		{
       
   620         _LIT(KErr , "Opened a read only file in Write mode hence failed ") ;
       
   621 		close(fd);
       
   622 		unlink(file);
       
   623         INFO_PRINTF1(KErr);
       
   624     	ret = KErrGeneral ;
       
   625 		}
       
   626     
       
   627     close(fd) ;
       
   628     chmod(file , S_IWUSR);
       
   629     unlink(file) ;
       
   630     return ret ; 
       
   631     
       
   632 	}
       
   633 
       
   634 
       
   635 
       
   636 /**
       
   637 * Function Name :	OpenInAppendMode
       
   638 * API Tested 	:	write
       
   639 * TestCase Description:	This test case is added as part of fix for DEF114524
       
   640 *						1. A file is opened in Append mode twice
       
   641 *						2. Few bytes are written into file using two different FIDs
       
   642 *						3. File is closed using both the FIDs
       
   643 * Expected result:	
       
   644 */
       
   645 TInt CTestSyscalls::OpenInAppendMode()
       
   646 	{
       
   647 	int fd[2];
       
   648 	char Buf[10+1];
       
   649 	TInt ret = KErrNone;
       
   650 	TBuf8<100> string1;
       
   651     TPtrC String;
       
   652     
       
   653     _LIT( KString, "String" );
       
   654 	TBool res = GetStringFromConfig(ConfigSection(), KString, String);
       
   655 
       
   656     if(!res)   
       
   657 		{
       
   658     	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   659     	INFO_PRINTF1(Kerr) ;
       
   660     	return KErrGeneral ;
       
   661 		}
       
   662     
       
   663 	string1.Copy(String);
       
   664 	char* file = (char*) string1.Ptr();
       
   665 	file[string1.Length()]='\0';
       
   666 	
       
   667 	
       
   668 	if( (fd[0] = open(file, O_WRONLY | O_APPEND | O_CREAT)) < 0)
       
   669 		{
       
   670 		_LIT(KFail, "Failed to open file in append mode");
       
   671         INFO_PRINTF1(KFail);
       
   672         return KErrGeneral;
       
   673 		}
       
   674 		
       
   675 	if((fd[1] = open(file, O_WRONLY | O_APPEND | O_CREAT)) < 0)
       
   676 		{
       
   677 		_LIT(KFail, "Failed to open file in append mode");
       
   678         INFO_PRINTF1(KFail);
       
   679         return KErrGeneral;
       
   680 		}
       
   681 	
       
   682 	if((write(fd[0], "Test", 4)) != 4)
       
   683 		{
       
   684 		INFO_PRINTF1(_L("Write API did not write expected number of characters into file"));
       
   685 		close(fd[0]);
       
   686         return KErrGeneral;
       
   687 		}
       
   688 	
       
   689 	if((write(fd[1], "Append", 6)) != 6)
       
   690 		{
       
   691 		INFO_PRINTF1(_L("Write API did not write expected number of characters into file"));
       
   692 		close(fd[0]);
       
   693 		close(fd[1]);
       
   694         return KErrGeneral;
       
   695 		}
       
   696 	
       
   697 	close(fd[0]);
       
   698 	close(fd[1]);
       
   699 	
       
   700 	if((fd[0] = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
   701 		{
       
   702 		_LIT(Kopen , "Failed to open file " ) ;
       
   703 		INFO_PRINTF1(Kopen) ;
       
   704         return KErrGeneral ;
       
   705 		}
       
   706 	
       
   707 	memset(Buf, 0, sizeof(Buf));
       
   708 	if(read(fd[0], Buf, 10) == 10) 
       
   709 		{
       
   710 		Buf[10]='\0';
       
   711         if(strcmp(Buf, "TestAppend"))
       
   712 			{
       
   713     		ret = KErrGeneral ;
       
   714 			}
       
   715 		else
       
   716 			{
       
   717 			ret = KErrNone;
       
   718 			}
       
   719 		}
       
   720 	else
       
   721 		{
       
   722 		INFO_PRINTF1(_L("read() failed"));
       
   723 		ret = KErrGeneral ;
       
   724 		}	
       
   725 	
       
   726 	close(fd[0]);
       
   727 	unlink(file);
       
   728 	return ret;
       
   729 	}
       
   730 
       
   731 
       
   732 //-------------------------------------------------------------------------------
       
   733 
       
   734 //  Test case : Write  Writes specified no of chars to the file 
       
   735 //            : returns 0 on success    
       
   736 //            : 2 on failure      
       
   737 //             
       
   738 // 
       
   739 //--------------------------------------------------------------------------------                  
       
   740 
       
   741 
       
   742 TInt CTestSyscalls :: write1()
       
   743 	{
       
   744 	int fd ;
       
   745 	TInt Expected ;          //Expected valued to be returned by syscall
       
   746 	TInt RetVal ;            //Actual value returned by syscall
       
   747 	TBuf8<100> string1;
       
   748     TPtrC String ;
       
   749     
       
   750    //first read file name , buffer and then 
       
   751    //actual no of bytes to be written
       
   752      _LIT( KString, "String" );
       
   753      TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   754      if(!res)   
       
   755 		{
       
   756     	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   757     	INFO_PRINTF1(Kerr) ;
       
   758     	return KErrGeneral ;
       
   759 		}
       
   760       
       
   761 	string1.Copy(String);
       
   762 	char* file = (char*) string1.Ptr();
       
   763 	file[string1.Length()]='\0';
       
   764 	_LIT( Kwrite1, "In write1" );
       
   765     INFO_PRINTF1( Kwrite1 );
       
   766     
       
   767     //Read no of bytes 
       
   768     TInt nBytes ;
       
   769     _LIT( KnBytes, "nBytes" );
       
   770 	res = GetIntFromConfig(ConfigSection(), KnBytes, nBytes);
       
   771     
       
   772     if(!res)    
       
   773 		{
       
   774     	_LIT(Kerr , "Failed to read input number of bytes  from the inifile ") ;
       
   775     	INFO_PRINTF1(Kerr) ;
       
   776     	return KErrGeneral ; 
       
   777 		}
       
   778     
       
   779     //Read actual string to be written 
       
   780     
       
   781     TBuf8<100> Buf;
       
   782     TPtrC buff    ;
       
   783     
       
   784     _LIT( Kbuff, "buff" );
       
   785     res = GetStringFromConfig(ConfigSection(), Kbuff, buff);
       
   786     if(!res) 
       
   787 		{
       
   788     	 _LIT(Kerr , "Failed to read actual buffer form the ini file") ;
       
   789     	 INFO_PRINTF1(Kerr) ;
       
   790     	 return KErrGeneral ;
       
   791 		}
       
   792 	Buf.Copy(buff);
       
   793 	char* Buffer = (char*) Buf.Ptr();
       
   794 	Buffer[Buf.Length()]='\0';  
       
   795 	
       
   796 	
       
   797 	//Now read expected value 
       
   798 	_LIT( KExpected, "Expected" );
       
   799 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
   800     unlink(file);
       
   801     
       
   802     if((fd = open(file  , O_CREAT | O_RDWR , 0666))  < 0) 
       
   803 		{
       
   804         _LIT(Kerr , "Failed to open specifed file \n") ;
       
   805         INFO_PRINTF1(Kerr);
       
   806         return KErrGeneral ;
       
   807 		}
       
   808     
       
   809     if((RetVal = write(fd , Buffer , nBytes) ) < 0)  
       
   810 		{
       
   811          _LIT(Kerr , "Failed to write specifed no of bytes to file ") ;
       
   812          INFO_PRINTF1(Kerr) ;
       
   813          if(nBytes > 0)
       
   814 			{
       
   815 			 close(fd);
       
   816 			return KErrGeneral;
       
   817 			}
       
   818 		}
       
   819         
       
   820     close(fd) ;
       
   821     if(RetVal == Expected)
       
   822 		{
       
   823 		return KErrNone ;
       
   824 		}
       
   825     
       
   826     return KErrGeneral ;
       
   827     
       
   828 	}
       
   829 
       
   830 
       
   831 
       
   832 //-------------------------------------------------------------------------------
       
   833 
       
   834 //  Test case : Writes specified no of chars to the invalid fd 
       
   835 //                 
       
   836 //             
       
   837 // 
       
   838 //--------------------------------------------------------------------------------                  
       
   839 
       
   840 
       
   841 TInt CTestSyscalls :: write2()
       
   842 	{
       
   843     _LIT( Kwrite2, "In write2" );
       
   844     INFO_PRINTF1( Kwrite2 );
       
   845     TInt fd ;
       
   846     
       
   847     _LIT( Kfd, "fd" );
       
   848 	TBool res = GetIntFromConfig(ConfigSection(), Kfd, fd);
       
   849     
       
   850     if(!res)   
       
   851 		{
       
   852     	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   853     	INFO_PRINTF1(Kerr) ;
       
   854     	return KErrGeneral ;
       
   855 		}
       
   856     
       
   857     if(write(fd , "Hello" , 6) < 0)  
       
   858 		{
       
   859         if(errno == EBADF) 
       
   860 			{
       
   861            _LIT(Kok , "Invalid file descriptor passed \n") ;
       
   862         	INFO_PRINTF1(Kok) ;
       
   863         	if(write(-1 , "Hello" , 6) < 0) 
       
   864         		{
       
   865         		if(errno == EBADF) 
       
   866 					{
       
   867 					_LIT(Kok , "Invalid file descriptor passed \n") ;
       
   868 					INFO_PRINTF1(Kok) ;
       
   869         			}
       
   870         		else 
       
   871 					{
       
   872 					_LIT(Kerr , "failed to set errno value \n") ;
       
   873         			INFO_PRINTF1(Kerr) ; 
       
   874         			return KErrGeneral ;
       
   875         			}
       
   876         	
       
   877 				}
       
   878 			}
       
   879         else 
       
   880 			{
       
   881             _LIT(Kerr , "failed to set errno value \n") ;
       
   882         	INFO_PRINTF1(Kerr) ; 
       
   883         	return KErrGeneral ;
       
   884         	}
       
   885 		}
       
   886     return KErrNone ;
       
   887     }
       
   888 
       
   889 
       
   890 //-------------------------------------------------------------------------------
       
   891 
       
   892 //  Test case : Read in an invalid Buffer address
       
   893 //--------------------------------------------------------------------------------                  
       
   894 
       
   895 
       
   896 
       
   897 TInt CTestSyscalls :: write3()
       
   898 	{
       
   899  	int fd ;
       
   900  
       
   901  	TPtrC String ;
       
   902     TBuf8<100> string1;
       
   903  	
       
   904     _LIT( Kread3, "In write3" );
       
   905     INFO_PRINTF1( Kread3 );
       
   906   	
       
   907   	_LIT( KString, "String" );
       
   908     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   909      
       
   910   	if(!res) 
       
   911 		{
       
   912        _LIT(Kerr , "Failed to read the input file name from ini file") ;
       
   913        INFO_PRINTF1(Kerr) ;	
       
   914 		}
       
   915     
       
   916 	string1.Copy(String);
       
   917 	char* file = (char*) string1.Ptr();
       
   918 	file[string1.Length()]='\0';
       
   919 	
       
   920 	unlink(file);
       
   921   
       
   922   	if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
   923 		{
       
   924        _LIT(Kerr , "Failed to open file " ) ;
       
   925        INFO_PRINTF1(Kerr) ;
       
   926         return KErrGeneral ;
       
   927 		}
       
   928     
       
   929     if(write(fd , NULL , 3) < 0)  
       
   930 		{
       
   931         if(errno != EFAULT)   
       
   932 			{
       
   933         	_LIT(Kerr , "Failed to set the errno value for invalid address") ;
       
   934         	INFO_PRINTF1(Kerr) ;
       
   935 			close(fd);
       
   936         	return KErrGeneral ;
       
   937 			}
       
   938     	
       
   939 		}
       
   940     
       
   941     _LIT(Kok , "Read with invalid buffer address passed") ;
       
   942     INFO_PRINTF1(Kok) ; 
       
   943     close(fd) ;
       
   944     return KErrNone ;
       
   945     
       
   946     
       
   947 	}
       
   948 
       
   949 
       
   950 
       
   951 
       
   952 //-------------------------------------------------------------------------------
       
   953 //  Test case : Write to file opened in R_ONLY MODE , 
       
   954 //                      
       
   955 //             
       
   956 // 
       
   957 //--------------------------------------------------------------------------------                  
       
   958 
       
   959 TInt CTestSyscalls :: write5()
       
   960 	{
       
   961  	int fd ;
       
   962 	TInt ret = KErrNone ;
       
   963 	TBuf8<100> string1;
       
   964     TPtrC String ;
       
   965     
       
   966     //Read the input file name 
       
   967     _LIT( KString, "String" );
       
   968     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
   969     
       
   970     if(!res)   
       
   971 		{
       
   972     	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
   973     	INFO_PRINTF1(Kerr) ;
       
   974     	return KErrGeneral ;
       
   975 		}
       
   976     
       
   977 	string1.Copy(String);
       
   978 	char* file = (char*) string1.Ptr();
       
   979 	file[string1.Length()]='\0';
       
   980 
       
   981     _LIT( Kwrite5, "In write5" );
       
   982     INFO_PRINTF1( Kwrite5 );
       
   983     unlink(file) ;
       
   984     
       
   985   	if((fd = open(file , O_CREAT | O_RDONLY , 0666))  < 0) 
       
   986 		{
       
   987        _LIT(Kwrite5 , "Failed to open file " ) ;
       
   988        INFO_PRINTF1(Kwrite5) ;
       
   989         return KErrGeneral ;
       
   990 		}
       
   991     
       
   992     if(write(fd , "Hello" , 25) < 6)  
       
   993 		{
       
   994 		int d = errno;
       
   995         if(errno == EBADF) 
       
   996 			{
       
   997 			ret = KErrNone ;	
       
   998 			}
       
   999     	else 
       
  1000     		{
       
  1001     		_LIT(Kerr , "Failed to set the errno value to EBADF") ;
       
  1002     		INFO_PRINTF1(Kerr);
       
  1003 			close(fd);
       
  1004     		ret = KErrGeneral ;
       
  1005     		}
       
  1006 		}
       
  1007     close(fd) ;
       
  1008     unlink(file) ;
       
  1009     return ret ;
       
  1010     }
       
  1011 
       
  1012 
       
  1013 //-------------------------------------------------------------------------------
       
  1014 
       
  1015 //  Test case : read specified bytes from a file, 
       
  1016 //              return 0  on success
       
  1017 //				3 on failure
       
  1018 // 
       
  1019 //--------------------------------------------------------------------------------                  
       
  1020 
       
  1021 
       
  1022 
       
  1023 TInt CTestSyscalls :: read1()
       
  1024 	{
       
  1025  	int fd ;
       
  1026  	TInt Retval ;
       
  1027  	char Buf[20] ;
       
  1028 	TBuf8<100> string1;
       
  1029     TPtrC String ;
       
  1030     
       
  1031     //Read the input file name 
       
  1032     _LIT( KString, "String" );
       
  1033     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1034     
       
  1035     if(!res)   
       
  1036 		{
       
  1037     	_LIT(Kerr , "Failed to read input file value from the ini file") ;
       
  1038     	INFO_PRINTF1(Kerr) ;
       
  1039     	return KErrGeneral ;
       
  1040 		}
       
  1041     
       
  1042 	string1.Copy(String);
       
  1043 	char* file = (char*) string1.Ptr();
       
  1044 	file[string1.Length()]='\0';
       
  1045 	
       
  1046 	TInt nbytes ;
       
  1047 	//read no of bytes to be read 
       
  1048 	
       
  1049 	_LIT( Knbytes, "nbytes" );
       
  1050 	res = GetIntFromConfig(ConfigSection(), Knbytes, nbytes);
       
  1051     
       
  1052     if(!res) 
       
  1053 		{
       
  1054 		_LIT(Kerr , "Failed to read input no of bytes to be read ") ;
       
  1055 		INFO_PRINTF1(Kerr) ;
       
  1056 		return KErrGeneral ;
       
  1057 		}
       
  1058 	
       
  1059 	//read Expected return value
       
  1060 	TInt Expected ;
       
  1061 	
       
  1062 	_LIT( KExpected, "Expected" );
       
  1063 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  1064     
       
  1065 	if(!res) 
       
  1066 		{
       
  1067 		_LIT(Kerr , "Failed to read input param Expected value \n") ;
       
  1068 		ERR_PRINTF1(Kerr);
       
  1069 		return KErrGeneral ;
       
  1070 		}
       
  1071     _LIT( Kread1, "In read1" );
       
  1072     INFO_PRINTF1( Kread1 );
       
  1073     unlink(file);
       
  1074     
       
  1075   	if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
  1076 		{
       
  1077 		_LIT(Kopen , "Failed to open file " ) ;
       
  1078 		INFO_PRINTF1(Kopen) ;
       
  1079         return KErrGeneral ;
       
  1080 		}
       
  1081     
       
  1082     if(( write(fd , "HELLO HELLO HELLO HELLO HELLO HELLO HELLO"  , 20) )<0 ) 
       
  1083 		{
       
  1084     	_LIT(Kerr , "Failed to write to the specified file ") ;
       
  1085     	INFO_PRINTF1(Kerr) ;
       
  1086 		close(fd);
       
  1087     	return KErrGeneral ;
       
  1088 		}
       
  1089     close(fd) ; //open again and try to read (or do an lseek)
       
  1090     
       
  1091     
       
  1092   	if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
  1093 		{
       
  1094 		_LIT(Kopen , "Failed to open file " ) ;
       
  1095 		INFO_PRINTF1(Kopen) ;
       
  1096         return KErrGeneral ;
       
  1097 		}
       
  1098     
       
  1099     if((Retval = read(fd , Buf , nbytes) ) < 0)  
       
  1100 		{
       
  1101     	_LIT(Kerr , "Failed to read from the specified file \n") ;
       
  1102 		close(fd);
       
  1103     	INFO_PRINTF1(Kerr);
       
  1104     	}
       
  1105     
       
  1106     if(Retval != Expected) 
       
  1107 		{
       
  1108     	_LIT(Kerr , "Expected and the actual return values dont match") ;
       
  1109     	ERR_PRINTF1(Kerr);
       
  1110 		close(fd);
       
  1111     	return KErrGeneral ;
       
  1112 		}
       
  1113     else
       
  1114 		{
       
  1115     	_LIT(Kerr , "Expected and the actual return values match") ;
       
  1116     	INFO_PRINTF1(Kerr);
       
  1117 		}
       
  1118    
       
  1119     close(fd) ;
       
  1120     return KErrNone ;
       
  1121 	}
       
  1122 
       
  1123 
       
  1124 //-------------------------------------------------------------------------------
       
  1125 
       
  1126 //  Test case :  Read from the given fd , no of bytes > size of file
       
  1127 //--------------------------------------------------------------------------------                  
       
  1128 
       
  1129 
       
  1130 
       
  1131 TInt CTestSyscalls :: read2()
       
  1132 	{
       
  1133  	int fd ;
       
  1134  	char Buf[20] ;
       
  1135 	TInt ret = KErrNone ;
       
  1136 	TBuf8<100> string1;
       
  1137     TPtrC String ; 
       
  1138     _LIT( Kread2, "In read2" );
       
  1139     INFO_PRINTF1( Kread2 ) ;
       
  1140     
       
  1141     //Read the input file name
       
  1142     _LIT( KString, "String" );
       
  1143     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1144  
       
  1145     if(!res) 
       
  1146 		{
       
  1147 		_LIT(Kerr , "Failed to read the input file name from ini file") ;
       
  1148 		INFO_PRINTF1(Kerr) ;	
       
  1149 		}
       
  1150     
       
  1151 	string1.Copy(String);
       
  1152 	char* file = (char*) string1.Ptr();
       
  1153 	file[string1.Length()]='\0';
       
  1154 	
       
  1155 	unlink(file);
       
  1156   	if((fd = open(file , O_CREAT | O_RDWR | O_TRUNC, 0666))  < 0) 
       
  1157 		{ 
       
  1158 		_LIT(Kerr , "Failed to open the given file ") ;
       
  1159 		INFO_PRINTF1(Kerr) ;
       
  1160 		return KErrGeneral ;
       
  1161 		}
       
  1162     
       
  1163     
       
  1164     //write  20 bytes to the file  and then try to read 30 bytes from the file
       
  1165     if( write(fd , "HELLO HELLO HELLO HELLO HELLO HELLO HELLO asdf adsf"  , 20)  != 20 ) 
       
  1166 		{
       
  1167     	_LIT(Kerr , "Failed to write to the specified file ") ;
       
  1168     	INFO_PRINTF1(Kerr) ;
       
  1169 		close(fd);
       
  1170     	return KErrGeneral ;
       
  1171 		}
       
  1172     
       
  1173     //Now reset the file pointer back to zero 
       
  1174     if(lseek(fd , 0 , SEEK_SET) < 0 )  
       
  1175 		{
       
  1176     	_LIT(Kerr , "Failed to reset the file pointer " ) ;
       
  1177     	INFO_PRINTF1(Kerr) ;
       
  1178 		close(fd);
       
  1179     	return KErrGeneral ;
       
  1180 		}
       
  1181     ret = read(fd , Buf , 30) ;
       
  1182     
       
  1183     if(ret != 20)
       
  1184 		{
       
  1185         _LIT(Kerr , "No of bytes returned is greater than or equal to 30 ") ;
       
  1186         INFO_PRINTF1(Kerr) ;
       
  1187 		close(fd);
       
  1188     	return KErrGeneral ;
       
  1189 		}
       
  1190 	close(fd) ;
       
  1191     return KErrNone ;
       
  1192 	}
       
  1193 
       
  1194 
       
  1195 //-------------------------------------------------------------------------------
       
  1196 
       
  1197 //  Test case : Read in an invalid Buffer address
       
  1198 //--------------------------------------------------------------------------------                  
       
  1199 
       
  1200 
       
  1201 
       
  1202 TInt CTestSyscalls :: read3()
       
  1203 	{
       
  1204  	int fd ;
       
  1205  	TPtrC String ;
       
  1206     TBuf8<100> string1;
       
  1207  	
       
  1208     _LIT( Kread3, "In read3" );
       
  1209     INFO_PRINTF1( Kread3 );
       
  1210   	
       
  1211   	_LIT( KString, "String" );
       
  1212     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1213 
       
  1214   	if(!res) 
       
  1215 		{
       
  1216 		_LIT(Kerr , "Failed to read the input file name from ini file") ;
       
  1217 		INFO_PRINTF1(Kerr) ;	
       
  1218 		}
       
  1219     
       
  1220 	string1.Copy(String);
       
  1221 	char* file = (char*) string1.Ptr();
       
  1222 	file[string1.Length()]='\0';
       
  1223 	
       
  1224 	unlink(file);
       
  1225   
       
  1226   	if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
  1227 		{
       
  1228 		_LIT(Kerr , "Failed to open file " ) ;
       
  1229 		INFO_PRINTF1(Kerr) ;
       
  1230         return KErrGeneral ;
       
  1231 		}
       
  1232     
       
  1233     if(read(fd , NULL , 3) < 0)  
       
  1234 		{
       
  1235         if(errno != EFAULT)   
       
  1236 			{
       
  1237         	_LIT(Kerr , "Failed to set the errno value for invalid address") ;
       
  1238         	INFO_PRINTF1(Kerr) ;
       
  1239 			close(fd);
       
  1240         	return KErrGeneral ;
       
  1241 			}
       
  1242     	}
       
  1243     
       
  1244     _LIT(Kok , "Read with invalid buffer address passed") ;
       
  1245     INFO_PRINTF1(Kok) ; 
       
  1246     close(fd) ;
       
  1247     return KErrNone ;
       
  1248     }
       
  1249 
       
  1250 
       
  1251 
       
  1252 //-------------------------------------------------------------------------------
       
  1253 
       
  1254 //  Test case :  Read from the from invalid arguments 
       
  1255 //--------------------------------------------------------------------------------                  
       
  1256 
       
  1257 
       
  1258 
       
  1259 TInt CTestSyscalls :: read4()
       
  1260 	{
       
  1261  	int fd ;
       
  1262  	TInt ret = KErrNone ;
       
  1263  	char Buf[20] ;
       
  1264     TBuf8<50> string1;
       
  1265     TPtrC String ; 
       
  1266 
       
  1267     _LIT( Kread4, "In read4" );
       
  1268     INFO_PRINTF1( Kread4 );
       
  1269 	if(read(-1 , Buf , 3) < 3)  
       
  1270 		{
       
  1271         if(errno != EBADF) 
       
  1272 			{
       
  1273         	_LIT(Kerr , "Failed to set errno value ") ;
       
  1274         	INFO_PRINTF1(Kerr) ;
       
  1275         	ret = KErrGeneral ;
       
  1276 			}
       
  1277       
       
  1278 		}
       
  1279      
       
  1280      //Read the file name  from the ini file 
       
  1281     _LIT( KString, "String" );
       
  1282     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1283   
       
  1284     if(!res) 
       
  1285 		{
       
  1286 		_LIT(Kerr , "Failed to read the input file name from ini file") ;
       
  1287 		INFO_PRINTF1(Kerr) ;	
       
  1288 		}  
       
  1289     
       
  1290     string1.Copy(String);
       
  1291 	char* file = (char*) string1.Ptr();
       
  1292 	file[string1.Length()]='\0'; 
       
  1293 	  
       
  1294      
       
  1295     if((fd = open(file , O_CREAT | O_WRONLY , 0666))  < 0) 
       
  1296 		{
       
  1297 		_LIT(Kopen , "Failed to open file " ) ;
       
  1298 		INFO_PRINTF1(Kopen) ;
       
  1299 		return KErrGeneral  ;
       
  1300 		}
       
  1301     
       
  1302     if(read(fd , Buf , 6)  < 0) 
       
  1303 		{
       
  1304     	if(errno != EBADF) 
       
  1305     		{
       
  1306     		_LIT(KErr , "Read from invalid fd failed \n") ;
       
  1307     		INFO_PRINTF1(KErr) ;
       
  1308 			close(fd);
       
  1309     		ret = KErrGeneral ;
       
  1310     		}
       
  1311 		}
       
  1312     
       
  1313 	else   
       
  1314 		{
       
  1315 		_LIT(Kerr , "Read from a write only file des should fail") ;
       
  1316 		INFO_PRINTF1(Kerr) ;
       
  1317 		ret = KErrGeneral ;
       
  1318 		}
       
  1319     close(fd);
       
  1320     return ret ; 
       
  1321 
       
  1322 	}
       
  1323 //-------------------------------------------------------------------------------
       
  1324 
       
  1325 //  Test case : open a directory
       
  1326 //            : returns 0 on success
       
  1327 //              4 on failure            
       
  1328 //--------------------------------------------------------------------------------                  
       
  1329 
       
  1330 TInt CTestSyscalls :: Opendir()
       
  1331 	{
       
  1332  	DIR *DirHandle ;
       
  1333  
       
  1334  	TBuf8<50> string1;
       
  1335     TPtrC String ; 
       
  1336     
       
  1337     TInt Expected ;
       
  1338 
       
  1339     _LIT( Kopendir, "In opendir" );
       
  1340     INFO_PRINTF1( Kopendir );
       
  1341   
       
  1342     //Read the directory  name  from the ini file 
       
  1343     _LIT( KString, "String" );
       
  1344     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1345     if(!res) 
       
  1346 		{
       
  1347        	_LIT(Kerr , "Failed to read the input file name from ini file") ;
       
  1348        	INFO_PRINTF1(Kerr) ;	
       
  1349 		}  
       
  1350     
       
  1351     string1.Copy(String);
       
  1352 	char* directory = (char*) string1.Ptr();
       
  1353 	directory[string1.Length()]='\0';   
       
  1354     
       
  1355     _LIT( KExpected, "Expected" );
       
  1356 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  1357 
       
  1358     if(!res) 
       
  1359 		{
       
  1360     	_LIT(Kerr , "Failed to read expected return value from ini file ") ;
       
  1361     	INFO_PRINTF1(Kerr) ;
       
  1362     	return  KErrGeneral ;
       
  1363 		}
       
  1364     int status = mkdir(directory,S_IRWXU | S_IRWXG );
       
  1365     
       
  1366     if (status != 0 )    
       
  1367     	{
       
  1368     	int d = errno;
       
  1369     	if (errno == EEXIST)
       
  1370     		{
       
  1371     		INFO_PRINTF1(_L("Directory already present")) ;
       
  1372     		}
       
  1373     	else
       
  1374     		{
       
  1375     		ERR_PRINTF1(_L("Can't create directory"));
       
  1376 	    	return  KErrGeneral ;
       
  1377 	   		}
       
  1378        	}
       
  1379     DirHandle = opendir(directory)  ;
       
  1380     if(Expected  == 0)     //for negative test cases 
       
  1381 		{
       
  1382        	if(Expected != (TInt) DirHandle)  
       
  1383        		{
       
  1384        	    _LIT(Kerr , "Expected and the return values are different") ;
       
  1385        	    INFO_PRINTF1(Kerr) ;
       
  1386 			rmdir(directory);
       
  1387        	    return  KErrGeneral ; 
       
  1388        		}
       
  1389        	}
       
  1390      else 
       
  1391 		{
       
  1392      	if(DirHandle == (DIR *)NULL ) 
       
  1393      		{
       
  1394      		_LIT(Kerr , "Failed to open given directory") ;
       
  1395      		INFO_PRINTF1(Kerr) ;
       
  1396 			rmdir(directory);
       
  1397      		return KErrGeneral ;
       
  1398      		}
       
  1399 		}
       
  1400 	closedir(DirHandle);
       
  1401     rmdir(directory);
       
  1402     return KErrNone ;
       
  1403 	}	
       
  1404 
       
  1405 
       
  1406 //------------------------------------------------------------------------
       
  1407 //
       
  1408 // test : Closedir
       
  1409 //------------------------------------------------------------------------
       
  1410 
       
  1411 
       
  1412 TInt CTestSyscalls :: Closedir() 
       
  1413 	{
       
  1414    
       
  1415     DIR *DirHandle ;
       
  1416   	TBuf8<50> string1;
       
  1417     TPtrC String ; 
       
  1418     
       
  1419     TInt Expected ;
       
  1420     
       
  1421 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1422 	INFO_PRINTF1(KTsyscalls) ;
       
  1423 	_LIT( Kclosedir , "In Closedir" );
       
  1424 	INFO_PRINTF1(Kclosedir);
       
  1425    
       
  1426 
       
  1427     //Read the directory  name  from the ini file 
       
  1428     _LIT( KString, "String" );
       
  1429     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1430   
       
  1431     if(!res) 
       
  1432 		{
       
  1433        _LIT(Kerr , "Failed to read the input file name from ini file") ;
       
  1434        INFO_PRINTF1(Kerr) ;	
       
  1435 		}  
       
  1436     
       
  1437     string1.Copy(String);
       
  1438 	char* directory = (char*) string1.Ptr();
       
  1439 	directory[string1.Length()]='\0';   
       
  1440     
       
  1441     _LIT( KExpected, "Expected" );
       
  1442 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  1443 
       
  1444     if(!res) 
       
  1445 		{
       
  1446     	_LIT(Kerr , "Failed to read expected return value from ini file ") ;
       
  1447     	INFO_PRINTF1(Kerr) ;
       
  1448     	return  KErrGeneral ;
       
  1449 		}
       
  1450     
       
  1451     
       
  1452     if(Expected < 0 ) 
       
  1453 		{
       
  1454 	    closedir(NULL) ;
       
  1455 	    
       
  1456         if(errno != EBADF) 
       
  1457 			{
       
  1458 	    	_LIT(Kerr , "Failed to set errno value") ;
       
  1459 	    	INFO_PRINTF1(Kerr) ;
       
  1460 	    	return KErrGeneral ;
       
  1461 			}
       
  1462 	    
       
  1463 		return KErrNone ;
       
  1464 		}
       
  1465 	DirHandle = opendir(directory)  ;
       
  1466 	
       
  1467 	if(DirHandle == (DIR *) NULL) 
       
  1468 		{
       
  1469 		_LIT (Kerr , "Failed to open the directory") ;
       
  1470 		INFO_PRINTF1(Kerr) ;
       
  1471 		return KErrGeneral ;
       
  1472 		}
       
  1473 	if(closedir(DirHandle) < 0 )   
       
  1474 		{
       
  1475 		if(errno != EBADF) 
       
  1476 			{
       
  1477 			_LIT(Kerr , "Failed to set errno value ") ;
       
  1478 			INFO_PRINTF1(Kerr) ;
       
  1479 			return KErrGeneral ;
       
  1480 			}
       
  1481 		return KErrNone ;
       
  1482 		}
       
  1483 	return KErrNone ;
       
  1484 	}
       
  1485 
       
  1486 
       
  1487 /*
       
  1488 //-------------------------------------------------------------------------------
       
  1489 
       
  1490 //  Test case : open  directory (negative test cases )
       
  1491 //            :       
       
  1492 //--------------------------------------------------------------------------------                  
       
  1493 
       
  1494 TInt CTestSyscalls :: Opendir1()
       
  1495 {
       
  1496  	DIR *DirHandle ;
       
  1497  	char Buf[20] ;
       
  1498 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1499     _LIT( Kopendir, "In opendir1" );
       
  1500     INFO_PRINTF1( Kopendir );
       
  1501   	
       
  1502   	if((DirHandle = opendir("Logs") ) != NULL)
       
  1503     {
       
  1504          _LIT( Kopendir, "Opendir for invalid argument failed" );
       
  1505          INFO_PRINTF1(Kopendir) ;
       
  1506          return	KErropendir  ;
       
  1507     }
       
  1508     
       
  1509     if((DirHandle = opendir("C:\\testdir")) != NULL)   
       
  1510     {
       
  1511     	_LIT( Kopendir, "Opendir for invalid argument failed" );
       
  1512          INFO_PRINTF1(Kopendir) ;
       
  1513          return	KErropendir  ;
       
  1514     }
       
  1515     return KOpendir ;
       
  1516 }
       
  1517 */
       
  1518 
       
  1519 //-------------------------------------------------------------------------------
       
  1520 
       
  1521 //  Test case : read  a directory
       
  1522 //            : returns 0 on success
       
  1523 //              5 on failure            
       
  1524 //--------------------------------------------------------------------------------                  
       
  1525 
       
  1526 
       
  1527 TInt CTestSyscalls :: Readdir()
       
  1528 	{
       
  1529  	DIR *DirHandle ;
       
  1530  	TBuf8<50> string1;
       
  1531     TPtrC String ; 
       
  1532     _LIT( Kreaddir, "In readdir" );
       
  1533     INFO_PRINTF1( Kreaddir );
       
  1534     
       
  1535     //Read the directory  name  from the ini file 
       
  1536     _LIT( KString, "String" );
       
  1537     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1538      
       
  1539     if(!res) 
       
  1540 		{
       
  1541 		_LIT(Kerr , "Failed to read the input file name from ini file") ;
       
  1542 		INFO_PRINTF1(Kerr) ;	
       
  1543 		}  
       
  1544     
       
  1545     string1.Copy(String);
       
  1546 	char* directory = (char*) string1.Ptr();
       
  1547 	directory[string1.Length()]='\0';   
       
  1548     if((DirHandle = opendir(directory) )== NULL)
       
  1549 		{
       
  1550         _LIT(Kerr , "Failed to open the given directory ") ;
       
  1551         INFO_PRINTF1(Kerr) ;
       
  1552         return KErrGeneral ;
       
  1553         }
       
  1554     if(readdir(DirHandle) == (dirent *)NULL)
       
  1555 		{
       
  1556         _LIT(Kerr , " Falied to read the directory") ;
       
  1557         ERR_PRINTF1(Kerr);
       
  1558         return KErrGeneral  ;
       
  1559 		}
       
  1560 	closedir(DirHandle);
       
  1561 	if(readdir(DirHandle) == (dirent *)NULL  && errno == EBADF)
       
  1562   		{
       
  1563         return KErrNone;
       
  1564   		}
       
  1565   	else
       
  1566   		{
       
  1567   		ERR_PRINTF2(_L("readir failed for invalid DIR list,Expected errno = 9 and actual errno is = %d "),errno);
       
  1568   		return KErrGeneral;	
       
  1569   		}
       
  1570 	}
       
  1571 
       
  1572 //-------------------------------------------------------------------------------
       
  1573 
       
  1574 //  Test case : seek to specified no of bytes in a file
       
  1575 //            : returns 0 on success
       
  1576 //              6 on failure            
       
  1577 //--------------------------------------------------------------------------------                  
       
  1578 
       
  1579 
       
  1580 TInt CTestSyscalls :: Lseek()
       
  1581 	{
       
  1582  	int fd ;
       
  1583 	TInt Seekbytes ; //read the seek 
       
  1584 	TInt ret ;
       
  1585 	TBuf8<50> string1;
       
  1586     TPtrC String ; 
       
  1587     
       
  1588 	
       
  1589 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1590     _LIT( Klseek, "In Lseek" );
       
  1591     INFO_PRINTF1(KTsyscalls) ;
       
  1592     INFO_PRINTF1( Klseek );
       
  1593     
       
  1594     _LIT( KString, "String" );
       
  1595     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1596    
       
  1597     if(!res) 
       
  1598 		{
       
  1599 		_LIT(Kerr , "Failed to read the input file name from ini file") ;
       
  1600 		INFO_PRINTF1(Kerr) ;	
       
  1601 		}  
       
  1602     
       
  1603     string1.Copy(String);
       
  1604 	char* file = (char*) string1.Ptr();
       
  1605 	file[string1.Length()]='\0';   
       
  1606 	
       
  1607 	
       
  1608 	_LIT( KSeekbytes, "Seekbytes" );
       
  1609 	res = GetIntFromConfig(ConfigSection(), KSeekbytes, Seekbytes);
       
  1610     if(!res) 
       
  1611 		{
       
  1612     	_LIT(Kerr , "Failed to read seekbytes value from ini file ") ;
       
  1613     	INFO_PRINTF1(Kerr) ;
       
  1614     	return  KErrGeneral ;
       
  1615 		}  
       
  1616 	unlink(file) ;
       
  1617     //SEEK AN EMPTY FILE
       
  1618     
       
  1619     if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
  1620 		{
       
  1621 		return KErrGeneral ;
       
  1622 		}
       
  1623       
       
  1624     ret =  lseek(fd , Seekbytes ,SEEK_SET) ;
       
  1625     if(ret < 0 )   
       
  1626 		{
       
  1627     	_LIT(Kerr , "Failed to SEEK_SET specified bytes ") ;
       
  1628     	INFO_PRINTF1(Kerr) ;
       
  1629         }
       
  1630     ret = lseek(fd ,Seekbytes , SEEK_END ) ;
       
  1631     
       
  1632     if(ret < 0 )
       
  1633 		{
       
  1634     	_LIT(Kerr , "Failed to SEEK_END specified bytes  seeking beyond end of file Not supported") ;
       
  1635     	INFO_PRINTF1(Kerr) ;    
       
  1636 		}
       
  1637     if(lseek(fd , Seekbytes , SEEK_CUR) < 0) 
       
  1638 		{ 
       
  1639         _LIT(Kerr , "Seeking beyond end of the file not supported") ;
       
  1640         INFO_PRINTF1(Kerr) ;
       
  1641 	    }
       
  1642 	close(fd);
       
  1643 	return KErrNone ;
       
  1644 	}
       
  1645 
       
  1646 
       
  1647 //-------------------------------------------------------------------------------
       
  1648 
       
  1649 //  Test case : lseek test (negative tests )
       
  1650 //            : returns 0 on success
       
  1651 //              6 on failure            
       
  1652 //--------------------------------------------------------------------------------                  
       
  1653 
       
  1654 
       
  1655 TInt CTestSyscalls :: Lseek1()
       
  1656 	{
       
  1657  	int fd ;
       
  1658  	char Buf[20] ;
       
  1659  	
       
  1660 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1661     _LIT( Klseek, "In Lseek" );
       
  1662     INFO_PRINTF1(KTsyscalls) ;
       
  1663     INFO_PRINTF1( Klseek );
       
  1664     
       
  1665     if((fd = open("C:\\Test\\Prog1234.txt" , O_CREAT | O_RDWR | O_TRUNC , 0666))  < 0) 
       
  1666 		{
       
  1667       return KErrGeneral ;
       
  1668 		}
       
  1669        
       
  1670     if(write(fd , "HELLO HELLO hello hello" , 20) < 0) 
       
  1671 		{
       
  1672     	_LIT(Kopen , "Failed to write to file ") ;
       
  1673     	INFO_PRINTF1(Kopen) ;
       
  1674 		close(fd);
       
  1675     	return KErrGeneral ;
       
  1676 		}
       
  1677     
       
  1678     if(lseek(fd , 2 ,SEEK_SET) < 0)   
       
  1679 		{
       
  1680 		close(fd);
       
  1681     	return KErrGeneral ;
       
  1682 		}
       
  1683     
       
  1684     if(read(fd , Buf , 3)   > 0) 
       
  1685 		{
       
  1686         if(strncmp(Buf , "LLO" , 3))
       
  1687 			{
       
  1688 			close(fd);
       
  1689     		return KErrGeneral ;
       
  1690 			}
       
  1691 		}
       
  1692 
       
  1693     if(lseek(fd , 1 , SEEK_CUR) < 0) 
       
  1694 		{
       
  1695 		close(fd);
       
  1696     	return KErrGeneral ;
       
  1697 		}
       
  1698     
       
  1699     if(read(fd , Buf , 5) > 0) 
       
  1700 		{
       
  1701         if(strncmp(Buf , "HELLO" , 5))
       
  1702 			{
       
  1703 			close(fd);
       
  1704     		return KErrGeneral;
       
  1705 			}
       
  1706 		}
       
  1707         
       
  1708     //Try to seek beyond the end of file
       
  1709     
       
  1710     if(lseek(fd , 10 , SEEK_END) < 0)     
       
  1711 		{
       
  1712     	_LIT(Kseek , "seek beyond the end of file Not supported") ;
       
  1713     	INFO_PRINTF1(Kseek) ;
       
  1714         }
       
  1715     //Try to seek -ve no of bytes from the start of the file 
       
  1716     
       
  1717     if(lseek(fd , -10 , SEEK_SET) < 0) 
       
  1718 		{
       
  1719     	if(errno != EINVAL) 
       
  1720     		{
       
  1721     		_LIT(Kseek , "Failed to seek -ve no of bytes from starting Not supported\n") ;
       
  1722     		INFO_PRINTF1(Kseek) ;
       
  1723 			close(fd);
       
  1724     		return KErrNone ;
       
  1725     		}
       
  1726 		}
       
  1727 	close(fd);
       
  1728 	return KErrNone ;
       
  1729 	}
       
  1730 
       
  1731 
       
  1732 
       
  1733 
       
  1734 
       
  1735 //-------------------------------------------------------------------------------
       
  1736 
       
  1737 //  Test case : access tests  R_OK for given file
       
  1738 //            : returns 0 on success
       
  1739 //            : 7 on failure  
       
  1740 //--------------------------------------------------------------------------------                  
       
  1741 
       
  1742 
       
  1743 TInt CTestSyscalls :: Access()
       
  1744 	{
       
  1745 	int fd ;
       
  1746 	TBuf8<50> string;
       
  1747 	TPtrC String ; 
       
  1748    
       
  1749 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1750 	INFO_PRINTF1(KTsyscalls) ;
       
  1751 	_LIT( Kaccess, "In Access" );
       
  1752     INFO_PRINTF1( Kaccess );
       
  1753     
       
  1754     _LIT( KString, "String" );
       
  1755     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1756     if(!res)  
       
  1757 		{
       
  1758     	_LIT(Kerr , "Failed to read input file name from the ini file") ;
       
  1759     	INFO_PRINTF1(Kerr) ;
       
  1760     	return KErrGeneral ;
       
  1761 		}
       
  1762     
       
  1763     string.Copy(String) ;
       
  1764     char *file = (char *) string.Ptr() ;
       
  1765     file[string.Length()] = '\0' ;
       
  1766     
       
  1767     unlink(file) ;
       
  1768    
       
  1769     if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
  1770 		{
       
  1771         _LIT(Kerr, "Failed to open the given file ") ;
       
  1772         ERR_PRINTF1(Kerr);
       
  1773         return KErrGeneral ;
       
  1774         }
       
  1775     close(fd) ;
       
  1776  	if(access(file ,R_OK) != 0 ) 
       
  1777  		{
       
  1778 		_LIT(Kopen , "Failed to open file " ) ;
       
  1779 		INFO_PRINTF1(Kopen) ;
       
  1780 		return KErrGeneral  ;
       
  1781 		}
       
  1782  	return KErrNone ;
       
  1783     }
       
  1784 
       
  1785 
       
  1786 //-------------------------------------------------------------------------------
       
  1787 
       
  1788 //  Test case : access tests  invalid args
       
  1789 //            : returns 0 on success
       
  1790 //            : 7 on failure  
       
  1791 //--------------------------------------------------------------------------------                  
       
  1792 
       
  1793 
       
  1794 
       
  1795 TInt CTestSyscalls :: Access1()
       
  1796 	{
       
  1797 	int fd ;
       
  1798 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1799 	INFO_PRINTF1(KTsyscalls) ;
       
  1800     _LIT( Kaccess, "In Access" );
       
  1801     INFO_PRINTF1( Kaccess );
       
  1802     TPtrC String ;
       
  1803     TBuf8<50> string;
       
  1804     TInt ret   ; //To store all the return values 
       
  1805    
       
  1806     ret = KErrNone ;
       
  1807     
       
  1808     
       
  1809     _LIT( KString, "String" );
       
  1810     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1811     if(!res)  
       
  1812 		{
       
  1813     	_LIT(Kerr , "Failed to read i/p file name from ini file ") ;
       
  1814     	INFO_PRINTF1(Kerr) ;
       
  1815     	return KErrGeneral ;
       
  1816 		}
       
  1817     string.Copy(String) ;
       
  1818     char *file = (char *) string.Ptr() ;
       
  1819     file[string.Length()] = '\0' ;
       
  1820     
       
  1821     unlink(file) ;
       
  1822 	if(access(file ,W_OK) < 0) 
       
  1823 		{
       
  1824        if(errno == ENOENT) 
       
  1825     		{
       
  1826     		_LIT(Kaccess ,"Access test(W_OK) for a file created in Read only mode pass") ;
       
  1827     		INFO_PRINTF1(Kaccess) ;
       
  1828     	   
       
  1829     		}
       
  1830     	else 
       
  1831     		{
       
  1832 			_LIT(Kaccess , "Access test failed to set errno value ") ;
       
  1833 			ERR_PRINTF1(Kaccess);
       
  1834 			ret = KErrGeneral ;
       
  1835     		}
       
  1836 		}
       
  1837     else 
       
  1838 		{
       
  1839     	_LIT(Kaccess , "access R_OK for a non existing file failed");
       
  1840     	INFO_PRINTF1(Kaccess) ;
       
  1841     	ret = KErrGeneral ;
       
  1842     	
       
  1843 		}
       
  1844     
       
  1845     
       
  1846     if((fd = open(file , O_CREAT | O_WRONLY , 0444))  < 0) 
       
  1847 		{
       
  1848 		_LIT(Kopen , "Failed to open file " ) ;
       
  1849 		INFO_PRINTF1(Kopen) ;
       
  1850 		return KErrGeneral ; ;
       
  1851 		}
       
  1852     close(fd) ;
       
  1853     
       
  1854     if(access(file , W_OK) < 0) 
       
  1855 		{
       
  1856     	if(errno == EACCES) 
       
  1857     		{
       
  1858     		_LIT(Kaccess ,"Access test(W_OK) for a file created in Read only mode pass") ;
       
  1859     		INFO_PRINTF1(Kaccess) ;
       
  1860     	  
       
  1861     		}
       
  1862     	else  
       
  1863     		{
       
  1864     		ret = KErrGeneral ;
       
  1865     		}
       
  1866 		}
       
  1867     else 
       
  1868 		{
       
  1869     	ret = KErrGeneral ;
       
  1870 		}
       
  1871     chmod(file , S_IWUSR);
       
  1872     return ret ;	
       
  1873     
       
  1874 	}
       
  1875 
       
  1876 //-------------------------------------------------------------------------------
       
  1877 
       
  1878 //  Test case : dup tests for duplicating the file descriptor
       
  1879 //            : returns 0 on success
       
  1880 //            : 8 on failure  
       
  1881 //--------------------------------------------------------------------------------                  
       
  1882 
       
  1883 
       
  1884 TInt CTestSyscalls :: Dup()
       
  1885 	{
       
  1886 	int fd ;
       
  1887 	int newfd ;
       
  1888 	TPtrC String ;
       
  1889 	TBuf8<50> string;
       
  1890 	TInt Expected  ;
       
  1891    
       
  1892 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1893 	INFO_PRINTF1(KTsyscalls) ;
       
  1894 	_LIT( Kdup, "In Dup" );
       
  1895 	INFO_PRINTF1( Kdup);
       
  1896     
       
  1897     //Read the input file name from ini file 
       
  1898 	_LIT( KString, "String" );
       
  1899 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1900 	if(!res)  
       
  1901 		{
       
  1902     	_LIT(Kerr , "Failed to read i/p file name from ini file ") ;
       
  1903     	INFO_PRINTF1(Kerr) ;
       
  1904     	return KErrGeneral ;
       
  1905 		}
       
  1906 	string.Copy(String) ;
       
  1907 	char *file = (char *) string.Ptr() ;
       
  1908 	file[string.Length()] = '\0' ;
       
  1909 	unlink(file) ;
       
  1910       
       
  1911     //Now read expected values 
       
  1912 	_LIT( KExpected, "Expected" );
       
  1913 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  1914     if(!res) 
       
  1915 		{
       
  1916     	_LIT(Kerr, "Failed to read expected values from ini") ;
       
  1917     	INFO_PRINTF1(Kerr) ;
       
  1918     	return KErrGeneral ;
       
  1919 		}
       
  1920     
       
  1921     if(Expected < 0) 
       
  1922 		{
       
  1923     	newfd = dup(-1) ;
       
  1924     	if(errno != EBADF) 
       
  1925     		{
       
  1926     		_LIT(Kerr , "Failed to set errno value") ;
       
  1927     		INFO_PRINTF1(Kerr) ;
       
  1928     		return KErrGeneral ;
       
  1929     		}
       
  1930     	if(newfd != Expected) 
       
  1931     		{
       
  1932     		_LIT(Kerr ,"Expected and the return value dont match") ;
       
  1933     		INFO_PRINTF1(Kerr) ;
       
  1934     		return KErrGeneral ;
       
  1935     		}
       
  1936     	return KErrNone ;
       
  1937 		}
       
  1938   
       
  1939 	if((fd = open(file, O_CREAT | O_RDWR , 0666))  < 0) 
       
  1940 		{
       
  1941 		_LIT(Kopen , "Failed to open file " ) ;
       
  1942 		INFO_PRINTF1(Kopen) ;
       
  1943         return KErrGeneral  ;
       
  1944 		}
       
  1945     
       
  1946     if((newfd = dup(fd)) < 0 )
       
  1947 		{
       
  1948 		close(fd) ;
       
  1949 		 unlink(file) ;
       
  1950     	return KErrGeneral ;
       
  1951 		}
       
  1952     
       
  1953     close(fd) ;
       
  1954     close(newfd) ;
       
  1955     unlink(file) ;
       
  1956     return KErrNone ;
       
  1957     
       
  1958 	}
       
  1959 
       
  1960 
       
  1961 
       
  1962 
       
  1963 
       
  1964 //-------------------------------------------------------------------------------
       
  1965 
       
  1966 //  Test case : dup tests for duplicating the file descriptor in given slot
       
  1967 //            : returns 0 on success
       
  1968 //            : 8 on failure  
       
  1969 //--------------------------------------------------------------------------------                  
       
  1970 
       
  1971 
       
  1972 TInt CTestSyscalls :: Dup2()
       
  1973 	{
       
  1974 	int fd ;
       
  1975 	TInt newfd ;
       
  1976 	TInt Expected ;
       
  1977 	TInt retval ;
       
  1978 	TPtrC String ;
       
  1979 	TBuf8<50> string;
       
  1980   
       
  1981    
       
  1982 	_LIT( KTsyscalls, "Tsyscalls" );
       
  1983 	INFO_PRINTF1(KTsyscalls) ;
       
  1984 	_LIT( Kdup2, "In Dup2" );
       
  1985 	INFO_PRINTF1( Kdup2);
       
  1986     
       
  1987    //Read the input file name from ini file 
       
  1988 	_LIT( KString, "String" );
       
  1989 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  1990 	if(!res)  
       
  1991 		{
       
  1992     	_LIT(Kerr , "Failed to read i/p file name from ini file ") ;
       
  1993     	INFO_PRINTF1(Kerr) ;
       
  1994     	return KErrGeneral ;
       
  1995 		}
       
  1996 	string.Copy(String) ;
       
  1997 	char *file = (char *) string.Ptr() ;
       
  1998 	file[string.Length()] = '\0' ;
       
  1999 	unlink(file) ;
       
  2000    
       
  2001    
       
  2002 	//Now read new fd's to be copied  values 
       
  2003     _LIT( Knewfd, "newfd" );
       
  2004 	res = GetIntFromConfig(ConfigSection(), Knewfd, newfd);
       
  2005 
       
  2006     if(!res) 
       
  2007 		{
       
  2008     	_LIT(Kerr, "Failed to read New fd  value from ini") ;
       
  2009     	INFO_PRINTF1(Kerr) ;
       
  2010     	return KErrGeneral ;
       
  2011 		}
       
  2012     if(newfd > 1000) 
       
  2013     	{
       
  2014     	_LIT(Kerr , "Upper bound for fd not supported \n") ;
       
  2015     	INFO_PRINTF1(Kerr) ;
       
  2016     	return KErrNone ;
       
  2017     	}
       
  2018     
       
  2019     //Now read expected values 
       
  2020     _LIT( KExpected, "Expected" );
       
  2021 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  2022     if(!res) 
       
  2023 		{
       
  2024     	_LIT(Kerr, "Failed to read expected values from ini") ;
       
  2025     	INFO_PRINTF1(Kerr) ;
       
  2026     	return KErrGeneral ;
       
  2027 		}
       
  2028       
       
  2029     
       
  2030   
       
  2031 	if((fd = open(file , O_CREAT | O_RDWR | O_TRUNC , 0666))  < 0) 
       
  2032 		{
       
  2033         _LIT(Kopen , "Failed  to open file ") ;
       
  2034         INFO_PRINTF1(Kopen) ;
       
  2035         return KErrGeneral ;
       
  2036 		}
       
  2037     
       
  2038 	retval = dup2(fd , newfd) ;
       
  2039     
       
  2040     if(retval == Expected ) 
       
  2041 		{
       
  2042     	if(Expected < 0 )  
       
  2043     		{
       
  2044     		if(errno != EBADF) 
       
  2045     			{
       
  2046     			_LIT(Kerr , "Failed to set errno value of dup2 call") ;
       
  2047     			INFO_PRINTF1(Kerr) ;
       
  2048     			return KErrGeneral ;
       
  2049     			}
       
  2050 			close(fd) ;
       
  2051 			close(newfd) ;
       
  2052 			return KErrNone ;
       
  2053     		}
       
  2054     	else   
       
  2055     		{
       
  2056     	    TInt Nbytes ;
       
  2057     		//Write some thing in the new fd and find size  using old fd 
       
  2058     		if((Nbytes = write(fd , "Hello " , 6)) < 0 ) 
       
  2059     			{
       
  2060     		 	_LIT(Kerr , "Failed to write  through old fd ") ;
       
  2061     		 	INFO_PRINTF1(Kerr) ;
       
  2062     			}
       
  2063     	    struct stat buf  ;
       
  2064     	    if(fstat(newfd , &buf ) < 0 )  
       
  2065     			{
       
  2066     	     	_LIT(Kerr, "Failed to stat the file through new fd") ;
       
  2067     	     	INFO_PRINTF1(Kerr) ;
       
  2068     	     	return KErrGeneral ;
       
  2069     			}
       
  2070     	    if(Nbytes != buf.st_size) 
       
  2071     			{
       
  2072     	        _LIT(Kerr , "Failed to dupilcate the file des ") ;
       
  2073     	        INFO_PRINTF1(Kerr) ;
       
  2074     	        return KErrGeneral ;
       
  2075     			}
       
  2076     	    close(fd) ;
       
  2077     	    close(newfd) ;
       
  2078     	    return KErrNone ;
       
  2079     		}
       
  2080 		}
       
  2081     
       
  2082     _LIT(Kerr , "Returned and the expected values are different ") ;
       
  2083     INFO_PRINTF1(Kerr) ;
       
  2084     close(fd) ;
       
  2085     close(newfd) ;
       
  2086     return KErrGeneral ;
       
  2087     
       
  2088 	}
       
  2089 
       
  2090 
       
  2091 
       
  2092 //-------------------------------------------------------------------------------
       
  2093 
       
  2094 //  Test case : rename tests for renaming the existing file
       
  2095 //            : returns 0 on success
       
  2096 //            : 9 on failure  
       
  2097 //--------------------------------------------------------------------------------                  
       
  2098 
       
  2099 
       
  2100 
       
  2101 TInt CTestSyscalls :: Rename()
       
  2102 	{
       
  2103 	int fd ;
       
  2104 	TPtrC String ;
       
  2105 	TBuf8 <50> string ;
       
  2106 	TInt Expected ;
       
  2107 	char File1[50] ; 
       
  2108 	char File2[50] ;
       
  2109    
       
  2110 	_LIT( KTsyscalls, "Tsyscalls" );
       
  2111 	INFO_PRINTF1(KTsyscalls) ;
       
  2112 	_LIT( Krename, "In Rename" );
       
  2113 	INFO_PRINTF1( Krename);
       
  2114    
       
  2115     
       
  2116 	_LIT( KString, "String" );
       
  2117 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2118 	if(!res) 
       
  2119 		{
       
  2120    		_LIT(Kerr , "failed to read input file name ") ;
       
  2121    		INFO_PRINTF1(Kerr) ;
       
  2122    		return KErrGeneral ;
       
  2123 		}
       
  2124    
       
  2125 	string.Copy(String) ; 
       
  2126 	char *file = (char *) string.Ptr() ;
       
  2127 	file[string.Length()] = '\0' ;
       
  2128    
       
  2129 	strcpy(File1 , file) ;
       
  2130 	TPtrC theString ;
       
  2131 	_LIT( KtheString, "theString" );
       
  2132 	res = GetStringFromConfig(ConfigSection(), KtheString, theString );
       
  2133 	if(!res) 
       
  2134 		{
       
  2135    		_LIT(Kerr , "failed to read input file1 name ") ;
       
  2136    		INFO_PRINTF1(Kerr) ;
       
  2137    		return KErrGeneral ;
       
  2138 		}
       
  2139    
       
  2140 	string.Copy(theString) ; 
       
  2141 	file = (char *) string.Ptr() ;
       
  2142 	file[string.Length()] = '\0' ;
       
  2143    
       
  2144 	strcpy(File2 , file);
       
  2145    
       
  2146     //Now read expected value
       
  2147     _LIT( KExpected, "Expected" );
       
  2148 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  2149     if(!res) 
       
  2150 		{
       
  2151     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  2152     	INFO_PRINTF1(Kerr) ;
       
  2153     	return KErrGeneral ;
       
  2154 		}
       
  2155     
       
  2156 	unlink(File1) ;unlink(File2);
       
  2157     
       
  2158     if(Expected < 0) 
       
  2159 		{
       
  2160 		TInt ret ; 
       
  2161 		ret =  rename(File1 , File2) ;
       
  2162        	INFO_PRINTF2(_L("errno is %d"), errno);
       
  2163 		if((errno != EINVAL) && (errno != ENOENT) && (errno != EACCES))  
       
  2164 			{
       
  2165 			_LIT(Kerr , "Failed to set errno value") ;
       
  2166        		INFO_PRINTF1(Kerr) ;
       
  2167        		return KErrGeneral ;
       
  2168 			}
       
  2169 		if(ret == Expected)
       
  2170 			{
       
  2171        		return KErrNone ;
       
  2172 			}
       
  2173        
       
  2174 		_LIT(Kerr , "Expected and the returned values are not matching") ;
       
  2175 		ERR_PRINTF1(Kerr);
       
  2176 		return KErrGeneral ;
       
  2177 		}
       
  2178    
       
  2179     if((fd = open(File1 , O_CREAT | O_RDWR , 0666))  < 0) 
       
  2180 		{
       
  2181 		_LIT(Kopen , "Failed  to create file ") ;
       
  2182         INFO_PRINTF1(Kopen) ;
       
  2183         return KErrGeneral ;
       
  2184 		}
       
  2185 	close(fd) ;
       
  2186     if(rename(File1 , File2) < 0)
       
  2187 		{
       
  2188 		_LIT(Krename , "Failed  to rename  file ") ;
       
  2189         INFO_PRINTF1(Krename) ;
       
  2190 
       
  2191         return KErrGeneral ;
       
  2192 		}
       
  2193     
       
  2194   
       
  2195     return KErrNone ;
       
  2196     
       
  2197 	}
       
  2198 
       
  2199 
       
  2200 //-----------------------------------------------------------------------------
       
  2201 // This function test rename call for existing files and for read-only files
       
  2202 
       
  2203 //------------------------------------------------------------------------------
       
  2204 
       
  2205 #define READ_ONLY_FILE  0
       
  2206 #define NORMAL_FILE		1 
       
  2207 TInt CTestSyscalls :: Rename1() 
       
  2208 	{
       
  2209 	int fd ;
       
  2210 	TPtrC String ;
       
  2211 	TBuf8 <50> string ;
       
  2212 	TInt Command ;
       
  2213 	char File1[50] ; 
       
  2214 	char File2[50] ;
       
  2215    
       
  2216 	_LIT( KTsyscalls, "Tsyscalls" );
       
  2217 	INFO_PRINTF1(KTsyscalls) ;
       
  2218 	_LIT( Krename, "In Rename1" );
       
  2219 	INFO_PRINTF1( Krename);
       
  2220    
       
  2221     
       
  2222 	_LIT( KString, "String" );
       
  2223 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2224 
       
  2225 	if(!res) 
       
  2226 		{
       
  2227    		_LIT(Kerr , "failed to read input file name ") ;
       
  2228    		INFO_PRINTF1(Kerr) ;
       
  2229    		return KErrGeneral ;
       
  2230 		}
       
  2231    
       
  2232 	string.Copy(String) ; 
       
  2233 	char *file = (char *) string.Ptr() ;
       
  2234 	file[string.Length()] = '\0' ;
       
  2235    
       
  2236 	strcpy(File1 , file) ;
       
  2237 	TPtrC theString;
       
  2238 	_LIT( KtheString, "theString" );
       
  2239 	res = GetStringFromConfig(ConfigSection(), KtheString, theString );
       
  2240 	if(!res) 
       
  2241 		{
       
  2242    		_LIT(Kerr , "failed to read input file1 name ") ;
       
  2243    		INFO_PRINTF1(Kerr) ;
       
  2244    		return KErrGeneral ;
       
  2245 		}
       
  2246    
       
  2247 	string.Copy(theString) ; 
       
  2248 	file = (char *) string.Ptr() ;
       
  2249 	file[string.Length()] = '\0' ;
       
  2250    
       
  2251 	strcpy(File2 , file);
       
  2252    
       
  2253 	_LIT( KCommand, "Command" );
       
  2254 	res = GetIntFromConfig(ConfigSection(), KCommand, Command);
       
  2255  
       
  2256 	if(!res) 
       
  2257 		{
       
  2258     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  2259     	INFO_PRINTF1(Kerr) ;
       
  2260     	return KErrGeneral ;
       
  2261 		}
       
  2262     
       
  2263 	fd = open(File1 , O_CREAT | O_RDWR , 0666) ;
       
  2264    		   	
       
  2265    	if(fd < 0 ) 
       
  2266    		{
       
  2267    		_LIT(Kerr , "Failed to open given file1\n") ;
       
  2268    		INFO_PRINTF1(Kerr) ;
       
  2269    		return KErrGeneral ;
       
  2270    		}
       
  2271    	close(fd) ;	   
       
  2272     
       
  2273 	switch(Command) 
       
  2274    		{
       
  2275    		case NORMAL_FILE :
       
  2276    		   	{
       
  2277    		   	int fd = open(File2 , O_CREAT | O_RDWR , 0666) ;
       
  2278    		   	
       
  2279    		   	if(fd < 0 ) 
       
  2280    		   		{
       
  2281    		   		_LIT(Kerr , "Failed to open given file2\n") ;
       
  2282    		   		INFO_PRINTF1(Kerr) ;
       
  2283    		   		return KErrGeneral ;
       
  2284    		   		}
       
  2285    		   		
       
  2286    		   	close(fd) ;
       
  2287    		   	
       
  2288    		   	if(rename(File1 , File2) < 0 ) 
       
  2289    		   		{
       
  2290    		   		_LIT(Kerr , "Rename of existing R/W file failed \n") ;
       
  2291    		   		INFO_PRINTF1(Kerr) ;
       
  2292    		   		return KErrGeneral ;
       
  2293    		   		}
       
  2294    		   	break ;
       
  2295    		   	}
       
  2296    		   	
       
  2297    		case READ_ONLY_FILE :
       
  2298    			{
       
  2299    			int fd =  open(File2 , O_CREAT | O_RDWR , 0444) ;
       
  2300    			
       
  2301    			if(fd < 0) 
       
  2302    				{
       
  2303    				_LIT(Kerr , "Failed to open given file2 \n") ;
       
  2304    				INFO_PRINTF1(Kerr) ;
       
  2305    				return KErrGeneral ;
       
  2306    				}
       
  2307    			close(fd) ;
       
  2308    			
       
  2309    			if(rename(File1 , File2) < 0 ) 
       
  2310    				{
       
  2311    				_LIT(Kerr , "Failed to Rename an Existing Readonly file\n") ;
       
  2312    				INFO_PRINTF1(Kerr) ;
       
  2313    				return KErrGeneral ;
       
  2314    				}
       
  2315    				
       
  2316    		    break ;	
       
  2317    			}
       
  2318 		}	
       
  2319    	return KErrNone ;
       
  2320 	}
       
  2321 
       
  2322 
       
  2323 
       
  2324 //-------------------------------------------------------------------------------
       
  2325 
       
  2326 //  Test case : chmod tests 
       
  2327 //            : 
       
  2328 //--------------------------------------------------------------------------------                  
       
  2329 
       
  2330 
       
  2331 TInt CTestSyscalls :: Chmod()
       
  2332 	{
       
  2333 	int fd ;
       
  2334 	TInt Expected ;
       
  2335 	TBuf8<50> string ;
       
  2336 	TPtrC  String ;
       
  2337    
       
  2338 	_LIT( KTsyscalls, "Tsyscalls" );
       
  2339 	INFO_PRINTF1(KTsyscalls) ;
       
  2340 	_LIT( Kchmod, "In Chmod" );
       
  2341 	INFO_PRINTF1( Kchmod);
       
  2342    
       
  2343 	//Read input file name 
       
  2344 	_LIT( KString, "String" );
       
  2345 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2346 	if(!res)  
       
  2347 		{
       
  2348    		_LIT(Kerr , "failed to read input file name ") ;
       
  2349    		INFO_PRINTF1(Kerr) ;
       
  2350    		return KErrGeneral ;
       
  2351 		}
       
  2352 	string.Copy(String) ;
       
  2353    
       
  2354 	char *file = (char *) string.Ptr() ;
       
  2355 	file[string.Length()] = '\0' ;
       
  2356    
       
  2357 	unlink(file) ;
       
  2358    
       
  2359 	//Now read expected value 
       
  2360 	_LIT( KExpected, "Expected" );
       
  2361 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  2362     if(!res) 
       
  2363 		{
       
  2364     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  2365     	INFO_PRINTF1(Kerr) ;
       
  2366     	return KErrGeneral ;
       
  2367 		}
       
  2368     if(Expected < 0 ) 
       
  2369 		{
       
  2370    
       
  2371 		TInt ret1 , ret2  ;
       
  2372        
       
  2373 		ret1 = chmod(file , S_IWUSR) ;
       
  2374      
       
  2375 		if(ret1 == Expected) 
       
  2376 			{
       
  2377 			if(errno != ENOENT) 
       
  2378 				{
       
  2379       			_LIT(Kerr, "Failed to set errno to ENOENT") ;
       
  2380       			INFO_PRINTF1(Kerr) ;
       
  2381       			return KErrGeneral ;
       
  2382 				}
       
  2383 			}
       
  2384     
       
  2385         if((fd = open(file , O_CREAT | O_RDWR , 0444) ) < 0) 
       
  2386 			{
       
  2387 			_LIT(Kopen , "Failed  to create file ") ;
       
  2388 			INFO_PRINTF1(Kopen) ;
       
  2389 			return KErrGeneral ;
       
  2390 			}
       
  2391         close(fd) ;
       
  2392      
       
  2393 		//chmod and write some thing 
       
  2394         if(chmod(file , S_IWUSR) < 0)
       
  2395 			{
       
  2396 			_LIT(Kerr , "Failed to change the modes of the file ") ;
       
  2397 			INFO_PRINTF1(Kerr) ;
       
  2398 			return KErrGeneral ;
       
  2399 			}
       
  2400     
       
  2401     
       
  2402 		//file  now is this file
       
  2403 		// in read write mode 
       
  2404         ret2 = open(file ,O_RDWR) ;
       
  2405     
       
  2406         if(ret2 >= 0) 
       
  2407 			{
       
  2408 			_LIT(Kok , "Open successfull \n") ;
       
  2409       		INFO_PRINTF1(Kok);
       
  2410       		close(ret2) ;
       
  2411       		ret2 = -1 ;
       
  2412       	    }
       
  2413         unlink(file) ;
       
  2414         if((ret1 == Expected) &&(ret2 == Expected)) 
       
  2415 			{
       
  2416 			return KErrNone ;
       
  2417 			}
       
  2418     
       
  2419 		_LIT(Kerr , "Returned and expected values are different") ;
       
  2420 		INFO_PRINTF1(Kerr) ;
       
  2421 		return KErrGeneral ;
       
  2422 		} //End of if(Expected < 0)
       
  2423     
       
  2424 	if(( fd = open(file , O_CREAT | O_RDWR , 0444 ))< 0 )  
       
  2425 		{	
       
  2426    		_LIT(Kerr , "Failed to open the file ") ;
       
  2427    		INFO_PRINTF1(Kerr) ;
       
  2428    		return KErrGeneral ;
       
  2429 		}
       
  2430 	close(fd) ;   
       
  2431    
       
  2432 	if(chmod(file  , S_IWUSR)  <0 )
       
  2433 		{
       
  2434    		_LIT(Kerr , "Failed to change file mode") ;
       
  2435    		INFO_PRINTF1(Kerr) ;
       
  2436    		return KErrGeneral ;
       
  2437 		}
       
  2438 	unlink(file) ;
       
  2439 	return KErrNone; 
       
  2440 	}
       
  2441 
       
  2442 
       
  2443 //-------------------------------------------------------------------------------
       
  2444 
       
  2445 //  Test case : fchmod tests 
       
  2446 //            : 
       
  2447 //--------------------------------------------------------------------------------                  
       
  2448 
       
  2449 
       
  2450 
       
  2451 TInt CTestSyscalls :: FChmod()
       
  2452 {
       
  2453    
       
  2454    int fd ;
       
  2455    TInt Expected ;
       
  2456    TBuf8<50> string ;
       
  2457    TPtrC  String ;
       
  2458    INFO_PRINTF1(_L("FChmod Test")) ;
       
  2459    _LIT( KTsyscalls, "Tsyscalls" );
       
  2460    INFO_PRINTF1(KTsyscalls) ;
       
  2461    _LIT( Kchmod, "In FChmod" );
       
  2462    INFO_PRINTF1( Kchmod);
       
  2463    
       
  2464    //Read input file name 
       
  2465    _LIT( KString, "String" );
       
  2466     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2467  
       
  2468    if(!res)  
       
  2469    {
       
  2470    	 _LIT(Kerr , "failed to read input file name ") ;
       
  2471    	 INFO_PRINTF1(Kerr) ;
       
  2472    	 return KErrGeneral ;
       
  2473    }
       
  2474    string.Copy(String) ;
       
  2475    
       
  2476    char *file = (char *) string.Ptr() ;
       
  2477    file[string.Length()] = '\0' ;
       
  2478    
       
  2479    unlink(file) ;
       
  2480    
       
  2481    //Now read expected value 
       
  2482    _LIT( KExpected, "Expected" );
       
  2483 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  2484  
       
  2485     if(!res) 
       
  2486     {
       
  2487     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  2488     	INFO_PRINTF1(Kerr) ;
       
  2489     	return KErrGeneral ;
       
  2490     }
       
  2491     
       
  2492  
       
  2493    if(Expected < 0 ) 
       
  2494    {
       
  2495      	fd = open(file , O_CREAT | O_RDWR  , 0666) ;
       
  2496    
       
  2497    		if(fd < 0 ) 
       
  2498    		{
       
  2499    		_LIT(Kerr , "Failed to open the given file name for fchmod \n") ;
       
  2500    		INFO_PRINTF1(Kerr) ;
       
  2501    		return KErrGeneral ;
       
  2502    		}
       
  2503    
       
  2504        TInt ret1 , ret2  ;
       
  2505        
       
  2506        ret1 = fchmod(-1 , 0666) ;
       
  2507      
       
  2508        if(ret1 == Expected) 
       
  2509        {
       
  2510           if(errno != EBADF) 
       
  2511           {
       
  2512       	    _LIT(Kerr, "Failed to set errno to EBADF") ;
       
  2513       	    INFO_PRINTF1(Kerr) ;
       
  2514 			close(fd);
       
  2515       	    return KErrGeneral ;
       
  2516           }
       
  2517      
       
  2518         }
       
  2519     
       
  2520           
       
  2521      //chmod and write some thing 
       
  2522         if(fchmod(fd , 0444 ) < 0)
       
  2523         {
       
  2524            _LIT(Kerr , "Failed to change the modes of the file ") ;
       
  2525            INFO_PRINTF1(Kerr) ;
       
  2526 		   close(fd);
       
  2527            return KErrGeneral ;
       
  2528         }
       
  2529         close(fd) ;
       
  2530     
       
  2531     //file  now is read only and hence it cannot be opened
       
  2532     // in read write mode 
       
  2533         ret2 = open(file ,O_RDWR) ;
       
  2534     
       
  2535         if(ret2 < 0) 
       
  2536         {
       
  2537            if(errno == EACCES) 
       
  2538            	{
       
  2539            	_LIT (Kerr , "Read-only file and hence cannot be opened in r/w mode\n") ;
       
  2540             INFO_PRINTF1(Kerr);
       
  2541            	}
       
  2542            	else 
       
  2543            	{
       
  2544            	 _LIT(Kerr , "open failed to set error value ") ;
       
  2545            	 INFO_PRINTF1(Kerr) ;
       
  2546            	 return KErrGeneral ;	
       
  2547            	}
       
  2548       	    // return KErrNone ;
       
  2549         }
       
  2550         
       
  2551         //Now try to do a chmod on closed fd 
       
  2552         
       
  2553         if(fchmod(fd , 0666) < 0 ) 
       
  2554         	{
       
  2555         	 if(errno != EBADF) 
       
  2556         	 	{
       
  2557         	 	_LIT(Kerr , " fchmod failed to set errno value , for closed fd") ;
       
  2558         	 	INFO_PRINTF1(Kerr) ;
       
  2559 				close(ret2);
       
  2560         	 	return KErrGeneral ;
       
  2561         	 	}
       
  2562         	}     
       
  2563          unlink(file) ;
       
  2564     
       
  2565     
       
  2566     	if((ret1 == Expected) &&(ret2 == Expected)) 
       
  2567     	{
       
  2568 		close(ret2);
       
  2569       	return KErrNone ;
       
  2570     	}
       
  2571     
       
  2572     	_LIT(Kerr , "Returned and expected values are different") ;
       
  2573 		close(ret2);
       
  2574    	 	INFO_PRINTF1(Kerr) ;
       
  2575     	return KErrGeneral ;
       
  2576    	} //End of if(Expected < 0)
       
  2577     
       
  2578     
       
  2579    if(( fd = open(file , O_CREAT | O_RDWR , 0666 ))< 0 )  
       
  2580    {
       
  2581    	  _LIT(Kerr , "Failed to open the file ") ;
       
  2582    	  INFO_PRINTF1(Kerr) ;
       
  2583    	  return KErrGeneral ;
       
  2584    }
       
  2585    //close(fd) ;
       
  2586  
       
  2587    
       
  2588    if(fchmod(fd  , 0444)  <0 )
       
  2589    {
       
  2590    	 _LIT(Kerr , "Failed to change file mode") ;
       
  2591    	 INFO_PRINTF1(Kerr) ;
       
  2592 	 close(fd);
       
  2593    	 return KErrGeneral ;
       
  2594    }
       
  2595    close(fd) ;
       
  2596    unlink(file) ;
       
  2597    return KErrNone; 
       
  2598 }
       
  2599 
       
  2600 
       
  2601 //-------------------------------------------------------------------------------
       
  2602 
       
  2603 //  Test case : chmod of a directory
       
  2604 //            : returns 0 on success
       
  2605 //            :  
       
  2606 //--------------------------------------------------------------------------------                  
       
  2607 
       
  2608 
       
  2609 TInt CTestSyscalls :: Chmod_dir()
       
  2610 	{
       
  2611 	TBuf8<50> string ;
       
  2612 	TPtrC  String ;
       
  2613    
       
  2614 	_LIT( KTsyscalls, "Tsyscalls" );
       
  2615 	INFO_PRINTF1(KTsyscalls) ;
       
  2616 	_LIT( Kchmod, "In Chmod_dir" );
       
  2617 	INFO_PRINTF1( Kchmod);
       
  2618    
       
  2619 	//Read input file name 
       
  2620 	_LIT( KString, "String");
       
  2621 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2622     if(!res)  
       
  2623 		{
       
  2624    		_LIT(Kerr , "failed to read input directory  name from ini file ") ;
       
  2625    		INFO_PRINTF1(Kerr) ;
       
  2626    		return KErrGeneral ;
       
  2627 		}
       
  2628    
       
  2629 	string.Copy(String) ;
       
  2630 	char *dir = (char *) string.Ptr() ;
       
  2631 	dir[string.Length()] = '\0' ;
       
  2632 	rmdir(dir) ;                         //unlink that directory 
       
  2633    
       
  2634 	//create the directory and then change the mode of that directory
       
  2635      
       
  2636 	if(mkdir(dir , S_IWUSR) < 0 )   
       
  2637 		{
       
  2638 		_LIT(Kerr , "create the directory") ;
       
  2639 		ERR_PRINTF1(Kerr);
       
  2640 		return KErrGeneral ;
       
  2641 		}   
       
  2642 	if(chmod(dir , S_IWUSR) < 0)
       
  2643 		{
       
  2644 		_LIT(Kerr , "Failed to change the modes of the directory") ;
       
  2645 		INFO_PRINTF1(Kerr) ;
       
  2646 		rmdir(dir);
       
  2647 		return KErrGeneral ;
       
  2648 		}
       
  2649     
       
  2650     //now change the working directory to the above given directory
       
  2651     
       
  2652     if(chdir(dir) < 0 )   
       
  2653 		{
       
  2654         if(errno != EACCES)
       
  2655 			{
       
  2656 			_LIT(Kerr , "Failed to set the ernno value for the chmod") ;
       
  2657 			INFO_PRINTF1(Kerr) ;
       
  2658 			rmdir(dir);
       
  2659 			return KErrGeneral ;
       
  2660 			}
       
  2661         return KErrNone ;
       
  2662 		}
       
  2663     
       
  2664     //Control comes here only for failur case 
       
  2665     _LIT(Kerr , "Chdir test fails ") ;
       
  2666 	rmdir(dir);
       
  2667     INFO_PRINTF1(Kerr) ;
       
  2668     return KErrNone ;
       
  2669 	}
       
  2670 
       
  2671 //-------------------------------------------------------------------------------
       
  2672 
       
  2673 //  Test case : fchmod of a directory
       
  2674 //            : returns 0 on success
       
  2675 //            :  
       
  2676 //--------------------------------------------------------------------------------                  
       
  2677 
       
  2678 
       
  2679 TInt CTestSyscalls :: FChmod_dir()
       
  2680 {
       
  2681    /*
       
  2682    TBuf8<50> string ;
       
  2683    TPtrC  String ;
       
  2684    
       
  2685    _LIT( KTsyscalls, "Tsyscalls" );
       
  2686    INFO_PRINTF1(KTsyscalls) ;
       
  2687    _LIT( Kchmod, "In Chmod_dir" );
       
  2688    INFO_PRINTF1( Kchmod);
       
  2689    
       
  2690    //Read input file name 
       
  2691   _LIT( KString, "String" );
       
  2692     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2693   
       
  2694    if(!res)  
       
  2695    {
       
  2696    	 _LIT(Kerr , "failed to read input directory  name from ini file ") ;
       
  2697    	 INFO_PRINTF1(Kerr) ;
       
  2698    	 return KErrGeneral ;
       
  2699    }
       
  2700    
       
  2701    string.Copy(String) ;
       
  2702    char *dir = (char *) string.Ptr() ;
       
  2703    dir[string.Length()] = '\0' ;
       
  2704    rmdir(dir) ;                         //unlink that directory 
       
  2705    
       
  2706    //create the directory and then change the mode of that directory
       
  2707      
       
  2708    if(mkdir(dir , 0666) < 0 )   
       
  2709    {
       
  2710       _LIT(Kerr , "create the directory") ;
       
  2711       return KErrGeneral ;
       
  2712    }   
       
  2713    
       
  2714    int fd = open(dir , O_RDONLY ) ;
       
  2715    
       
  2716         
       
  2717     if(fd < 0 ) 
       
  2718     {
       
  2719      _LIT(Kerr , "Failed to a given directory ") ;
       
  2720      INFO_PRINTF1(Kerr) ;
       
  2721      return KErrGeneral ;	
       
  2722     }
       
  2723     
       
  2724     if(fchmod(fd , 0444) < 0)
       
  2725     {
       
  2726      _LIT(Kerr , "Failed to change the modes of the directory") ;
       
  2727      INFO_PRINTF1(Kerr) ;
       
  2728      return KErrGeneral ;
       
  2729       
       
  2730      }
       
  2731     
       
  2732     close(fd) ;
       
  2733     //now change the working directory to the above given directory
       
  2734     
       
  2735     if(chdir(dir) < 0 )   
       
  2736     {
       
  2737         if(errno != EACCES)
       
  2738         {
       
  2739            _LIT(Kerr , "Failed to set the ernno value for the chmod") ;
       
  2740            INFO_PRINTF1(Kerr) ;
       
  2741            return KErrGeneral ;
       
  2742         }
       
  2743         return KErrNone ;
       
  2744     }
       
  2745     
       
  2746     //Control comes here only for failur case 
       
  2747     _LIT(Kerr , "Chdir test fails  No support for permissions for directory ") ;
       
  2748     INFO_PRINTF1(Kerr) ;*/
       
  2749     return KErrNone ;
       
  2750    
       
  2751 
       
  2752 }
       
  2753 
       
  2754 //-------------------------------------------------------------------------------
       
  2755 
       
  2756 //  Test case : exit tests for renaming the existing file
       
  2757 //            : returns 0 on success
       
  2758 //            : 11 on failure  
       
  2759 //
       
  2760 //--------------------------------------------------------------------------------                  
       
  2761 
       
  2762 
       
  2763 TInt CTestSyscalls :: Exit()
       
  2764 	{
       
  2765 	return KErrNone ;
       
  2766     }
       
  2767 
       
  2768 
       
  2769 
       
  2770 //-------------------------------------------------------------------------------
       
  2771 
       
  2772 //  Test case : close tests 
       
  2773 //            : returns 0 on success
       
  2774 //            : 11 on failure  
       
  2775 //
       
  2776 //--------------------------------------------------------------------------------                  
       
  2777 
       
  2778 TInt CTestSyscalls :: Close()
       
  2779 	{
       
  2780 	int fd ;
       
  2781 	TInt Expected ;
       
  2782 	TPtrC String ;
       
  2783 	TBuf8<50> string ;
       
  2784    
       
  2785    
       
  2786 	_LIT( KTsyscalls, "Tsyscalls" );
       
  2787 	INFO_PRINTF1(KTsyscalls) ;
       
  2788 	_LIT( Kclose, "In close" );
       
  2789 	INFO_PRINTF1( Kclose);
       
  2790    
       
  2791    
       
  2792 	//read the file name from ini file 
       
  2793 	_LIT( KString, "String" );
       
  2794 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2795  
       
  2796     if(!res) 
       
  2797 		{
       
  2798     	_LIT(Kerr, "Failed to read file name from ini file") ;
       
  2799     	INFO_PRINTF1(Kerr) ;
       
  2800     	return KErrGeneral ;
       
  2801 		}
       
  2802     
       
  2803     string.Copy(String) ;
       
  2804     
       
  2805     char *file = (char *) string.Ptr() ;
       
  2806     file[string.Length()] = '\0' ;
       
  2807     
       
  2808     unlink(file) ;
       
  2809     //Now read expected value 
       
  2810     _LIT( KExpected, "Expected" );
       
  2811 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  2812 
       
  2813     if(!res) 
       
  2814 		{
       
  2815     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  2816     	INFO_PRINTF1(Kerr) ;
       
  2817     	return KErrGeneral ;
       
  2818 		}
       
  2819     
       
  2820     if(Expected < 0)  
       
  2821 		{
       
  2822 		TInt ret1 , ret2 ;
       
  2823 		TInt Err1 , Err2 ; //store the errvalues
       
  2824     	 //give an invalid fd 
       
  2825 		ret1 = close(-1) ;
       
  2826 		Err1 = errno ;
       
  2827 		ret2 = close(123) ;
       
  2828 		Err2 = errno ;
       
  2829        
       
  2830 		if((ret1 == Expected) &&(ret2 == Expected))
       
  2831 			{
       
  2832        		if((Err1 == EBADF) && (Err2 == EBADF) ) 
       
  2833        			{
       
  2834        	 		return KErrNone ;
       
  2835        			}
       
  2836        		_LIT(Kerr , "Failed to set errno") ;
       
  2837        		INFO_PRINTF1(Kerr) ;
       
  2838        		return KErrGeneral ;
       
  2839 			}
       
  2840        
       
  2841 		else   
       
  2842 			{
       
  2843        		_LIT(Kerr , "Expected and the return values are different ") ;
       
  2844        		INFO_PRINTF1(Kerr) ;
       
  2845        		return KErrGeneral ;
       
  2846 			}
       
  2847        }
       
  2848      
       
  2849 	if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
  2850 		{
       
  2851 		_LIT(Kopen , "Failed  to create file ") ;
       
  2852         INFO_PRINTF1(Kopen) ;
       
  2853         return KErrGeneral ;
       
  2854 		}
       
  2855      
       
  2856     if(close(fd) < 0) 
       
  2857 		{
       
  2858 		_LIT(Kerr , "Failed to close the opened file") ;
       
  2859 		INFO_PRINTF1(Kerr) ;
       
  2860 		unlink(file) ;
       
  2861 		return KErrGeneral  ;	
       
  2862 		}
       
  2863     
       
  2864     unlink(file) ;
       
  2865     return KErrNone ;
       
  2866     
       
  2867 	}
       
  2868 
       
  2869 
       
  2870 
       
  2871 //-------------------------------------------------------------------------------
       
  2872 
       
  2873 //  Test case : mkdir  makes a directory with given name 
       
  2874 //            : returns 0 on success
       
  2875 //            : 13 on failure  
       
  2876 //
       
  2877 //--------------------------------------------------------------------------------                  
       
  2878 
       
  2879 TInt CTestSyscalls :: Mkdir()
       
  2880 	{
       
  2881     TBuf8<50> string ;
       
  2882     TPtrC  String ;
       
  2883     TInt Expected , ret ;     //To store expected and return values
       
  2884     
       
  2885     _LIT( KTsyscalls, "Tsyscalls" );
       
  2886     INFO_PRINTF1(KTsyscalls) ;
       
  2887     _LIT( Kmkdir, "In Mkdir" );
       
  2888     INFO_PRINTF1( Kmkdir);
       
  2889     
       
  2890     
       
  2891     //First read input directory name
       
  2892     _LIT( KString, "String" );
       
  2893     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2894 
       
  2895     if(!res) 
       
  2896 		{
       
  2897 		_LIT(Kerr , "Failed to read input dir name from ini file") ;
       
  2898 		INFO_PRINTF1(Kerr) ;
       
  2899 		return KErrGeneral;
       
  2900 		}
       
  2901     string.Copy(String) ;
       
  2902     
       
  2903     char *DirName = (char *)string.Ptr() ;
       
  2904     
       
  2905     DirName[string.Length()] = '\0' ;
       
  2906      
       
  2907     //Read Expected value  
       
  2908     _LIT( KExpected, "Expected" );
       
  2909 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  2910  
       
  2911     if(!res) 
       
  2912 		{
       
  2913     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  2914     	INFO_PRINTF1(Kerr) ;
       
  2915     	return KErrGeneral ;
       
  2916 		}
       
  2917     
       
  2918     rmdir(DirName) ;
       
  2919      
       
  2920     ret = mkdir(DirName , S_IWUSR) ;
       
  2921     
       
  2922     if(ret == Expected ) 
       
  2923 		{
       
  2924         if(ret < 0 ) 
       
  2925 			{
       
  2926     		if((errno != ENOENT) && (errno != EEXIST)) 
       
  2927     			{
       
  2928     			_LIT(Kerr , "Failed to set errno") ;
       
  2929     			ERR_PRINTF1(Kerr);
       
  2930          		ret=  KErrGeneral ;
       
  2931     			}
       
  2932     		else
       
  2933 				{
       
  2934                 ret = KErrNone ; 
       
  2935 				}
       
  2936 			}
       
  2937 		}
       
  2938     else 
       
  2939 		{
       
  2940     	 _LIT(Kerr , "Expected and the return values are different ") ;
       
  2941     	 ERR_PRINTF1(Kerr) ;
       
  2942     	 ret = KErrNone ; 
       
  2943 		}
       
  2944     return ret;
       
  2945     
       
  2946 	}
       
  2947    
       
  2948 
       
  2949 
       
  2950 //-------------------------------------------------------------------------------
       
  2951 
       
  2952 //  Test case : rmdir  removes the given direcorty 
       
  2953 //            : returns 0 on success
       
  2954 //            : -1 on failure  
       
  2955 //
       
  2956 //--------------------------------------------------------------------------------                  
       
  2957 
       
  2958 TInt CTestSyscalls :: Rmdir()
       
  2959 	{
       
  2960 	_LIT( KTsyscalls, "Tsyscalls" );
       
  2961 	INFO_PRINTF1(KTsyscalls) ;
       
  2962 	_LIT( Krmdir, "In Rmdir" );
       
  2963 	INFO_PRINTF1( Krmdir);
       
  2964    
       
  2965 	TInt Expected  ;
       
  2966 	TPtrC String ;
       
  2967 	TBuf8<50>string ;
       
  2968 	TInt ret1 , ret2 ;
       
  2969 
       
  2970 	_LIT( KString, "String" );
       
  2971 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  2972 	if(!res) 
       
  2973 		{
       
  2974    		_LIT(Kerr , "Failed to read input dir name from ini file ") ;
       
  2975    		INFO_PRINTF1(Kerr) ;
       
  2976    		return KErrGeneral ;
       
  2977 		}
       
  2978 	string.Copy(String) ;
       
  2979    
       
  2980 	char *DirName = (char *) string.Ptr() ;
       
  2981 	DirName[string.Length()] = '\0' ;
       
  2982    
       
  2983 	_LIT( KExpected, "Expected" );
       
  2984 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  2985 	if(!res) 
       
  2986 		{
       
  2987    		_LIT(Kerr , "Failed to read input expected value ini file") ;
       
  2988    		INFO_PRINTF1(Kerr) ;
       
  2989    		return KErrGeneral ;
       
  2990 		}
       
  2991    
       
  2992 	if(Expected < 0) 
       
  2993 		{
       
  2994    		ret1 = rmdir(DirName) ;
       
  2995    		if(ret1 == Expected ) 
       
  2996    			{   
       
  2997    	        if((errno != ENOENT)  && (errno != ENOTEMPTY))
       
  2998    				{
       
  2999    	        	_LIT(Kerr , "Failed to set errno value ") ;
       
  3000    	        	INFO_PRINTF1(Kerr) ;
       
  3001    	        	return KErrGeneral ;
       
  3002    				}
       
  3003 			}
       
  3004    	    else 
       
  3005    			{
       
  3006    			_LIT(Kerr , "Expected and actual values are different ") ;
       
  3007    			INFO_PRINTF1(Kerr) ;
       
  3008    	    	return KErrGeneral ;
       
  3009    			}
       
  3010    	    
       
  3011    	    //Now create  a directory , create some files 
       
  3012    	    // in the directory  and then try to delete it  
       
  3013    	    
       
  3014    	    if(mkdir(DirName ,S_IWUSR)  < 0) 
       
  3015 			{
       
  3016 			if(errno != EEXIST) 
       
  3017 				{
       
  3018 				_LIT(Kerr , "Failed to make dir entry") ;
       
  3019     			INFO_PRINTF1(Kerr) ;
       
  3020     			return KErrGeneral ;
       
  3021 				}
       
  3022 			}
       
  3023 		//Creaty an entry in the directory
       
  3024 		char FullPath[50] ;
       
  3025 		strcpy(FullPath , DirName) ;
       
  3026 		strcat(FullPath , "\\TEST_DIR.txt") ;
       
  3027 		TInt fd ;
       
  3028        
       
  3029 		if((fd = open(FullPath , O_CREAT | O_RDWR , 0666 ))< 0) 
       
  3030 			{
       
  3031    			_LIT(Kerr , "Failed to create entries in the newly created dir") ;
       
  3032    			INFO_PRINTF1(Kerr) ;
       
  3033    			return KErrGeneral ;
       
  3034 			}
       
  3035        
       
  3036 		close (fd) ;
       
  3037        
       
  3038 		ret2 = rmdir(DirName) ;
       
  3039        
       
  3040 		if(ret2 == Expected) 
       
  3041 			{
       
  3042 			TInt Ret = KErrNone ;
       
  3043 			if(errno != ENOTEMPTY)   
       
  3044 				{	
       
  3045          		_LIT(Kerr , "Failed to set errno value for rmdir") ;
       
  3046          		INFO_PRINTF1(Kerr) ;
       
  3047          		Ret = KErrGeneral ;
       
  3048 				}
       
  3049 			unlink(FullPath) ;
       
  3050 			rmdir(DirName) ;
       
  3051 			return Ret ;
       
  3052 			}
       
  3053 		_LIT(Kerr , "Expected and returned values are different") ;
       
  3054 		INFO_PRINTF1(Kerr) ;
       
  3055 		return  KErrGeneral ;
       
  3056 		}          //End of if(Expected < 0)
       
  3057 	if(mkdir(DirName ,S_IWUSR)  < 0) 
       
  3058 		{
       
  3059         _LIT(Kerr , "Failed to make dir entry") ;
       
  3060     	INFO_PRINTF1(Kerr) ;
       
  3061     	return KErrGeneral ;
       
  3062 		}
       
  3063     
       
  3064     ret2 = rmdir(DirName) ;
       
  3065     
       
  3066     if(ret2 != Expected) 
       
  3067 		{
       
  3068     	_LIT(KErr , "Return and expected values are different") ;
       
  3069     	INFO_PRINTF1(KErr) ;
       
  3070     	return KErrGeneral;
       
  3071     	}
       
  3072     return KErrNone ;
       
  3073         
       
  3074 	}
       
  3075 
       
  3076 
       
  3077 //For test of \.
       
  3078 
       
  3079 TInt CTestSyscalls :: Rmdir1()
       
  3080 	{
       
  3081 	if(mkdir("C:\\Test\\TestDir" ,S_IWUSR)  < 0) 
       
  3082 		{
       
  3083     	_LIT(Kerr , "Failed to make dir entry") ;
       
  3084     	INFO_PRINTF1(Kerr) ;
       
  3085     	return KErrGeneral ;
       
  3086 		}
       
  3087     
       
  3088     if(rmdir("C:\\Test\\TestDir\\." )  < 0) 
       
  3089 		{
       
  3090 		TInt Err = errno ;
       
  3091         if(errno != EINVAL) 
       
  3092 			{
       
  3093 			_LIT(Kerr , "Failed to make dir entry") ;
       
  3094     		INFO_PRINTF1(Kerr) ;
       
  3095     		return KErrGeneral ;
       
  3096 			}
       
  3097 		return KErrGeneral ;
       
  3098 		}
       
  3099      return KErrNone ;
       
  3100 	}
       
  3101 
       
  3102 //-------------------------------------------------------------------------------
       
  3103 
       
  3104 //  Test case : Chdir_Rmdir  removes the given direcorty 
       
  3105 //            : returns 0 on success
       
  3106 //            : 
       
  3107 //
       
  3108 //--------------------------------------------------------------------------------                  
       
  3109 
       
  3110 TInt CTestSyscalls :: Rmdir_Chdir()
       
  3111 	{
       
  3112 	_LIT( KTsyscalls, "Tsyscalls" );
       
  3113 	INFO_PRINTF1(KTsyscalls) ;
       
  3114 	_LIT( Krmdir, "In Rmdir_Chdir" );
       
  3115 	INFO_PRINTF1( Krmdir);
       
  3116    
       
  3117 	// TInt Expected  ;
       
  3118 	TPtrC String ;
       
  3119 	TBuf8<50>string ;
       
  3120   
       
  3121 	//TInt exists = 0 ;
       
  3122  
       
  3123 	_LIT( KString, "String" );
       
  3124 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  3125 	if(!res) 
       
  3126 		{
       
  3127    		_LIT(Kerr , "Failed to read input dir name from ini file ") ;
       
  3128    		INFO_PRINTF1(Kerr) ;
       
  3129    		return KErrGeneral ;
       
  3130 		}
       
  3131 	string.Copy(String) ;
       
  3132    
       
  3133 	char *DirName = (char *) string.Ptr() ;
       
  3134 	DirName[string.Length()] = '\0' ;
       
  3135    //Now create  a directory , create some files 
       
  3136    // in the directory  and then try to delete it  
       
  3137 	rmdir(DirName) ;
       
  3138    	    
       
  3139 	if(mkdir(DirName ,S_IWUSR)  < 0) 
       
  3140 		{
       
  3141 		if(errno != EEXIST) 
       
  3142 			{
       
  3143 			_LIT(Kerr , "Failed to make dir entry") ;
       
  3144 			INFO_PRINTF1(Kerr) ;
       
  3145 			return KErrGeneral ;
       
  3146 			}
       
  3147 		}
       
  3148        
       
  3149 	//Now chage the current working directory to the new one 
       
  3150 	// and then try to  remove that directory
       
  3151        
       
  3152     if(chdir(DirName) < 0 )   
       
  3153 		{
       
  3154 		_LIT(Kerr , "Failed to change the current working directory to the given") ;
       
  3155 		INFO_PRINTF1(Kerr) ;
       
  3156 		return KErrGeneral ;
       
  3157 		}
       
  3158       
       
  3159     //Now try to delete the current working directory.
       
  3160        
       
  3161     if(rmdir(DirName) > 0 )   
       
  3162 		{
       
  3163        	_LIT(Kerr , "Rmdir should fail as the some process is using this as currnet working directory") ;
       
  3164        	INFO_PRINTF1(Kerr) ;
       
  3165        	return KErrGeneral ;
       
  3166 		}
       
  3167     return KErrNone ;
       
  3168         
       
  3169 	}
       
  3170 //-------------------------------------------------------------------------------
       
  3171 
       
  3172 //  Test case : fsync  tests 
       
  3173 //            : returns 0 on success
       
  3174 //            : -1 on failure  
       
  3175 //
       
  3176 //--------------------------------------------------------------------------------                  
       
  3177 
       
  3178 
       
  3179 TInt CTestSyscalls :: Fsync()
       
  3180 	{
       
  3181        
       
  3182 	int fd ;
       
  3183 	TBuf8<50> string ;
       
  3184 	TPtrC String ;
       
  3185 	TInt Expected ;
       
  3186 	TInt ret ;
       
  3187  
       
  3188 	_LIT( KString, "String" );
       
  3189     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  3190     if(!res) 
       
  3191 		{
       
  3192    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  3193    		INFO_PRINTF1(Kerr) ;
       
  3194    		return KErrGeneral ;
       
  3195 		}
       
  3196 	string.Copy(String) ;
       
  3197    
       
  3198 	char *file = (char *) string.Ptr() ;
       
  3199 	file[string.Length()] = '\0' ;
       
  3200    
       
  3201 	//Now read expected value
       
  3202  
       
  3203 	_LIT( KExpected, "Expected" );
       
  3204 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  3205     if(!res) 
       
  3206 		{ 
       
  3207    		_LIT(Kerr , "Failed to read Expected value from ini file ") ;
       
  3208    		INFO_PRINTF1(Kerr) ;
       
  3209    		return KErrGeneral ;  
       
  3210 		}
       
  3211 	_LIT( KTsyscalls, "Tsyscalls" );
       
  3212 	INFO_PRINTF1(KTsyscalls) ;
       
  3213 	_LIT( Kfsync, "In Fsync" );
       
  3214 	INFO_PRINTF1(Kfsync);
       
  3215    
       
  3216 	if(Expected < 0) 
       
  3217 		{    
       
  3218    		ret = fsync(-1) ;
       
  3219    		if(ret != 0)
       
  3220    			{
       
  3221 	   		if(errno != EBADF)   
       
  3222 	   			{
       
  3223 	   	   		_LIT(Kerr , "Failed to set errno value ") ;
       
  3224 	   	   		INFO_PRINTF1(Kerr) ;
       
  3225 	   	   		return KErrGeneral ;
       
  3226 	   			}
       
  3227 			}
       
  3228 		else 
       
  3229 			{
       
  3230 	   		_LIT(Kerr , "fsync failed") ;
       
  3231    	   		INFO_PRINTF1(Kerr) ;
       
  3232    	   		return KErrGeneral;
       
  3233    			}
       
  3234    	   return KErrNone ;
       
  3235 	}
       
  3236   
       
  3237 	if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0) 
       
  3238 		{
       
  3239 		_LIT(Kopen , "Failed  to create file ") ;
       
  3240         INFO_PRINTF1(Kopen) ;
       
  3241         return KErrGeneral ;
       
  3242 		}
       
  3243      
       
  3244 	if(fsync(fd) < 0) 
       
  3245 		{
       
  3246    		_LIT(Kerr , "Fsync failed ") ;
       
  3247    		INFO_PRINTF1(Kerr) ;
       
  3248    		return KErrGeneral ;
       
  3249 		}
       
  3250 	return KErrNone 	;
       
  3251     }
       
  3252 
       
  3253 //-------------------------------------------------------------------------------
       
  3254 
       
  3255 //  Test case : UTIMES  tests 
       
  3256 //            : returns 0 on success
       
  3257 //            : 16 on failure  
       
  3258 //
       
  3259 //--------------------------------------------------------------------------------                  
       
  3260 
       
  3261 
       
  3262 TInt CTestSyscalls :: Utimes()
       
  3263 	{
       
  3264     
       
  3265     TBuf8<50> string ;
       
  3266     TPtrC String ;
       
  3267  
       
  3268     TInt  timeVal  = 0;
       
  3269    
       
  3270     TInt fd ;
       
  3271     _LIT( KTsyscalls, "Tsyscalls" );
       
  3272     INFO_PRINTF1(KTsyscalls) ;
       
  3273     _LIT( Kutimes, "In Utimes" );
       
  3274     INFO_PRINTF1(Kutimes);
       
  3275    
       
  3276 	struct stat  buf ;
       
  3277 	buf.st_atime=0;
       
  3278 	struct timeval tim[2] ;
       
  3279    
       
  3280     fd = open("C:\\Test\\123_123.txt" , O_CREAT | O_RDWR , 0666) ;
       
  3281    
       
  3282 	if(fd < 0) 
       
  3283    		{
       
  3284    		_LIT(Kerr , "failed to open the file") ;
       
  3285    		INFO_PRINTF1(Kerr) ;
       
  3286    		return KErrGeneral ;
       
  3287    		}
       
  3288 	tim[0].tv_sec = 0 ; tim[0].tv_usec = 0;
       
  3289 	tim[1].tv_sec = 0 ; tim[1].tv_usec = 0;
       
  3290 
       
  3291 	close(fd) ;
       
  3292 	//Read the  input file name
       
  3293 	_LIT( KString, "String" );
       
  3294     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  3295 	if(!res) 
       
  3296 		{
       
  3297    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  3298    		INFO_PRINTF1(Kerr) ;
       
  3299    		return KErrGeneral ;
       
  3300 		}
       
  3301 	string.Copy(String) ;
       
  3302 	
       
  3303     //Read the time 
       
  3304 	_LIT( KtimeVal, "timeVal" );
       
  3305 	res = GetIntFromConfig(ConfigSection(), KtimeVal, timeVal);
       
  3306  
       
  3307 	if(!res) 
       
  3308 		{ 
       
  3309 		_LIT(Kerr , "Failed to read time value from ini file ") ;
       
  3310 		INFO_PRINTF1(Kerr) ;
       
  3311 		return KErrGeneral ;  
       
  3312 		}
       
  3313 	buf.st_atime += timeVal  ;
       
  3314 	if(utimes("C:\\Test\\123_123.txt"  , tim) < 0 ) 
       
  3315 		{
       
  3316      
       
  3317 		_LIT(Kerr, "Utime failed") ;
       
  3318 		INFO_PRINTF1(Kerr) ;
       
  3319 		return KErrGeneral ;
       
  3320 		}
       
  3321 	return KErrNone ;
       
  3322 	}
       
  3323     
       
  3324  
       
  3325  
       
  3326   
       
  3327   //-------------------------------------------------------------------------------
       
  3328 
       
  3329 //  Test case : UTIMES  tests 
       
  3330 //            : returns 0 on success
       
  3331 //            : 16 on failure  
       
  3332 //
       
  3333 //--------------------------------------------------------------------------------                  
       
  3334 
       
  3335 
       
  3336 TInt CTestSyscalls :: Utime()
       
  3337 	{
       
  3338     
       
  3339     TInt Expected ;
       
  3340     TInt ret ;
       
  3341     TPtrC String ;
       
  3342     TBuf8<50> string ;
       
  3343     TInt timeVal ;
       
  3344     
       
  3345 	struct utimbuf *tim = NULL ;
       
  3346     char *rfile ;
       
  3347     int fd = 0;
       
  3348   
       
  3349 	_LIT( KTsyscalls, "Tsyscalls" );
       
  3350 	INFO_PRINTF1(KTsyscalls) ;
       
  3351 	_LIT( Kutime, "In Utime" );
       
  3352     INFO_PRINTF1(Kutime);
       
  3353 
       
  3354 
       
  3355 
       
  3356 	//Read the  input file name
       
  3357 	_LIT( KString, "String" );
       
  3358     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  3359     if(!res) 
       
  3360 		{
       
  3361    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  3362    		INFO_PRINTF1(Kerr) ;
       
  3363    		return KErrGeneral ;
       
  3364 		}
       
  3365 	string.Copy(String) ;
       
  3366 	rfile = (char *) string.Ptr() ;
       
  3367     //Read the time 
       
  3368 
       
  3369 	_LIT( KtimeVal, "timeVal" );
       
  3370 	res = GetIntFromConfig(ConfigSection(), KtimeVal, timeVal);
       
  3371 	if(!res) 
       
  3372 		{ 
       
  3373 		_LIT(Kerr , "Failed to read time value from ini file ") ;
       
  3374 		INFO_PRINTF1(Kerr) ;
       
  3375 		return KErrGeneral ;  
       
  3376 		}
       
  3377     
       
  3378 	rfile[string.Length()] = '\0' ;
       
  3379    
       
  3380 	//Now read expected value 
       
  3381 	_LIT( KExpected, "Expected" );
       
  3382 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  3383 	if(!res) 
       
  3384 		{ 
       
  3385    		_LIT(Kerr , "Failed to read Expected value from ini file ") ;
       
  3386    		INFO_PRINTF1(Kerr) ;
       
  3387    		return KErrGeneral ;  
       
  3388 		}
       
  3389 	unlink(rfile) ;
       
  3390 
       
  3391  
       
  3392     tim =(struct utimbuf *) calloc(1 , sizeof(struct timeval)) ; 
       
  3393     
       
  3394     //Negative tests 
       
  3395     if(Expected < 0 ) 
       
  3396 		{
       
  3397       	tim->actime = (time_t) timeVal ;
       
  3398       	tim->modtime = (time_t) timeVal ;
       
  3399       	
       
  3400       	ret = utime(rfile , tim) ;          //Try to do utime on non existent file
       
  3401       	
       
  3402       	if(ret == Expected ) 
       
  3403       		{
       
  3404 			if(errno != ENOENT)   
       
  3405       			{
       
  3406 				_LIT(Kerr ,"Failed to set errno value  ") ;
       
  3407       			INFO_PRINTF1(Kerr) ;
       
  3408       			close(fd) ;
       
  3409       			free(tim);
       
  3410       			return KErrGeneral ;
       
  3411       			}
       
  3412 			free(tim);      			
       
  3413       	    return KErrNone ;
       
  3414       		}
       
  3415       	
       
  3416 		} //End of if(Expected < 0)
       
  3417     
       
  3418     struct stat buf1;
       
  3419      
       
  3420     if((fd = open(rfile , O_CREAT | O_RDWR , 0666))  < 0) 
       
  3421 		{
       
  3422 		_LIT(Kopen , "Failed  to create file ") ;
       
  3423         INFO_PRINTF1(Kopen) ;
       
  3424         free(tim);
       
  3425         return KErrGeneral ;
       
  3426 		}
       
  3427      
       
  3428     
       
  3429     if(fstat(fd , &buf1) <0 )  
       
  3430 		{
       
  3431     	_LIT(Kerr , "Failed to stat the given file ") ;
       
  3432     	INFO_PRINTF1(Kerr) ;
       
  3433     	free(tim);
       
  3434     	return KErrGeneral ;
       
  3435 		}
       
  3436     
       
  3437     buf1.st_atime += timeVal ;
       
  3438     tim->actime = buf1.st_atime ; 
       
  3439     tim->modtime = buf1.st_atime  ; 
       
  3440 	// ret = utime(rfile , tim) ;
       
  3441     close(fd) ;
       
  3442     
       
  3443     if(utime(rfile , tim)  < 0) 
       
  3444 		{
       
  3445 		_LIT(Kerr , "Failed to set the access and modification time stamps of the given file ") ;
       
  3446 		INFO_PRINTF1(Kerr) ;
       
  3447 		free(tim);
       
  3448 		return KErrGeneral ; 
       
  3449 		}
       
  3450 	free(tim);
       
  3451     return KErrNone ;
       
  3452 	}
       
  3453     
       
  3454   
       
  3455 //-------------------------------------------------------------------------------
       
  3456 
       
  3457 //  Test case : CHDIR  tests 
       
  3458 //            : returns 0 on success
       
  3459 //            : 17(CHDIR_FAIL) on failure  
       
  3460 //
       
  3461 //--------------------------------------------------------------------------------                  
       
  3462 
       
  3463 
       
  3464 TInt CTestSyscalls :: Chdir()
       
  3465 	{
       
  3466 
       
  3467 	TBuf8<50> string ;
       
  3468 	TPtrC String ;
       
  3469 	TInt Expected ;
       
  3470 	TInt ret ;
       
  3471    
       
  3472 	_LIT( KTsyscalls, "Tsyscalls" );
       
  3473 	INFO_PRINTF1(KTsyscalls) ;
       
  3474 	_LIT( Kchdir, "In Chdir" );
       
  3475 	INFO_PRINTF1(Kchdir);
       
  3476    
       
  3477     //Read dir to be changed
       
  3478     _LIT( KString, "String" );
       
  3479     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  3480 	if(!res) 
       
  3481 		{
       
  3482    		_LIT(Kerr, "Failed to read input dir name from ini file ") ;
       
  3483    		INFO_PRINTF1(Kerr) ;
       
  3484    		return KErrGeneral ;
       
  3485 		}
       
  3486 	string.Copy(String) ;
       
  3487    
       
  3488 	char *dir = (char *) string.Ptr() ;
       
  3489    
       
  3490 	dir[string.Length()] = '\0' ;
       
  3491      
       
  3492 	//Now read expected value 
       
  3493    	_LIT( KExpected, "Expected" );
       
  3494 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  3495     if(!res) 
       
  3496 		{ 
       
  3497    		_LIT(Kerr , "Failed to read Expected value from ini file ") ;
       
  3498    		INFO_PRINTF1(Kerr) ;
       
  3499    		return KErrGeneral ;  
       
  3500 		}
       
  3501 	ret = chdir(dir) ;
       
  3502   
       
  3503 	if(ret  == Expected)   
       
  3504 		{
       
  3505 		if(ret < 0 ) 
       
  3506 			{
       
  3507 			if(errno != ENOENT) 
       
  3508    				{
       
  3509    	  			_LIT(Kerr , "Failed to set errno value ") ;
       
  3510    	  			INFO_PRINTF1(Kerr) ;
       
  3511    	  			return KErrGeneral ;
       
  3512    				}
       
  3513 			}
       
  3514    		return KErrNone ;
       
  3515 		}
       
  3516  	_LIT(Kerr, "Expected and return value are different") ;
       
  3517  	INFO_PRINTF1(Kerr);
       
  3518 	return KErrGeneral ;
       
  3519     }
       
  3520 
       
  3521 
       
  3522 
       
  3523 //-------------------------------------------------------------------------------
       
  3524 
       
  3525 //  Test case : FCNTL tests 
       
  3526 //            : returns 0 on success
       
  3527 //            : KErrGeneral on failure  
       
  3528 //
       
  3529 //--------------------------------------------------------------------------------                  
       
  3530 
       
  3531 #define F_BADCMD  999
       
  3532 
       
  3533 TInt CTestSyscalls :: Fcntl()
       
  3534 	{
       
  3535 
       
  3536 	int fd ;
       
  3537 	TBuf8<50> string ;
       
  3538 	TPtrC String ;
       
  3539 	TInt command ;
       
  3540   
       
  3541 	_LIT( KTsyscalls, "Tsyscalls" );
       
  3542 	INFO_PRINTF1(KTsyscalls) ;
       
  3543 	_LIT( Kfcntl, "In Fcntl" );
       
  3544 	INFO_PRINTF1(Kfcntl);
       
  3545 	//Read file name 
       
  3546 	_LIT( KString, "String" );
       
  3547 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  3548  
       
  3549 	if(!res) 
       
  3550 		{
       
  3551    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  3552    		INFO_PRINTF1(Kerr) ;
       
  3553    		return KErrGeneral ;
       
  3554 		}
       
  3555 	string.Copy(String) ;
       
  3556    
       
  3557 	char *file = (char *) string.Ptr() ;
       
  3558    
       
  3559 	file[string.Length()] = '\0' ;
       
  3560    
       
  3561     //Read input command 
       
  3562     _LIT( Kcommand, "command" );
       
  3563     res = GetIntFromConfig(ConfigSection(), Kcommand, command);
       
  3564     if(!res)   
       
  3565 		{
       
  3566    		_LIT(Kerr , "Failed to read the input command ") ;
       
  3567    		INFO_PRINTF1(Kerr) ;
       
  3568    		return KErrGeneral ;
       
  3569 		}
       
  3570 	remove(file);
       
  3571 	if((fd = open(file , O_CREAT | O_RDWR | O_TRUNC  , 0666))  < 0) 
       
  3572 		{
       
  3573 		_LIT(Kopen , "Failed  to create file ") ;
       
  3574 		INFO_PRINTF1(Kopen) ;
       
  3575 		return KErrGeneral  ;
       
  3576 		}
       
  3577    
       
  3578 	switch(command)   
       
  3579 		{
       
  3580    		case F_GETFL :
       
  3581    			{
       
  3582    			TInt flags ;
       
  3583    			flags = fcntl(fd , F_GETFL ) ;
       
  3584    			if(flags != O_RDWR )   
       
  3585   				{
       
  3586   				_LIT(Kerr , "Flag values returned is not proper ") ;
       
  3587    				INFO_PRINTF1(Kerr) ;
       
  3588    				return KErrGeneral ;
       
  3589   				}
       
  3590    			else  
       
  3591    				{
       
  3592    	    		_LIT(Kerr , "Flags returned are correct") ;
       
  3593    	    		INFO_PRINTF1(Kerr) ;
       
  3594    	    		return KErrNone ;
       
  3595    				}
       
  3596 			}              //End of F_GETFL 
       
  3597    	      
       
  3598    		case  F_SETFL :
       
  3599    			{
       
  3600     		//First read the flag value to be set 
       
  3601    	   		TInt flag ;
       
  3602    	   		_LIT( Kflag, "flag" );
       
  3603 			res = GetIntFromConfig(ConfigSection(), Kflag, flag);
       
  3604    	   		if(!res)  
       
  3605    	   			{
       
  3606    	   			_LIT(Kerr , "Failed to read input flag value to be set ") ;
       
  3607    	   			INFO_PRINTF1(Kerr) ;
       
  3608    	   			return KErrGeneral ;
       
  3609    	   			}
       
  3610    	   		if(fcntl(fd , F_SETFL , O_APPEND) < 0 ) 
       
  3611    	   			{
       
  3612    	   			_LIT(Kerr , "Failed to set the flags of the opened file \n") ;
       
  3613    	   	  		INFO_PRINTF1(Kerr) ;
       
  3614    	   	  		return KErrGeneral ;
       
  3615    	   			}
       
  3616    	   		if((flag = fcntl(fd , F_GETFL)) != (O_RDWR | O_APPEND)) 
       
  3617    	   			{
       
  3618    	   			_LIT(Kerr , "fcntl for F_SETFL Failed") ;
       
  3619    	   			INFO_PRINTF1(Kerr) ;
       
  3620    	   			return  KErrGeneral ;	
       
  3621    	   			}
       
  3622    	   	   }              //End of F_SETFL 
       
  3623    	   
       
  3624    	   
       
  3625    		case   F_DUPFD :           //Duplicate file descriptor 
       
  3626    			{
       
  3627    	   		TInt Newfd ;
       
  3628    	   		Newfd = fcntl(fd , F_DUPFD ,fd -1) ;
       
  3629    	   		if(Newfd < (fd - 1 )) 
       
  3630    	   			{
       
  3631    	  			_LIT(Kerr , "failed to duplicate file descriptor") ;
       
  3632    	   			INFO_PRINTF1(Kerr) ;
       
  3633    	   			return KErrGeneral ;
       
  3634    	   			}
       
  3635    	   		close(Newfd); 
       
  3636    	   		Newfd = fcntl(fd ,  F_DUPFD , fd )  ;
       
  3637    	   		close (Newfd); 
       
  3638    			if(Newfd < fd ) 
       
  3639    	   			{
       
  3640    	  			_LIT(Kerr , "failed to duplicate file descriptor") ;
       
  3641    	   			INFO_PRINTF1(Kerr) ;
       
  3642    	   			return KErrGeneral ;
       
  3643    	   			}
       
  3644    	   		close(Newfd);
       
  3645    	   		Newfd = fcntl(fd ,  F_DUPFD , fd+1 )  ;
       
  3646    	   		//Write something in using new file descriptor
       
  3647    	   		if(Newfd < (fd +1 )) 
       
  3648    	   			{
       
  3649    	  			_LIT(Kerr , "failed to duplicate file descriptor") ;
       
  3650    	   			INFO_PRINTF1(Kerr) ;
       
  3651    	   			return KErrGeneral ;
       
  3652    	   			}
       
  3653    	   		int nbytes ;
       
  3654    	   		if((nbytes  = write(Newfd , "Hello" , 6)) < 0 )
       
  3655    	   			{
       
  3656    	   	 		_LIT(Kerr , "dup value returned is improper " ) ;
       
  3657    	   	 		INFO_PRINTF1(Kerr) ;
       
  3658    	   	 		return KErrGeneral ;
       
  3659    	   			}
       
  3660 			//Now find out the size of the file through old fd 
       
  3661    	  	
       
  3662    	  		struct stat buf ;
       
  3663    	 
       
  3664    	  		if(fstat(fd , &buf) < 0 ) 
       
  3665    	  			{
       
  3666    				_LIT(Kerr , "Failed to stat the file ") ;
       
  3667    	  			INFO_PRINTF1(Kerr) ;
       
  3668    	  			return KErrGeneral ;
       
  3669    	  			}
       
  3670    	  	
       
  3671    	  		if(buf.st_size != nbytes) 
       
  3672    	  			{
       
  3673    	  			_LIT(Kerr , "File des are not duplicated properly") ;
       
  3674    	  			INFO_PRINTF1(Kerr);
       
  3675    	  			return KErrGeneral ;
       
  3676    	  			}
       
  3677    	  		close(fd) ; 
       
  3678    	  		close(Newfd);
       
  3679    	   		break ;
       
  3680    			}             //End of F_DUPFL 
       
  3681 
       
  3682 	case  F_GETFD :              //get close on exec flags 
       
  3683    		{
       
  3684    	  	TInt cflag ;
       
  3685    	  	
       
  3686    	  	cflag = fcntl(fd , F_GETFD ) ;
       
  3687    	  	
       
  3688    	  	if(cflag < 0 ) 
       
  3689    	  		{
       
  3690    	  		_LIT(Kerr , "failed to get close on exec flags") ;
       
  3691    	  		INFO_PRINTF1(Kerr) ;
       
  3692    	  		return KErrGeneral ;
       
  3693    	  		}
       
  3694 
       
  3695    	  	break  ;
       
  3696    		}             //End of F_GETFD
       
  3697    	
       
  3698 	case F_SETFD :                 //Set close on exec flags 
       
  3699 		{
       
  3700     	//First read the flag value to be set 
       
  3701    	   	TInt flag ;
       
  3702    	   	_LIT( Kflag, "flag" );
       
  3703 		res = GetIntFromConfig(ConfigSection(), Kflag, flag);
       
  3704  
       
  3705    	   	if(!res)  
       
  3706    	   		{
       
  3707    	   		_LIT(Kerr , "Failed to read input flag value to be set ") ;
       
  3708    	   		INFO_PRINTF1(Kerr) ;
       
  3709    	   		return KErrGeneral ;
       
  3710    	   		}
       
  3711    	   	if(fcntl(fd , F_SETFD , flag) < 0 ) 
       
  3712    	   		{
       
  3713    	   	    _LIT(Kerr , "Failed to set the flags of the opened file \n") ;
       
  3714    	   	  	INFO_PRINTF1(Kerr) ;
       
  3715    	   	  	return KErrGeneral ;
       
  3716    	   		}
       
  3717    	   	break ;
       
  3718    		}	           //End of F_SETFD 
       
  3719    	  
       
  3720    	case F_BADCMD :
       
  3721    	 	{
       
  3722    	 	if(fcntl(fd , F_BADCMD , 1) < 0 ) 
       
  3723    	 		{
       
  3724    	 		if(errno != EINVAL) 
       
  3725    	 			{
       
  3726    	 			_LIT(Kerr , "Fcntl failed to set errno value for bad command") ;
       
  3727    	 			INFO_PRINTF1(Kerr) ;
       
  3728    	 			return KErrGeneral ;	
       
  3729    	 			}
       
  3730    	 		_LIT(Kok , "Fcntl test passes for bad command");
       
  3731    	 		INFO_PRINTF1(Kok) ;
       
  3732    	 		return KErrNone ;
       
  3733    	 		}
       
  3734    	 	else 
       
  3735    	 		{
       
  3736    	 		 _LIT(Kerr , "Fcntl should fail for bad command but passes") ;
       
  3737    	 		INFO_PRINTF1(Kerr) ;
       
  3738    	 		return KErrGeneral ;	
       
  3739    	 		}
       
  3740 		}  //End of F_BADCMD :
       
  3741    	  case  F_SETLK :
       
  3742    	  	{
       
  3743    	  	  TInt flag,start,len,whence;
       
  3744     	//First read the flag value to be set 
       
  3745    	   	 _LIT( Kflag, "flag" );
       
  3746     	 res = GetIntFromConfig(ConfigSection(), Kflag, flag);
       
  3747     	 if(!res)   
       
  3748 			{
       
  3749    			_LIT(Kerr , "Failed to read the flag ") ;
       
  3750    			INFO_PRINTF1(Kerr) ;
       
  3751    			return KErrGeneral ;
       
  3752 			}
       
  3753 		_LIT( Kstart, "start" );
       
  3754     	 res = GetIntFromConfig(ConfigSection(), Kstart, start);
       
  3755     	 if(!res)   
       
  3756 			{
       
  3757    			_LIT(Kerr , "Failed to read start ") ;
       
  3758    			INFO_PRINTF1(Kerr) ;
       
  3759    			return KErrGeneral ;
       
  3760 			}
       
  3761 		_LIT( Klen, "len" );
       
  3762     	 res = GetIntFromConfig(ConfigSection(), Klen, len);
       
  3763     	 if(!res)   
       
  3764 			{
       
  3765    			_LIT(Kerr , "Failed to read the len ") ;
       
  3766    			INFO_PRINTF1(Kerr) ;
       
  3767    			return KErrGeneral ;
       
  3768 			}
       
  3769    	   
       
  3770 		_LIT( Kwhence, "whence" );
       
  3771     	 res = GetIntFromConfig(ConfigSection(), Kwhence, whence);
       
  3772     	 if(!res)   
       
  3773 			{
       
  3774    			_LIT(Kerr , "Failed to read the whence ") ;
       
  3775    			INFO_PRINTF1(Kerr) ;
       
  3776    			return KErrGeneral ;
       
  3777 			}
       
  3778 	     
       
  3779 	     struct flock fl;
       
  3780    	   	 fl.l_type = F_WRLCK;
       
  3781     	 fl.l_whence = whence;
       
  3782     	 fl.l_start = start;
       
  3783     	 fl.l_len = len;
       
  3784          for(int i=0;i<=15;i++)
       
  3785 			{
       
  3786 			if(write(fd , "hello" ,6) < 0) 
       
  3787 				{
       
  3788 				_LIT(Kerr , "Failed to write to the file ") ;
       
  3789 				INFO_PRINTF1(Kerr) ;
       
  3790 				_LIT(Kerr1 , "errno%d") ;
       
  3791 				INFO_PRINTF2(Kerr1,errno) ;
       
  3792 				close(fd) ;
       
  3793 				return KErrGeneral ;
       
  3794 				}
       
  3795 			}
       
  3796 	     
       
  3797 	    
       
  3798    	   	 if(flag==1||flag==2||flag==3||flag==4||flag==11)
       
  3799    	   	 	{
       
  3800    	   	 		if(fcntl(fd , F_SETLK , &fl)== -1 ) 
       
  3801    	   	 		{	
       
  3802    	   	  		_LIT(Kerr , "Failed to set the lock on the opened file \n") ;
       
  3803    	   	  		INFO_PRINTF1(Kerr);
       
  3804    	   	  		return KErrGeneral ;
       
  3805   	   	 		}
       
  3806    	   	 		if (errno == EACCES || errno == EAGAIN)
       
  3807   	   	 		{
       
  3808   	   	 		_LIT(Kerr , "Failed to set the lock on the opened file \n") ;
       
  3809    	   	  		INFO_PRINTF1(Kerr);
       
  3810    	   	  		return KErrGeneral ;
       
  3811   	   	 		}
       
  3812    	   	 
       
  3813    	   		}
       
  3814    	   	 if(flag==5||flag==9||flag==12)
       
  3815    	   	 	{
       
  3816    	   	 	if(fcntl(fd , F_SETLK , &fl)!= -1 ) 
       
  3817    	   	 		{
       
  3818    	   	   		_LIT(Kerr , " set the lock on the opened file \n") ;
       
  3819    	   	  		INFO_PRINTF1(Kerr);
       
  3820    	   	  		return KErrGeneral ;
       
  3821   	   	 		}	
       
  3822    	   	 	}
       
  3823    	   	if(flag==6)
       
  3824    	   		{
       
  3825    	   		if(fcntl(-1 , F_SETLK , &fl)!= -1 ) 
       
  3826    	   	 		{
       
  3827    	   	   		_LIT(Kerr , " set the lock on the opened file \n") ;
       
  3828    	   	  		INFO_PRINTF1(Kerr);
       
  3829    	   	  		return KErrGeneral ;
       
  3830   	   	 		}	
       
  3831    	   		}
       
  3832    	   if(flag==7)
       
  3833    	   		{
       
  3834    	   		if(fcntl(fd , F_SETLK , NULL)!= -1 ) 
       
  3835    	   	 		{
       
  3836    	   	   		_LIT(Kerr , " set the lock on the opened file \n") ;
       
  3837    	   	  		INFO_PRINTF1(Kerr);
       
  3838    	   	  		return KErrGeneral ;
       
  3839   	   	 		}	
       
  3840    	   		}
       
  3841    	  
       
  3842    	   if(flag==10)
       
  3843    	   	{
       
  3844    	   		fl.l_type = F_RDLCK;
       
  3845     	    if(fcntl(fd , F_SETLK , &fl)!= -1 ) 
       
  3846    	   	 		{
       
  3847    	   	   		return KErrGeneral ;
       
  3848   	   	 		}
       
  3849    	   	}
       
  3850    	   
       
  3851   	   	 break ;
       
  3852   	  }              //End of F_SETLK 
       
  3853    	   
       
  3854 	case F_GETLK :
       
  3855    	  {
       
  3856    	    
       
  3857    	      TInt flag,start,len,whence;
       
  3858     	//First read the flag value to be set 
       
  3859    	   	 _LIT( Kflag, "flag" );
       
  3860     	 res = GetIntFromConfig(ConfigSection(), Kflag, flag);
       
  3861     	 if(!res)   
       
  3862 			{
       
  3863    			_LIT(Kerr , "Failed to read the flag ") ;
       
  3864    			INFO_PRINTF1(Kerr) ;
       
  3865    			return KErrGeneral ;
       
  3866 			}
       
  3867 		_LIT( Kstart, "start" );
       
  3868     	 res = GetIntFromConfig(ConfigSection(), Kstart, start);
       
  3869     	 if(!res)   
       
  3870 			{
       
  3871    			_LIT(Kerr , "Failed to read the start ") ;
       
  3872    			INFO_PRINTF1(Kerr) ;
       
  3873    			return KErrGeneral ;
       
  3874 			}
       
  3875 		_LIT( Klen, "len" );
       
  3876     	 res = GetIntFromConfig(ConfigSection(), Klen, len);
       
  3877     	 if(!res)   
       
  3878 			{
       
  3879    			_LIT(Kerr , "Failed to read the len ") ;
       
  3880    			INFO_PRINTF1(Kerr) ;
       
  3881    			return KErrGeneral ;
       
  3882 			}
       
  3883    	   
       
  3884 		_LIT( Kwhence, "whence" );
       
  3885     	 res = GetIntFromConfig(ConfigSection(), Kwhence, whence);
       
  3886     	 if(!res)   
       
  3887 			{
       
  3888    			_LIT(Kerr , "Failed to read the whence") ;
       
  3889    			INFO_PRINTF1(Kerr) ;
       
  3890    			return KErrGeneral ;
       
  3891 			}
       
  3892 	     
       
  3893 	     for(int i=0;i<=15;i++)
       
  3894 			{
       
  3895 			if(write(fd , "hello" ,6) < 0) 
       
  3896 				{
       
  3897 				_LIT(Kerr , "Failed to write to the file ") ;
       
  3898 				INFO_PRINTF1(Kerr) ;
       
  3899 				_LIT(Kerr1 , "errno%d") ;
       
  3900 				INFO_PRINTF2(Kerr1,errno) ;
       
  3901 				close(fd) ;
       
  3902 				return KErrGeneral ;
       
  3903 				}
       
  3904 			}
       
  3905 	     
       
  3906    	  	 struct flock fl;
       
  3907    	   	 fl.l_type = F_WRLCK;
       
  3908     	 fl.l_whence = whence;
       
  3909     	 fl.l_start = start;
       
  3910     	 fl.l_len = len;
       
  3911     	 if(flag==8)
       
  3912     	 {
       
  3913     	 if(fcntl(fd , F_GETLK , &fl)== -1 ) 
       
  3914    	   	 		{
       
  3915    	   	   		_LIT(Kerr , "Failed to get the lock on the opened file \n") ;
       
  3916    	   	    	INFO_PRINTF1(Kerr);
       
  3917    	   	  		return KErrGeneral ;
       
  3918   	   	 		}
       
  3919   	   	 fl.l_type = F_WRLCK;
       
  3920     	 fl.l_whence = whence;
       
  3921     	 fl.l_start = start;
       
  3922     	 fl.l_len = len;
       
  3923   	   	 if(fcntl(fd , F_GETLK , &fl)!= -1 ) 
       
  3924    	   	 		{
       
  3925    	   	   		_LIT(Kerr , "Failed to get the lock on the opened file \n") ;
       
  3926    	   	    	INFO_PRINTF1(Kerr);
       
  3927    	   	  		return KErrGeneral ;
       
  3928   	   	 		}	
       
  3929     	 }
       
  3930   	   	 if(flag==1||flag==3||flag==4||flag==5)
       
  3931    	   	 	{
       
  3932   	   	 	if(fcntl(fd , F_GETLK , &fl)== -1 ) 
       
  3933    	   	 		{
       
  3934    	   	   		_LIT(Kerr , "Failed to get the lock on the opened file \n") ;
       
  3935    	   	    	INFO_PRINTF1(Kerr);
       
  3936    	   	  		return KErrGeneral ;
       
  3937   	   	 		}
       
  3938   	   	 	if (errno == EACCES || errno == EAGAIN)
       
  3939   	   	 		{
       
  3940   	   	 		_LIT(Kerr , "Failed to get the lock on the opened file \n") ;
       
  3941    	   	    	INFO_PRINTF1(Kerr);
       
  3942    	   	  		return KErrGeneral ;
       
  3943   	   	 		}
       
  3944   	   	 	if( fl.l_type != F_UNLCK)
       
  3945   	   	 		{
       
  3946   	   	 		return KErrGeneral;
       
  3947   	   	 		}
       
  3948   	   	 	}
       
  3949   	   	 
       
  3950   	   	if(flag==6||flag==2)
       
  3951   	   		{
       
  3952   	   		if(fcntl(fd , F_GETLK , &fl)!= -1 ) 
       
  3953    	   	 		{
       
  3954    	   	   		_LIT(Kerr , "Failed to get the lock on the opened file \n") ;
       
  3955    	   	    	INFO_PRINTF1(Kerr);
       
  3956    	   	  		return KErrGeneral ;
       
  3957   	   	 		}
       
  3958   	   		}
       
  3959   	   	if(flag==7)
       
  3960    	   	{
       
  3961    	   		fl.l_type = F_RDLCK;
       
  3962     	    if(fcntl(fd , F_GETLK , &fl)!= -1 ) 
       
  3963    	   	 		{
       
  3964    	   	   		return KErrGeneral ;
       
  3965   	   	 		}
       
  3966    	   	}
       
  3967   	   	
       
  3968    	    break ;
       
  3969    	  }              //End of F_GETFL 
       
  3970    	 default :
       
  3971    		{
       
  3972    	   	_LIT(Kerr , "Invalid command ") ;
       
  3973    	   	INFO_PRINTF1(Kerr) ;
       
  3974    	   	return KErrGeneral ;
       
  3975 		}            //End of default 
       
  3976    	}  
       
  3977 	return KErrNone ;
       
  3978 	}
       
  3979 
       
  3980 
       
  3981 //-------------------------------------------------------------------------------
       
  3982 
       
  3983 //  Test case : ioctl tests 
       
  3984 //            : returns 0 on success
       
  3985 //            : 18(KErrFcntl) on failure  
       
  3986 //
       
  3987 //--------------------------------------------------------------------------------                  
       
  3988 
       
  3989 TInt CTestSyscalls :: Ioctl()
       
  3990 	{
       
  3991 	TBuf8<50> string ;
       
  3992 	TPtrC String ;
       
  3993 	TInt command ;
       
  3994   
       
  3995 	_LIT( KTsyscalls, "Tsyscalls" );
       
  3996 	INFO_PRINTF1(KTsyscalls) ;
       
  3997 	_LIT( Kfcntl, "In Fcntl" );
       
  3998 	INFO_PRINTF1(Kfcntl);
       
  3999    
       
  4000    
       
  4001 	//Read file name
       
  4002 	_LIT( KString, "String" );
       
  4003 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  4004 	if(!res) 
       
  4005 		{
       
  4006    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  4007    		INFO_PRINTF1(Kerr) ;
       
  4008    		return KErrGeneral ;
       
  4009 		}
       
  4010 	string.Copy(String) ;
       
  4011     char *file = (char *) string.Ptr() ;
       
  4012     file[string.Length()] = '\0' ;
       
  4013    
       
  4014     //Read input command 
       
  4015     _LIT( Kcommand, "command" );
       
  4016     res = GetIntFromConfig(ConfigSection(), Kcommand, command);
       
  4017 	if(!res)   
       
  4018 		{
       
  4019    		_LIT(Kerr , "Failed to read the input command ") ;
       
  4020    		INFO_PRINTF1(Kerr) ;
       
  4021    		return KErrGeneral ;
       
  4022 		}
       
  4023    
       
  4024 	if((open(file , O_CREAT | O_RDWR | O_TRUNC  , 0666))  < 0) 
       
  4025 		{
       
  4026 		_LIT(Kopen , "Failed  to create file ") ;
       
  4027 		INFO_PRINTF1(Kopen) ;
       
  4028 		return KErrGeneral  ;
       
  4029 		}
       
  4030    
       
  4031 	switch(command)   
       
  4032 		{
       
  4033    		default :
       
  4034    			{
       
  4035    	   		_LIT(Kerr , "Invalid command ") ;
       
  4036    	   		INFO_PRINTF1(Kerr) ;
       
  4037    	   		return KErrNone ;
       
  4038    			}            //End of default 
       
  4039    		}
       
  4040 	}
       
  4041 
       
  4042 #define SIZE       0  
       
  4043 #define LINKS      1
       
  4044 #define ATIME      2
       
  4045 #define MTIME      3
       
  4046 #define CTIME      4
       
  4047 
       
  4048 
       
  4049 TInt CTestSyscalls :: Fstat() 
       
  4050 	{
       
  4051 	int fd ;
       
  4052 	TBuf8<50> string ;
       
  4053 	TPtrC String ;
       
  4054 	TInt Expected ;
       
  4055 	TInt command  ;
       
  4056 	TInt ret =KErrNone;
       
  4057    
       
  4058 	_LIT( KTsyscalls, "Tsyscalls" );
       
  4059 	INFO_PRINTF1(KTsyscalls) ;
       
  4060 	_LIT( Kfstat, "In Fstat" );
       
  4061 	INFO_PRINTF1(Kfstat);
       
  4062       //Read dir to be changed
       
  4063 
       
  4064 	_LIT( KString, "String" );
       
  4065 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  4066 	if(!res) 
       
  4067 		{
       
  4068    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  4069    		INFO_PRINTF1(Kerr) ;
       
  4070    		return KErrGeneral ;
       
  4071 		}
       
  4072 	string.Copy(String) ;
       
  4073    
       
  4074 	char *file = (char *) string.Ptr() ;
       
  4075    
       
  4076 	file[string.Length()] = '\0' ;
       
  4077    
       
  4078      //Now read expected value 
       
  4079     _LIT( KExpected, "Expected" );
       
  4080 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  4081  
       
  4082 	if(!res) 
       
  4083 		{ 
       
  4084    		_LIT(Kerr , "Failed to read Expected value from ini file ") ;
       
  4085    		INFO_PRINTF1(Kerr) ;
       
  4086    		return KErrGeneral ;  
       
  4087 		}
       
  4088 	//Now read command
       
  4089 	_LIT( Kcommand, "command" );
       
  4090 	res = GetIntFromConfig(ConfigSection(), Kcommand, command);
       
  4091 	if(!res) 
       
  4092 		{ 
       
  4093    		_LIT(Kerr , "Failed to read command value from ini file ") ;
       
  4094    		INFO_PRINTF1(Kerr) ;
       
  4095    		return KErrGeneral ;  
       
  4096 		}
       
  4097    
       
  4098 	if(Expected < 0 ) 
       
  4099 		{
       
  4100 		struct stat statbuf ;
       
  4101 		fd = -1 ;    
       
  4102    		ret = fstat(fd , &statbuf) ;
       
  4103    		if(ret == Expected) 
       
  4104    			{
       
  4105    	 		if(errno !=EBADF) 
       
  4106    	 			{
       
  4107    	 			_LIT(Kerr , "Failed to set errno value") ;
       
  4108    	 			INFO_PRINTF1(Kerr) ;
       
  4109    	 			return KErrGeneral ;
       
  4110    	 			}
       
  4111    	 		return KErrNone ;
       
  4112    			}
       
  4113    		else 
       
  4114    			{
       
  4115    	 		_LIT(Kerr , "Return and expected values are different") ;
       
  4116    	 		INFO_PRINTF1(Kerr) ;
       
  4117    	 		return KErrGeneral ;
       
  4118    			}
       
  4119    		}
       
  4120    
       
  4121 	unlink(file) ;
       
  4122    
       
  4123 	if((fd = open(file , O_CREAT | O_RDWR | O_TRUNC , 0666)) < 0) 
       
  4124 		{
       
  4125    		_LIT(Kerr , "Failed to open specified file ") ;
       
  4126    		INFO_PRINTF1(Kerr) ;
       
  4127    		return KErrGeneral ;
       
  4128 		}
       
  4129      //Write  some  bytes to the file 
       
  4130    
       
  4131 	if(write(fd , "Hello Hello" , 12 ) < 12) 
       
  4132 		{
       
  4133    		_LIT(Kerr , "failed to write to the newly opened file ") ;
       
  4134    		ERR_PRINTF1(Kerr) ;
       
  4135    		return KErrGeneral ;
       
  4136 		}
       
  4137    
       
  4138 	struct stat Buf ;
       
  4139 	Buf.st_atime  = -1 ; //Need to do some modifications here 
       
  4140 	Buf.st_mtime  = -1 ;
       
  4141 	Buf.st_ctime  = -1 ;   
       
  4142   
       
  4143 	if(fstat(fd , &Buf) < 0) 
       
  4144 		{
       
  4145    		_LIT(Kerr , "Failed to fstat the given file") ;
       
  4146    		INFO_PRINTF1(Kerr) ;
       
  4147    		return KErrGeneral ;
       
  4148 		}
       
  4149    
       
  4150 	switch(command)   
       
  4151 		{
       
  4152     	case SIZE :
       
  4153     		if(12 == Buf.st_size)
       
  4154     			{
       
  4155     	    	ret = 0 ;
       
  4156     			}
       
  4157     	    else 
       
  4158     			{
       
  4159     	    	ret = -1 ;
       
  4160     			}
       
  4161     	     break ;
       
  4162     	     
       
  4163     	case ATIME :
       
  4164     	     if(Buf.st_atime  > 0) 
       
  4165     			{
       
  4166     	     	ret = 0 ;
       
  4167     			}
       
  4168     	     else 
       
  4169     			{
       
  4170     	     	ret = -1 ;
       
  4171     	     	}
       
  4172     		break ;
       
  4173     	     
       
  4174     	case MTIME :
       
  4175     	    if(Buf.st_mtime  > 0) 
       
  4176     			{
       
  4177     	     	ret = 0 ;
       
  4178     			}
       
  4179     	     else 
       
  4180     			{
       
  4181     	     	ret = -1 ;
       
  4182     	     	}
       
  4183     	     break ;
       
  4184     	     
       
  4185     	case CTIME :   //This will be same as atime. DEF124164 
       
  4186 			if(Buf.st_ctime  > 0)  
       
  4187     			{
       
  4188     	     	ret = 0 ;
       
  4189     			}
       
  4190     	     else 
       
  4191     			{
       
  4192     	     	ret = -1 ;
       
  4193     	     	}
       
  4194     	     break ;   
       
  4195 		}  
       
  4196 	close (fd) ;
       
  4197     unlink(file);           
       
  4198    
       
  4199 	if(ret != Expected ) 
       
  4200 		{
       
  4201    		_LIT(Kerr , "Expected and return values dont match") ;
       
  4202    		INFO_PRINTF1(Kerr) ;
       
  4203    		return KErrGeneral ;
       
  4204 		}
       
  4205 	return KErrNone ;    
       
  4206 }
       
  4207 
       
  4208 #define NORMAL_FILE_NAME "c:\\Test\\stattestnormal.txt"
       
  4209 #define HIDDEN_SYS_FILE_NAME "c:\\Test\\stattesthidden.txt"
       
  4210 #define HIDDEN_FILE 0
       
  4211 #define SYSTEM_FILE 1
       
  4212 
       
  4213 //---------------------------------------------------------------------------
       
  4214 //Stat Test cases 
       
  4215 //---------------------------------------------------------------------------
       
  4216 TInt CTestSyscalls :: Stat1()
       
  4217 {
       
  4218     struct stat normalStat = {0};
       
  4219     struct stat hiddenSysStat = {0};
       
  4220 	TInt   Expected ;
       
  4221 	TInt   command  ;
       
  4222 	TBool  res ;
       
  4223     RFs    rfs;
       
  4224     
       
  4225     TInt   err = rfs.Connect();
       
  4226         
       
  4227     _LIT(KNormalFileName, "c:\\Test\\stattestnormal.txt");
       
  4228     _LIT(KHiddenSysFileName, "c:\\Test\\stattesthidden.txt");
       
  4229     
       
  4230     // Create files for testing
       
  4231     if (err == KErrNone)
       
  4232     {
       
  4233         RFile normalFile;
       
  4234         RFile hiddenFile;
       
  4235         err = normalFile.Create(rfs, KNormalFileName, EFileWrite);
       
  4236         if(KErrNone != err)
       
  4237         	{
       
  4238             rfs.Delete(KNormalFileName);
       
  4239             err = normalFile.Create(rfs, KNormalFileName, EFileWrite);             
       
  4240         	}
       
  4241         
       
  4242         if (err == KErrNone)
       
  4243         {
       
  4244             normalFile.Close();
       
  4245             err = hiddenFile.Create(rfs, KHiddenSysFileName, EFileWrite);
       
  4246             if(KErrNone != err)
       
  4247             	{
       
  4248             	rfs.Delete(KHiddenSysFileName);
       
  4249             	err = hiddenFile.Create(rfs, KHiddenSysFileName, EFileWrite);
       
  4250             	}      
       
  4251             if (err == KErrNone)
       
  4252             {
       
  4253                 hiddenFile.Close();
       
  4254             
       
  4255                 //Now read expected value
       
  4256             	_LIT( KExpected, "Expected" );
       
  4257             	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  4258             	if(!res) 
       
  4259             	{	 
       
  4260           			_LIT(Kerr , "Failed to read Expected value from ini file ") ;
       
  4261           			INFO_PRINTF1(Kerr) ;
       
  4262           			return KErrGeneral ;  
       
  4263             	}
       
  4264                 
       
  4265             	//Now read command
       
  4266             	_LIT( Kcommand, "command" );
       
  4267             	res = GetIntFromConfig(ConfigSection(), Kcommand, command);
       
  4268             	if(!res) 
       
  4269             	{ 
       
  4270             		_LIT(Kerr , "Failed to read command value from ini file ") ;
       
  4271             	   	INFO_PRINTF1(Kerr) ;
       
  4272             	   	return KErrGeneral ;  
       
  4273             	}
       
  4274             	switch(command)
       
  4275             		{
       
  4276             		case HIDDEN_FILE:
       
  4277             			rfs.SetAtt(KHiddenSysFileName, KEntryAttHidden, 0);
       
  4278             			break;
       
  4279             		case SYSTEM_FILE:
       
  4280             			rfs.SetAtt(KHiddenSysFileName, KEntryAttSystem, 0);
       
  4281             			break;
       
  4282             		}      		
       
  4283             }
       
  4284         }
       
  4285     }
       
  4286     else
       
  4287     {
       
  4288     	_LIT(Kerr , "Failed to Connect to FileServer ") ;
       
  4289     	INFO_PRINTF1(Kerr) ;
       
  4290     	return KErrGeneral ;
       
  4291     }
       
  4292 
       
  4293     // Do the stat for files
       
  4294     if (err == KErrNone)
       
  4295     {
       
  4296         stat(NORMAL_FILE_NAME, &normalStat);
       
  4297         stat(HIDDEN_SYS_FILE_NAME, &hiddenSysStat);
       
  4298        
       
  4299         // Stat should be equivalent for both, since hidden attribute should not be relevant for statting,
       
  4300         // and especially it shouldn't mean that the file is a symbolic link.
       
  4301         if (normalStat.st_mode == hiddenSysStat.st_mode)
       
  4302         {
       
  4303             _LIT(Kerr , "st_modes are equivalent!") ;
       
  4304             INFO_PRINTF1(Kerr) ;
       
  4305         } 
       
  4306         else 
       
  4307         {
       
  4308             _LIT(Kerr , "st_modes are different!") ;
       
  4309         	INFO_PRINTF1(Kerr) ;
       
  4310             err = KErrGeneral; 
       
  4311         }
       
  4312         
       
  4313         if ((hiddenSysStat.st_mode & S_IFLNK) == S_IFLNK) 
       
  4314         {
       
  4315             _LIT(Kerr , "Hidden file considered a symbolic link!!") ;
       
  4316             INFO_PRINTF1(Kerr) ;
       
  4317             err = KErrGeneral;
       
  4318         }
       
  4319     }
       
  4320 
       
  4321     //rfs.Delete(KNormalFileName);
       
  4322     //rfs.Delete(KHiddenSysFileName);
       
  4323     rfs.Close();
       
  4324    
       
  4325     return err;
       
  4326 }
       
  4327 
       
  4328 
       
  4329 //---------------------------------------------------------------------------
       
  4330 //Stat Test cases 
       
  4331 //---------------------------------------------------------------------------
       
  4332 
       
  4333 
       
  4334 TInt CTestSyscalls :: Stat() 
       
  4335 	{
       
  4336 	int fd ;
       
  4337 	TBuf8<50> string ;
       
  4338 	TPtrC String ;
       
  4339 	TInt Expected ;
       
  4340 	TInt command  ;
       
  4341 	TInt ret=KErrNone ;
       
  4342    
       
  4343 	_LIT( KTsyscalls, "Tsyscalls" );
       
  4344 	INFO_PRINTF1(KTsyscalls) ;
       
  4345 	_LIT( Kfstat, "In stat" );
       
  4346 	INFO_PRINTF1(Kfstat);
       
  4347   
       
  4348 	//Read dir to be changed
       
  4349 	_LIT( KString, "String" );
       
  4350 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  4351 	if(!res) 
       
  4352 		{
       
  4353    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  4354    		INFO_PRINTF1(Kerr) ;
       
  4355    		return KErrGeneral ;
       
  4356 		}
       
  4357 	string.Copy(String) ;
       
  4358    
       
  4359 	char *file = (char *) string.Ptr() ;
       
  4360    
       
  4361 	file[string.Length()] = '\0' ;
       
  4362    
       
  4363      //Now read expected value
       
  4364 	_LIT( KExpected, "Expected" );
       
  4365 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  4366     if(!res) 
       
  4367 		{ 
       
  4368    		_LIT(Kerr , "Failed to read Expected value from ini file ") ;
       
  4369    		INFO_PRINTF1(Kerr) ;
       
  4370    		return KErrGeneral ;  
       
  4371 		}
       
  4372    //Now read command
       
  4373 	_LIT( Kcommand, "command" );
       
  4374 	res = GetIntFromConfig(ConfigSection(), Kcommand, command);
       
  4375 	if(!res) 
       
  4376 		{ 
       
  4377    		_LIT(Kerr , "Failed to read command value from ini file ") ;
       
  4378    		INFO_PRINTF1(Kerr) ;
       
  4379    		return KErrGeneral ;  
       
  4380 		}
       
  4381 	if(Expected < 0 ) 
       
  4382 		{
       
  4383 		struct stat statbuf ;
       
  4384 		unlink(file) ;
       
  4385    		ret = stat(file , &statbuf) ;
       
  4386    	 
       
  4387    		if(ret == Expected) 
       
  4388    			{
       
  4389    	 		if(errno !=ENOENT) 
       
  4390    	 			{
       
  4391    	 			_LIT(Kerr , "Failed to set errno value") ;
       
  4392    	 			INFO_PRINTF1(Kerr) ;
       
  4393    	 			return KErrGeneral ;
       
  4394    	 			}
       
  4395    	 		return KErrNone ;
       
  4396    			}
       
  4397    		else 
       
  4398    			{
       
  4399    	 		_LIT(Kerr , "Return and expected values are different") ;
       
  4400    	 		INFO_PRINTF1(Kerr) ;
       
  4401    	 		return KErrGeneral ;
       
  4402    			}
       
  4403    	
       
  4404 		}
       
  4405    
       
  4406 	unlink(file) ;
       
  4407    
       
  4408 	if((fd = open(file , O_CREAT | O_RDWR | O_TRUNC , 0666)) < 0) 
       
  4409 		{
       
  4410    		_LIT(Kerr , "Failed to open specified file ") ;
       
  4411    		INFO_PRINTF1(Kerr) ;
       
  4412    		return KErrGeneral ;
       
  4413 		}
       
  4414    
       
  4415    //Write  some  bytes to the file 
       
  4416    
       
  4417 	if(write(fd , "Hello Hello" , 12 ) < 12) 
       
  4418 		{
       
  4419    		_LIT(Kerr , "failed to write to the newly opened file ") ;
       
  4420    		ERR_PRINTF1(Kerr) ;
       
  4421    		return KErrGeneral ;
       
  4422    		}
       
  4423 	close(fd);
       
  4424    
       
  4425 	struct stat Buf ;
       
  4426 	Buf.st_atime  = -1 ;
       
  4427 	Buf.st_atime  = -1 ; //Need to do some modifications here 
       
  4428 	Buf.st_mtime  = -1 ;
       
  4429 	Buf.st_ctime  = -1 ;   
       
  4430   
       
  4431 	if(stat(file , &Buf) < 0) 
       
  4432 		{
       
  4433    		_LIT(Kerr , "Failed to fstat the given file") ;
       
  4434    		INFO_PRINTF1(Kerr) ;
       
  4435    		return KErrGeneral ;
       
  4436    		}
       
  4437    
       
  4438     switch(command)   
       
  4439 		{
       
  4440     	case SIZE :
       
  4441     	    if(12 == Buf.st_size)
       
  4442     			{
       
  4443     	    	ret = 0 ;
       
  4444     			}
       
  4445     	    else 
       
  4446     			{
       
  4447     	    	ret = -1 ;
       
  4448     			}
       
  4449     	    break ;
       
  4450     	     
       
  4451     	case ATIME :
       
  4452     	     if(Buf.st_atime  > 0) 
       
  4453     			{
       
  4454     	     	ret = 0 ;
       
  4455     			}
       
  4456     	     else 
       
  4457     			{
       
  4458     	     	ret = -1 ;
       
  4459 				}
       
  4460     	     break ;
       
  4461     	     
       
  4462     	case MTIME :
       
  4463     	    if(Buf.st_mtime  > 0) 
       
  4464     			{
       
  4465     	     	ret = 0 ;
       
  4466     			}
       
  4467     	     else 
       
  4468     			{
       
  4469     	     	ret = -1 ;
       
  4470     			}
       
  4471     	     break ;
       
  4472     	     
       
  4473     	case CTIME :    //This will be same as atime. DEF124164
       
  4474              if(Buf.st_ctime > 0) 
       
  4475     			{
       
  4476     	     	ret = 0 ;
       
  4477     			}
       
  4478     	     else 
       
  4479     			{
       
  4480     	     	ret = -1 ;
       
  4481     	     	}
       
  4482     	     break ;   
       
  4483 		}  
       
  4484     close (fd) ;
       
  4485     unlink(file);           
       
  4486    
       
  4487 	if(ret != Expected ) 
       
  4488 		{
       
  4489    		_LIT(Kerr , "Expected and return values dont match") ;
       
  4490    		INFO_PRINTF1(Kerr) ;
       
  4491    		return KErrGeneral ;
       
  4492 		}
       
  4493 	return KErrNone ;    
       
  4494 
       
  4495 	}
       
  4496 
       
  4497 
       
  4498 //---------------------------------------------------------------------------
       
  4499 //Stat Test cases 
       
  4500 //---------------------------------------------------------------------------
       
  4501 TInt CTestSyscalls :: Stat2() 
       
  4502 	{
       
  4503 	TInt ret = KErrNone;
       
  4504     
       
  4505 	_LIT(Kerr , "stat should not succeed for nonexistent drives!") ;
       
  4506 	INFO_PRINTF1(Kerr) ;
       
  4507     
       
  4508     RFs   rfs;
       
  4509     ret = rfs.Connect();
       
  4510     if(KErrNone == ret)
       
  4511     	{
       
  4512         TDriveList aList;
       
  4513 	    TUint16 driveNum = 0;	    
       
  4514 	    char buffer[4];
       
  4515 	    char buffer2[20];
       
  4516         struct stat st;
       
  4517 
       
  4518 	    rfs.DriveList(aList);
       
  4519 	    
       
  4520 	    for(char c='A'; c <='Z'; c++, driveNum++, ret = KErrNone)
       
  4521 	    	{
       
  4522 	        sprintf(buffer, "%c:/", c);
       
  4523 	        sprintf(buffer2, "%c:/private/", c);
       
  4524 	        
       
  4525 	        ret = stat(buffer, &st);
       
  4526 	        if((0 != aList[driveNum]) && (KErrNone != ret))
       
  4527 	        	{
       
  4528 		    		ERR_PRINTF2(_L("stat Failed for an existing drive : %c "),c);
       
  4529 		    		return KErrGeneral ;	        		
       
  4530 	        	}
       
  4531 	        ret = stat(buffer2, &st);       
       
  4532 	    	}
       
  4533     	}
       
  4534     else
       
  4535     	{
       
  4536     	_LIT(Kerr , "Failed to Connect to FileServer ") ;
       
  4537     	INFO_PRINTF1(Kerr) ;
       
  4538     	return KErrGeneral ;
       
  4539     	}
       
  4540 	return KErrNone;
       
  4541 	}
       
  4542 
       
  4543 
       
  4544 //-------------------------------------------------------------------------
       
  4545 // getpid test : 
       
  4546 //-------------------------------------------------------------------------
       
  4547 
       
  4548 
       
  4549 TInt CTestSyscalls :: Getpid() 
       
  4550 	{
       
  4551 	pid_t pid ;
       
  4552 	
       
  4553 	_LIT( KTsyscalls, "Tsyscalls" );
       
  4554 	INFO_PRINTF1(KTsyscalls) ;
       
  4555 	_LIT( Kgetpid, "In Getpid" );
       
  4556 	INFO_PRINTF1(Kgetpid);
       
  4557       
       
  4558 	pid = getpid() ;
       
  4559 	
       
  4560 	if(pid < 0 ) 
       
  4561 		{
       
  4562 		_LIT(Kerr , "getpid call failed \n") ;
       
  4563 		INFO_PRINTF1(Kerr);
       
  4564 		return KErrGeneral ;
       
  4565 		}
       
  4566 	return KErrNone ;
       
  4567 	}
       
  4568 
       
  4569 //-------------------------------------------------------------------------
       
  4570 // Time  test : 
       
  4571 //-------------------------------------------------------------------------
       
  4572 
       
  4573 TInt CTestSyscalls :: Time() 
       
  4574 	{
       
  4575    
       
  4576 	time_t tim;
       
  4577 	char Buff[50] ;
       
  4578 	_LIT( KTsyscalls, "Tsyscalls" );
       
  4579 	INFO_PRINTF1(KTsyscalls) ;
       
  4580 	_LIT( Ktime , "In Time" );
       
  4581 	INFO_PRINTF1(Ktime);
       
  4582    
       
  4583     if(time(&tim) < 0 ) 
       
  4584 		{
       
  4585 		_LIT(Kerr , "time  call failed \n") ;
       
  4586 		INFO_PRINTF1(Kerr);
       
  4587 		return KErrGeneral ;
       
  4588 		}
       
  4589 	char* ptr = ctime(&tim);
       
  4590 	strcpy(Buff , ctime(&tim)) ;  //For Debug testing 
       
  4591 	
       
  4592 	return KErrNone ;
       
  4593 	
       
  4594 	}
       
  4595 
       
  4596 
       
  4597 //-------------------------------------------------------------------------
       
  4598 // Clock  test : 
       
  4599 //-------------------------------------------------------------------------
       
  4600 
       
  4601 TInt CTestSyscalls :: Clock() 
       
  4602 	{
       
  4603    
       
  4604 	clock_t tim;
       
  4605 	char Buff[50] ;
       
  4606 	_LIT( KTsyscalls, "Tsyscalls" );
       
  4607 	INFO_PRINTF1(KTsyscalls) ;
       
  4608 	_LIT( Ktime , "In Clock" );
       
  4609 	INFO_PRINTF1(Ktime);
       
  4610     
       
  4611     tim = clock() ;
       
  4612     
       
  4613     if(tim == (clock_t)-1 ) 
       
  4614 		{
       
  4615 		_LIT(Kerr , "clock  call failed \n") ;
       
  4616 		INFO_PRINTF1(Kerr);
       
  4617 		return KErrGeneral ;
       
  4618 		}
       
  4619 	strcpy(Buff , ctime((const int *)&tim)) ;  //For Debug testing 
       
  4620 	
       
  4621 	return KErrNone ;
       
  4622 	
       
  4623 	}
       
  4624 
       
  4625 
       
  4626 //-------------------------------------------------------------------------
       
  4627 // Waitpid  test : 
       
  4628 //-------------------------------------------------------------------------
       
  4629 
       
  4630 TInt CTestSyscalls :: WaitPid() 
       
  4631 	{
       
  4632 	pid_t pid ;
       
  4633 	TInt status ;
       
  4634     
       
  4635 	_LIT( KTsyscalls, "Tsyscalls" );
       
  4636 	INFO_PRINTF1(KTsyscalls) ;
       
  4637 	_LIT( Kwaitpid , "WaitPid" );
       
  4638 	INFO_PRINTF1(Kwaitpid);
       
  4639     
       
  4640     pid = getpid() ;
       
  4641     
       
  4642     if(pid < 0 )  
       
  4643 		{
       
  4644     	_LIT(Kerr , "Failed to  get pid ") ;
       
  4645     	INFO_PRINTF1(Kerr);
       
  4646     	return KErrGeneral ;
       
  4647 		}
       
  4648     
       
  4649     if(waitpid(pid , &status , 0) < 0 )    
       
  4650 		{
       
  4651     	if(errno != ECHILD)  
       
  4652     		{
       
  4653     		_LIT(Kerr , " failed to set errno value for waitpid") ;
       
  4654             INFO_PRINTF1(Kerr) ;
       
  4655             return KErrGeneral ;  
       
  4656     		}
       
  4657     	return KErrNone ;
       
  4658 		}
       
  4659     
       
  4660 	return KErrNone ;
       
  4661 	}
       
  4662 
       
  4663 TInt CTestSyscalls :: Sleep()
       
  4664 	{
       
  4665 	_LIT( KTsyscalls, "Tsyscalls" );
       
  4666 	INFO_PRINTF1(KTsyscalls) ;
       
  4667 	_LIT( Ksleep , "Sleep" );
       
  4668 	INFO_PRINTF1(Ksleep);
       
  4669 	TInt Stime ;     //sleep time
       
  4670 	_LIT( KStime, "Stime" );
       
  4671 	TBool res = GetIntFromConfig(ConfigSection(), KStime, Stime);
       
  4672  
       
  4673 	if(!res) 
       
  4674 		{ 
       
  4675    		_LIT(Kerr , "Failed to read Sleep time from ini file ") ;
       
  4676    		INFO_PRINTF1(Kerr) ;
       
  4677    		return KErrGeneral ;  
       
  4678 		}
       
  4679 	sleep(Stime);
       
  4680 	return KErrNone ;
       
  4681 	}
       
  4682 
       
  4683 /*
       
  4684 //------------------------------------------------------------------
       
  4685 //Waitpid test : wait on a dead child 
       
  4686 //-------------------------------------------------------------------
       
  4687 TInt CTestSyscalls :: WaitPid1() 
       
  4688 {
       
  4689    
       
  4690    pid_t pid ;
       
  4691    TInt status ;
       
  4692     
       
  4693    _LIT( KTsyscalls, "Tsyscalls" );
       
  4694    INFO_PRINTF1(KTsyscalls) ;
       
  4695    _LIT( Kwaitpid , "WaitPid" );
       
  4696    INFO_PRINTF1(Kwaitpid);
       
  4697     
       
  4698     pid = getpid() ;
       
  4699     
       
  4700     if(pid < 0 )  
       
  4701     {
       
  4702     	_LIT(Kerr , "Failed to  get pid ") ;
       
  4703     	INFO_PRINTF1(Kerr);
       
  4704     	return KErrGeneral ;
       
  4705     }
       
  4706     
       
  4707     if(waitpid(pid , &status , 0) < 0 )    
       
  4708     {
       
  4709     	if(errno != ECHILD)  
       
  4710     	{
       
  4711     		_LIT(Kerr , " failed to set errno value for waitpid") ;
       
  4712              INFO_PRINTF1(Kerr) ;
       
  4713              return KErrGeneral ;  
       
  4714     	}
       
  4715     	return KErrNone ;
       
  4716     }
       
  4717     
       
  4718 	return KErrNone ;
       
  4719 }
       
  4720 
       
  4721 */
       
  4722 
       
  4723 /*
       
  4724 *This function test writev for directory file discrptor
       
  4725 */
       
  4726 
       
  4727 TInt CTestSyscalls :: Writev_Dir_Test(char *file)  
       
  4728 	{
       
  4729 	char Buf1[20] ;
       
  4730 	char Buf2[20] ;
       
  4731 	struct iovec Iovec[2] ;
       
  4732    
       
  4733 	Iovec[0].iov_base = Buf1 ;
       
  4734 	Iovec[0].iov_len = 20 ;
       
  4735 	Iovec[1].iov_base = Buf2 ;
       
  4736 	Iovec[1].iov_len = 20 ;
       
  4737    
       
  4738 	int fd =open(file , O_RDONLY) ;
       
  4739    
       
  4740 	if(fd < 0 ) 
       
  4741    		{
       
  4742    		_LIT(Kerr , "Failed to open the given directory for readv test") ;
       
  4743    		INFO_PRINTF1(Kerr) ;
       
  4744    		return KErrGeneral ;
       
  4745    		}
       
  4746    	
       
  4747 	if(writev(fd , Iovec , 2) < 0 ) 
       
  4748 		{
       
  4749    	   
       
  4750    		if(errno != EBADF) 
       
  4751    			{
       
  4752    			_LIT(Kerr , "failed to set errno value for writev for directory file discriport") ;
       
  4753    			INFO_PRINTF1(Kerr) ; 
       
  4754    	  		return KErrGeneral ;
       
  4755    	   		}
       
  4756    		return KErrNone  ;
       
  4757    		}
       
  4758    	else 
       
  4759    		{
       
  4760    		_LIT(Kerr , "Write on a directory file discriptor should fail ");
       
  4761    		INFO_PRINTF1(Kerr) ;
       
  4762 		}
       
  4763    	return KErrGeneral  ;
       
  4764 	}
       
  4765 
       
  4766 /**
       
  4767 *This function test writev on an invalid file discriptor
       
  4768 **/
       
  4769 
       
  4770 TInt CTestSyscalls :: Writev_Invalid_Fd(void)
       
  4771 	{
       
  4772 	char Buf1[20] ;
       
  4773 	char Buf2[20] ;
       
  4774 	struct iovec Iovec[2] ;
       
  4775    
       
  4776 	Iovec[0].iov_base = Buf1 ;
       
  4777 	Iovec[0].iov_len = 20 ;
       
  4778 	Iovec[1].iov_base = Buf2 ;
       
  4779 	Iovec[1].iov_len = 20 ;
       
  4780    
       
  4781 	
       
  4782 	if(writev(-1 , Iovec , 2) < 0 ) 
       
  4783 		{
       
  4784    		if(errno == EBADF) 
       
  4785    			{
       
  4786    	  		_LIT(Kok , "writev from invalid discrptor passed") ;
       
  4787    	  		INFO_PRINTF1(Kok) ;
       
  4788    	  		return KErrNone ;	 
       
  4789    			}
       
  4790    		_LIT(Kerr , "writev failed to set errno value to EBADF") ;
       
  4791    		INFO_PRINTF1(Kerr) ;
       
  4792    		return KErrGeneral ;
       
  4793 		}
       
  4794 	_LIT(Kerr , "writev from an invalid discriptor should fail but found to pass"  ) ;
       
  4795     INFO_PRINTF1(Kerr) ;
       
  4796     return KErrGeneral ;	
       
  4797 	}
       
  4798 
       
  4799 /**
       
  4800 * This function is called by Writev() and tests writev on an 
       
  4801 * read-only file discriptor 
       
  4802 **/
       
  4803 
       
  4804 TInt CTestSyscalls :: Writev_Readfd_Test(char *file ) 
       
  4805 	{
       
  4806 	char Buf1[20] ;
       
  4807 	char Buf2[20] ;
       
  4808 	struct iovec Iovec[2] ;
       
  4809 	int fd = 0 ;
       
  4810    
       
  4811 	Iovec[0].iov_base = Buf1 ;
       
  4812 	Iovec[0].iov_len = 20 ;
       
  4813 	Iovec[1].iov_base = Buf2 ;
       
  4814 	Iovec[1].iov_len = 20 ;
       
  4815    
       
  4816 	unlink(file) ;
       
  4817    
       
  4818 	fd = open(file , O_WRONLY | O_CREAT , 0666) ;
       
  4819    
       
  4820 	if(fd < 0 ) 
       
  4821 		{
       
  4822    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  4823    		INFO_PRINTF1(Kerr) ;
       
  4824    		return KErrGeneral ;
       
  4825 		} 
       
  4826    	
       
  4827 	if(readv(fd , Iovec , 2) < 0 ) 
       
  4828    		{
       
  4829    		if(errno != EACCES )
       
  4830    			{
       
  4831    			_LIT(Kerr , "failed to read to different I/O Vectors for directory file descriptor") ;
       
  4832    			INFO_PRINTF1(Kerr) ;
       
  4833 			return KErrGeneral ;
       
  4834    			}
       
  4835 		}
       
  4836    	return KErrNone ;
       
  4837 	}
       
  4838 
       
  4839 
       
  4840 //-------------------------------------------------------------------------------------------------
       
  4841 // This function test for writev  with iov vector length as zero
       
  4842 // and is called by 
       
  4843 //-------------------------------------------------------------------------------------------------
       
  4844 TInt CTestSyscalls :: Writev_Invalidcount_Test(char *file , TInt Firstarg)
       
  4845 	{
       
  4846 	char Buf1[20] ;
       
  4847 	char Buf2[20] ;
       
  4848 	struct iovec Iovec[2] ;
       
  4849 	int fd = 0 ;
       
  4850    
       
  4851 	if(Firstarg)
       
  4852 		{
       
  4853 		Iovec[0].iov_len =  0 ;	
       
  4854 		Iovec[1].iov_len = 20 ;
       
  4855 		}
       
  4856 	else 
       
  4857 		{
       
  4858 		Iovec[0].iov_len =  20 ;	
       
  4859 		Iovec[1].iov_len =  0 ;
       
  4860 		}
       
  4861    
       
  4862 	Iovec[0].iov_base = Buf1;
       
  4863 	Iovec[1].iov_base = Buf2 ;
       
  4864    
       
  4865 	unlink(file) ;
       
  4866 	
       
  4867 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  4868    
       
  4869 	if(fd < 0 ) 
       
  4870 		{
       
  4871    		_LIT(Kerr , "Failed to open the given file writev test") ;
       
  4872    		INFO_PRINTF1(Kerr) ;
       
  4873    		return KErrGeneral ;
       
  4874 		}
       
  4875    	
       
  4876 	if(writev(fd , Iovec , 2) < 0 ) 
       
  4877    		{
       
  4878    		if(errno != EINVAL)
       
  4879    			{
       
  4880    			_LIT(Kerr , "failed to write from different I/O Vectors for directory file descriptor") ;
       
  4881    			INFO_PRINTF1(Kerr) ;
       
  4882 			close(fd);
       
  4883 			return KErrGeneral ;
       
  4884    			}
       
  4885    	    }
       
  4886    	close(fd);
       
  4887    	return KErrNone ;
       
  4888 	}
       
  4889   
       
  4890 /**
       
  4891 * This function is called by writev and is used to test writev for
       
  4892 * invalid io- vector addresses
       
  4893 **/
       
  4894 
       
  4895 TInt CTestSyscalls :: Writev_AddInvalid_Test(char *file ,TInt Firstarg) 
       
  4896 	{
       
  4897 	char Buf1[20] = "HELLO";
       
  4898 	char Buf2[20] = "World" ;
       
  4899 	struct iovec Iovec[2] ;
       
  4900 	int fd = 0 ;
       
  4901    
       
  4902 	if(Firstarg)
       
  4903 		{
       
  4904 		Iovec[0].iov_base =  NULL ;	
       
  4905 		Iovec[1].iov_base = Buf2 ;
       
  4906 		}
       
  4907 	else 
       
  4908 		{
       
  4909 		Iovec[0].iov_base =  Buf1 ;	
       
  4910 		Iovec[1].iov_base =  NULL ;
       
  4911 		}
       
  4912    
       
  4913 	Iovec[0].iov_len = 20 ;
       
  4914 	Iovec[1].iov_len = 20 ;
       
  4915    
       
  4916 	unlink(file) ;
       
  4917    
       
  4918 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  4919    
       
  4920 	if(fd < 0 ) 
       
  4921 		{
       
  4922    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  4923    		INFO_PRINTF1(Kerr) ;
       
  4924    		return KErrGeneral ;
       
  4925 		}
       
  4926 	if(writev(fd , Iovec , 2) < 0 ) 
       
  4927    		{
       
  4928    		if(errno != EINVAL)
       
  4929    			{
       
  4930    			_LIT(Kerr , "failed to write from different I/O Vectors for directory file descriptor") ;
       
  4931    			INFO_PRINTF1(Kerr) ;
       
  4932 			return KErrGeneral ;
       
  4933    			}
       
  4934    	    }
       
  4935 	return KErrNone ;
       
  4936 	}
       
  4937 
       
  4938 /**
       
  4939 * This function is called by WriteV() function and tests writev call
       
  4940 * for io-vectors = IOV_MAX.
       
  4941 **/
       
  4942 
       
  4943 TInt CTestSyscalls :: Writev_MaxIov_Test(char *file)
       
  4944 	{
       
  4945 	char Buf1[20] ;
       
  4946 	char Buf2[20] ;
       
  4947 	struct iovec Iovec[2] ;
       
  4948 	TInt fd = 0 ;
       
  4949    
       
  4950 	Iovec[0].iov_base = Buf1 ;
       
  4951 	Iovec[0].iov_len = 20 ;
       
  4952 	Iovec[1].iov_base = Buf2 ;
       
  4953 	Iovec[1].iov_len = 20 ;
       
  4954    
       
  4955 	unlink(file) ;
       
  4956    
       
  4957 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  4958    
       
  4959 	if(fd < 0 ) 
       
  4960 		{
       
  4961    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  4962    		INFO_PRINTF1(Kerr) ;
       
  4963    		return KErrGeneral ;
       
  4964 		}
       
  4965 	
       
  4966 	if(writev(fd , Iovec , IOV_MAX + 1) < 0 ) 
       
  4967 		{
       
  4968    		if(errno == EINVAL) 
       
  4969    			{
       
  4970    	  		_LIT(Kok , "INVALID ARGUMENT PASSED") ;
       
  4971    	  		INFO_PRINTF1(Kok) ;
       
  4972    	  		return KErrNone ;	 
       
  4973    			}
       
  4974    		_LIT(Kerr , "readv failed to set errno value to EBADF") ;
       
  4975    		INFO_PRINTF1(Kerr) ;
       
  4976    		return KErrGeneral ;
       
  4977 		}
       
  4978 	_LIT(Kerr , "readv from an invalid discriptor should fail but found to pass"  ) ;
       
  4979     INFO_PRINTF1(Kerr) ;
       
  4980     return KErrGeneral ;
       
  4981 	}
       
  4982 
       
  4983 /**
       
  4984  *This function is called by WriteV() function and  this function test writev
       
  4985  * for negative io-vector lengths
       
  4986 **/ 
       
  4987 
       
  4988 TInt CTestSyscalls :: Writev_Negativecount_Test(char *file , TInt Firstarg)
       
  4989 	{
       
  4990 	char Buf1[20] ;
       
  4991 	char Buf2[20] ;
       
  4992 	struct iovec Iovec[2] ;
       
  4993 	int fd = 0 ;
       
  4994    
       
  4995 	if(Firstarg)
       
  4996 		{
       
  4997 		Iovec[0].iov_len =  0 ;	
       
  4998 		Iovec[1].iov_len = size_t(-123 );
       
  4999 		}
       
  5000 	else 
       
  5001 		{
       
  5002 		Iovec[0].iov_len =  20 ;	
       
  5003 		Iovec[1].iov_len =  size_t(-12) ;
       
  5004 		}
       
  5005    
       
  5006 	Iovec[0].iov_base = Buf1;
       
  5007 	Iovec[1].iov_base = Buf2 ;
       
  5008    
       
  5009 	unlink(file) ;
       
  5010    
       
  5011 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  5012 	
       
  5013 	if(fd < 0 ) 
       
  5014 		{
       
  5015    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  5016    		INFO_PRINTF1(Kerr) ;
       
  5017    		return KErrGeneral ;
       
  5018 		}
       
  5019 	if(writev(fd , Iovec , 2) < 0 ) 
       
  5020    		{
       
  5021    		if(errno != EINVAL)
       
  5022    			{
       
  5023    			_LIT(Kerr , "failed to read to different I/O Vectors for directory file descriptor") ;
       
  5024    			INFO_PRINTF1(Kerr) ;
       
  5025 			close(fd);
       
  5026 			return KErrGeneral ;
       
  5027    			}
       
  5028    	    }
       
  5029    	close(fd);
       
  5030    	return KErrNone ;
       
  5031    
       
  5032 	}
       
  5033 
       
  5034 /**
       
  5035 * This function is called by WriteV and does functionality testing of writev 
       
  5036 * system call.
       
  5037 **/
       
  5038 
       
  5039 TInt CTestSyscalls :: Writev_Normal(char *file)
       
  5040 	{
       
  5041 	char Buf1[] = "Hello World";
       
  5042 	char Buf2[] =  "By ritche" ; 
       
  5043 	struct iovec Iovec[2] ;
       
  5044    
       
  5045 	Iovec[0].iov_base = Buf1 ;
       
  5046 	Iovec[0].iov_len = sizeof(Buf1)  ;
       
  5047 	Iovec[1].iov_base = Buf2 ;
       
  5048 	Iovec[1].iov_len = sizeof(Buf2) ;
       
  5049    
       
  5050 	TInt fd = open(file , O_CREAT | O_RDWR | O_TRUNC , 0666) ;
       
  5051    
       
  5052 	if(fd < 0) 
       
  5053 		{
       
  5054 		_LIT(Kerr , "failed to open the given file ") ;
       
  5055 		INFO_PRINTF1(Kerr) ;
       
  5056 		return KErrGeneral ;	
       
  5057 		}
       
  5058 	if(writev(fd , Iovec , 2) < (sizeof(Buf1) + sizeof(Buf2))  ) 
       
  5059 		{
       
  5060 		_LIT(Kerr , "Failed to write given no of bytes to the file specified") ;
       
  5061 		INFO_PRINTF1(Kerr) ;
       
  5062 		return KErrGeneral ;	
       
  5063 		}
       
  5064 	return KErrNone ;
       
  5065    
       
  5066 	}
       
  5067 
       
  5068 /**
       
  5069 * This function is called by ReadV() function and does functionality test
       
  5070 * of readv System call.
       
  5071 **/
       
  5072 
       
  5073 TInt CTestSyscalls :: Readv_Normal(char *file)
       
  5074 	{
       
  5075 	char Buf1[20]  ;    //= "Hello World";
       
  5076 	char Buf2[20]  ;     //=  "By ritche" ; 
       
  5077 	struct iovec Iovec[2] ;
       
  5078 	TInt ret=KErrNone;
       
  5079 	Iovec[0].iov_base = Buf1 ;
       
  5080 	Iovec[0].iov_len = sizeof("Hello World")  ;
       
  5081 	Iovec[1].iov_base = Buf2 ;
       
  5082 	Iovec[1].iov_len = sizeof("By ritche") ;
       
  5083    
       
  5084 	TInt fd = open(file , O_CREAT | O_RDWR  , 0666) ;
       
  5085    
       
  5086 	if(fd < 0) 
       
  5087 		{
       
  5088 		_LIT(Kerr , "failed to open the given file ") ;
       
  5089 		INFO_PRINTF1(Kerr) ;
       
  5090 		return KErrGeneral ;	
       
  5091 		}
       
  5092    
       
  5093    
       
  5094 	if(readv(fd , Iovec , 2) < 0  ) 
       
  5095 		{
       
  5096 		_LIT(Kerr , "Failed to read from the file specified") ;
       
  5097 		INFO_PRINTF1(Kerr) ;
       
  5098 		return KErrGeneral ;	
       
  5099 		}
       
  5100    
       
  5101 	if((!strcmp(Buf1 , "Hello World")) && (!strcmp(Buf2 , "By ritche"))) 
       
  5102 		{
       
  5103 		_LIT(Kok , "Readv normal test case pass") ;
       
  5104 		INFO_PRINTF1(Kok) ;
       
  5105 		ret = KErrNone ;	
       
  5106 		}
       
  5107 	else 
       
  5108 		{
       
  5109    		_LIT(Kerr, "Failed to read from the file") ;
       
  5110    		INFO_PRINTF1(Kerr) ;
       
  5111    		ret = KErrGeneral ;
       
  5112 		}
       
  5113 	return ret;
       
  5114    
       
  5115 	}
       
  5116 
       
  5117 TInt CTestSyscalls :: Readv_Dir_Test(char *file)  
       
  5118 	{
       
  5119 	char Buf1[20] ;
       
  5120 	char Buf2[20] ;
       
  5121 	struct iovec Iovec[2] ;
       
  5122    
       
  5123 	Iovec[0].iov_base = Buf1 ;
       
  5124 	Iovec[0].iov_len = 20 ;
       
  5125 	Iovec[1].iov_base = Buf2 ;
       
  5126 	Iovec[1].iov_len = 20 ;
       
  5127    
       
  5128 	int fd =open(file , O_RDONLY) ;
       
  5129    
       
  5130 	if(fd < 0 ) 
       
  5131    		{
       
  5132    		_LIT(Kerr , "Failed to open the given directory for readv test") ;
       
  5133    		INFO_PRINTF1(Kerr) ;
       
  5134    		return KErrGeneral ;
       
  5135    		}
       
  5136    	
       
  5137 	if(readv(fd , Iovec , 2) < 0 ) 
       
  5138    		{
       
  5139    		_LIT(Kerr , "failed to read to different I/O Vectors for directory file descriptor") ;
       
  5140    		INFO_PRINTF1(Kerr) ;
       
  5141    		return KErrGeneral ;
       
  5142    		}
       
  5143    	return KErrNone ;
       
  5144 	}
       
  5145 
       
  5146 TInt CTestSyscalls :: Readv_Invalid_Fd(void)
       
  5147 	{
       
  5148 	char Buf1[20] ;
       
  5149 	char Buf2[20] ;
       
  5150 	struct iovec Iovec[2] ;
       
  5151    
       
  5152 	Iovec[0].iov_base = Buf1 ;
       
  5153 	Iovec[0].iov_len = 20 ;
       
  5154 	Iovec[1].iov_base = Buf2 ;
       
  5155 	Iovec[1].iov_len = 20 ;
       
  5156    
       
  5157 	
       
  5158 	if(readv(-1 , Iovec , 2) < 0 ) 
       
  5159 		{
       
  5160    	
       
  5161    		if(errno == EBADF) 
       
  5162    			{
       
  5163    	  		_LIT(Kok , "readv from invalid discrptor passed") ;
       
  5164    	  		INFO_PRINTF1(Kok) ;
       
  5165    	  		return KErrNone ;	 
       
  5166    			}
       
  5167    		_LIT(Kerr , "readv failed to set errno value to EBADF") ;
       
  5168    		INFO_PRINTF1(Kerr) ;
       
  5169    		return KErrGeneral ;
       
  5170 		}
       
  5171     _LIT(Kerr , "readv from an invalid discriptor should fail but found to pass"  ) ;
       
  5172     INFO_PRINTF1(Kerr) ;
       
  5173     return KErrGeneral ;	
       
  5174 	}
       
  5175    
       
  5176 TInt CTestSyscalls :: Readv_Writefd_Test(char *file ) 
       
  5177 	{
       
  5178 	char Buf1[20] ;
       
  5179 	char Buf2[20] ;
       
  5180 	struct iovec Iovec[2] ;
       
  5181 	int fd = 0 ;
       
  5182    
       
  5183 	Iovec[0].iov_base = Buf1 ;
       
  5184 	Iovec[0].iov_len = 20 ;
       
  5185 	Iovec[1].iov_base = Buf2 ;
       
  5186 	Iovec[1].iov_len = 20 ;
       
  5187    
       
  5188 	unlink(file) ;
       
  5189    
       
  5190 	fd = open(file , O_WRONLY | O_CREAT , 0666) ;
       
  5191    
       
  5192 	if(fd < 0 ) 
       
  5193 		{
       
  5194    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  5195    		INFO_PRINTF1(Kerr) ;
       
  5196    		return KErrGeneral ;
       
  5197 		}
       
  5198 	if(readv(fd , Iovec , 2) < 0 ) 
       
  5199    		{
       
  5200    		if(errno != EBADF )
       
  5201    			{
       
  5202    			_LIT(Kerr , "failed to read to different I/O Vectors for directory file descriptor") ;
       
  5203    			INFO_PRINTF1(Kerr) ;
       
  5204 			return KErrGeneral ;
       
  5205    			}
       
  5206    	    }
       
  5207    	return KErrNone ;
       
  5208 	}
       
  5209 
       
  5210 
       
  5211 TInt CTestSyscalls :: Readv_AddInvalid_Test(char *file ,TInt Firstarg) 
       
  5212 	{
       
  5213 	char Buf1[20] ;
       
  5214 	char Buf2[20] ;
       
  5215 	struct iovec Iovec[2] ;
       
  5216 	int fd = 0 ;
       
  5217    
       
  5218 	if(Firstarg)
       
  5219 		{
       
  5220 		Iovec[0].iov_base =  NULL ;	
       
  5221 		Iovec[1].iov_base = Buf2 ;
       
  5222 		}
       
  5223 	else 
       
  5224 		{
       
  5225 		Iovec[0].iov_base =  Buf1 ;	
       
  5226 		Iovec[1].iov_base =  NULL ;
       
  5227 		}
       
  5228    
       
  5229 	Iovec[0].iov_len = 20 ;
       
  5230 	Iovec[1].iov_len = 20 ;
       
  5231    
       
  5232 	unlink(file) ;
       
  5233    
       
  5234 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  5235    
       
  5236 	if(fd < 0 ) 
       
  5237 		{
       
  5238    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  5239    		INFO_PRINTF1(Kerr) ;
       
  5240    		return KErrGeneral ;
       
  5241 		}
       
  5242 	if(readv(fd , Iovec , 2) < 0 ) 
       
  5243    		{
       
  5244    		if(errno != EINVAL)
       
  5245    			{
       
  5246    			_LIT(Kerr , "failed to read to different I/O Vectors for directory file descriptor") ;
       
  5247    			INFO_PRINTF1(Kerr) ;
       
  5248 			return KErrGeneral ;
       
  5249    			}
       
  5250    	    }
       
  5251    	
       
  5252    	return KErrNone ;
       
  5253    
       
  5254 	}
       
  5255 
       
  5256 
       
  5257 
       
  5258 
       
  5259 
       
  5260 /**
       
  5261 * This function test for readv for vector length = IOV_MAX
       
  5262 **/
       
  5263 
       
  5264 
       
  5265 TInt CTestSyscalls :: Readv_MaxIov_Test(char *file)
       
  5266 	{
       
  5267 	char Buf1[20] ;
       
  5268 	char Buf2[20] ;
       
  5269 	struct iovec Iovec[2] ;
       
  5270 	TInt fd = 0 ;
       
  5271    
       
  5272 	Iovec[0].iov_base = Buf1 ;
       
  5273 	Iovec[0].iov_len = 20 ;
       
  5274 	Iovec[1].iov_base = Buf2 ;
       
  5275 	Iovec[1].iov_len = 20 ;
       
  5276    
       
  5277 	unlink(file) ;
       
  5278    
       
  5279 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  5280    
       
  5281 	if(fd < 0 ) 
       
  5282 		{
       
  5283    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  5284    		INFO_PRINTF1(Kerr) ;
       
  5285    		return KErrGeneral ;
       
  5286 		}
       
  5287 	
       
  5288 	if(readv(fd , Iovec , IOV_MAX + 1) < 0 ) 
       
  5289 		{
       
  5290    		if(errno == EINVAL) 
       
  5291    			{
       
  5292    	  		_LIT(Kok , "INVALID ARGUMENT PASSED") ;
       
  5293    	  		INFO_PRINTF1(Kok) ;
       
  5294    	  		return KErrNone ;	 
       
  5295    			}
       
  5296    		_LIT(Kerr , "readv failed to set errno value to EBADF") ;
       
  5297    		INFO_PRINTF1(Kerr) ;
       
  5298    		return KErrGeneral ;
       
  5299 		}
       
  5300     _LIT(Kerr , "readv from an invalid discriptor should fail but found to pass"  ) ;
       
  5301     INFO_PRINTF1(Kerr) ;
       
  5302     return KErrGeneral ;
       
  5303   	
       
  5304 	}
       
  5305 
       
  5306 /**
       
  5307 This function test for readv  with iov vector length as negative
       
  5308 **/
       
  5309 TInt CTestSyscalls :: Readv_Invalidcount_Test(char *file , TInt Firstarg)
       
  5310 	{
       
  5311 	char Buf1[20] ;
       
  5312 	char Buf2[20] ;
       
  5313 	struct iovec Iovec[2] ;
       
  5314 	int fd = 0 ;
       
  5315    
       
  5316 	if(Firstarg)
       
  5317 		{
       
  5318 		Iovec[0].iov_len =  0 ;	
       
  5319 		Iovec[1].iov_len = 20 ;
       
  5320 		}
       
  5321 	else 
       
  5322 		{
       
  5323 		Iovec[0].iov_len =  20 ;	
       
  5324 		Iovec[1].iov_len =  0 ;
       
  5325 		}
       
  5326    
       
  5327 	Iovec[0].iov_base = Buf1;
       
  5328 	Iovec[1].iov_base = Buf2 ;
       
  5329    
       
  5330 	unlink(file) ;
       
  5331    
       
  5332 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  5333    
       
  5334 	if(fd < 0 ) 
       
  5335 		{
       
  5336    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  5337    		INFO_PRINTF1(Kerr) ;
       
  5338    		return KErrGeneral ;
       
  5339 		}
       
  5340 	if(readv(fd , Iovec , 2) < 0 ) 
       
  5341    		{
       
  5342    		if(errno != EINVAL)
       
  5343    			{
       
  5344    			_LIT(Kerr , "failed to read to different I/O Vectors for directory file descriptor") ;
       
  5345    			INFO_PRINTF1(Kerr) ;
       
  5346 			return KErrGeneral ;
       
  5347    			}
       
  5348    	    }
       
  5349    	
       
  5350    	return KErrNone ;
       
  5351 	}
       
  5352 
       
  5353 
       
  5354 TInt CTestSyscalls :: Readv_Negativecount_Test(char *file , TInt Firstarg)
       
  5355 	{
       
  5356 	char Buf1[20] ;
       
  5357 	char Buf2[20] ;
       
  5358 	struct iovec Iovec[2] ;
       
  5359 	int fd = 0 ;
       
  5360    
       
  5361 	if(Firstarg)
       
  5362 		{
       
  5363 		Iovec[0].iov_len =  0 ;	
       
  5364 		Iovec[1].iov_len = size_t(-123) ;
       
  5365 		}
       
  5366 	else 
       
  5367 		{
       
  5368 		Iovec[0].iov_len =  20 ;	
       
  5369 		Iovec[1].iov_len = size_t(-12) ;
       
  5370 		}
       
  5371    
       
  5372 	Iovec[0].iov_base = Buf1;
       
  5373 	Iovec[1].iov_base = Buf2 ;
       
  5374    
       
  5375 	unlink(file) ;
       
  5376    
       
  5377 	fd = open(file , O_RDWR | O_CREAT , 0666) ;
       
  5378    
       
  5379 	if(fd < 0 ) 
       
  5380 		{
       
  5381    		_LIT(Kerr , "Failed to open the given file readv test") ;
       
  5382    		INFO_PRINTF1(Kerr) ;
       
  5383    		return KErrGeneral ;
       
  5384 		}
       
  5385 	if(readv(fd , Iovec , 2) < 0 ) 
       
  5386    		{
       
  5387    		if(errno != EINVAL)
       
  5388    			{
       
  5389    			_LIT(Kerr , "failed to read to different I/O Vectors for directory file descriptor") ;
       
  5390    			INFO_PRINTF1(Kerr) ;
       
  5391 			return KErrGeneral ;
       
  5392    			}
       
  5393    	    }
       
  5394    	return KErrNone ;
       
  5395    
       
  5396 	}
       
  5397 
       
  5398 
       
  5399 #define DIRECT_TEST         0         //test for directory
       
  5400 #define INVALID_ADD_TEST    1         //test for invalid address
       
  5401 #define INVALID_FD          2         //test for invalid file descriptor 
       
  5402 #define WRITE_ONLY_FD       3         // test of read on write only fd
       
  5403 #define INVALID_COUNT_TEST  4         //Test for invalid vector count
       
  5404 #define MAX_IOV_MAX         5         //TEST if the iovector is > IOV_MAX
       
  5405 #define COUNT_NEGATIVE      7         //negative count testing   
       
  5406 #define REGULAR_TEST        8         //functionality test
       
  5407 #define READ_ONLY_FD        9         //Test for read-only fd  for writev
       
  5408 
       
  5409 TInt CTestSyscalls :: ReadV() 
       
  5410 	{
       
  5411 	TInt cmd = 0 ;
       
  5412 	TBuf8<50> string ;
       
  5413 	TPtrC String ;
       
  5414 	_LIT( KString, "String" );
       
  5415 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  5416 	if(!res) 
       
  5417 		{
       
  5418    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  5419    		INFO_PRINTF1(Kerr) ;
       
  5420    		return KErrGeneral ;
       
  5421 		}
       
  5422    
       
  5423 	string.Copy(String) ;
       
  5424 	char *file = (char *) string.Ptr() ;
       
  5425    
       
  5426 	file[string.Length()] = '\0' ;
       
  5427 	_LIT( Kcmd, "cmd" );
       
  5428 	res = GetIntFromConfig(ConfigSection(), Kcmd, cmd);
       
  5429 	if(!res) 
       
  5430 		{
       
  5431    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  5432    		INFO_PRINTF1(Kerr) ;
       
  5433    		return KErrGeneral ;
       
  5434 		}
       
  5435    
       
  5436 	TInt retVal = 0 ;
       
  5437    
       
  5438 	switch(cmd) 
       
  5439 		{
       
  5440    	
       
  5441    		case  DIRECT_TEST :
       
  5442    		   retVal = Readv_Dir_Test(file) ;
       
  5443    		   break ;
       
  5444    		   
       
  5445    		case INVALID_FD :
       
  5446    		    retVal = Readv_Invalid_Fd() ;
       
  5447    		    break ;
       
  5448    		    
       
  5449    		case WRITE_ONLY_FD :
       
  5450    		    retVal = Readv_Writefd_Test(file ) ;
       
  5451    		    break ;
       
  5452    		    
       
  5453    	    case INVALID_COUNT_TEST :
       
  5454    	    	{
       
  5455    	    	TInt retVal1 = Readv_Invalidcount_Test(file , 1) ;
       
  5456    	    	TInt retVal2 = Readv_Invalidcount_Test(file , 0) ;
       
  5457    	    	
       
  5458    	    	if((retVal1 != 0  ) && (retVal2 != 0)) 
       
  5459    	    		{
       
  5460    	    		retVal = KErrGeneral ;
       
  5461    	    		}
       
  5462    	    	else 
       
  5463    				{
       
  5464    	    		retVal = KErrNone ;
       
  5465    	    		}
       
  5466    	    	break ;	
       
  5467    	    	}
       
  5468    	    case  INVALID_ADD_TEST :
       
  5469    			{
       
  5470    			TInt retVal1 = Readv_AddInvalid_Test(file , 1) ;
       
  5471    	    	TInt retVal2 = Readv_AddInvalid_Test(file , 0) ;
       
  5472    	    	
       
  5473    	    	if((retVal1 != 0  ) && (retVal2 != 0)) 
       
  5474    	    		{
       
  5475    	    		retVal = KErrGeneral ;
       
  5476    	    		}
       
  5477    	    	else 
       
  5478    				{
       
  5479    	    		retVal = KErrNone ;
       
  5480    	    		}
       
  5481    	    	break ;	
       
  5482    	    	}
       
  5483    	    	
       
  5484    	    case MAX_IOV_MAX :
       
  5485    	        {
       
  5486    	        retVal = Readv_MaxIov_Test(file) ;
       
  5487    	        break;	
       
  5488    	        }	
       
  5489    	     
       
  5490    	    case COUNT_NEGATIVE:
       
  5491    	    	{
       
  5492    	    	TInt retVal1 = Readv_Negativecount_Test(file , 0) ;
       
  5493    	    	TInt retVal2 = Readv_Negativecount_Test(file , 0) ;
       
  5494    	    	
       
  5495    	    	if((retVal1 != 0  ) && (retVal2 != 0)) 
       
  5496    	    		{
       
  5497    	    		retVal = KErrGeneral ;
       
  5498    	    		}
       
  5499    	    	else 
       
  5500    				{
       
  5501    	    		retVal = KErrNone ;
       
  5502    	    		}
       
  5503    	    	break ;	
       
  5504    	    	}
       
  5505    	        
       
  5506    	    case REGULAR_TEST :
       
  5507    	    	{
       
  5508    	    	 unlink(file) ;
       
  5509    	    	 Writev_Normal(file) ;
       
  5510    	    	 retVal = Readv_Normal(file);
       
  5511    	    	 unlink(file) ;
       
  5512    	    	 break ;
       
  5513    	    	}
       
  5514    	   
       
  5515       }                 //End of switch
       
  5516 	return retVal ;
       
  5517    
       
  5518 	}
       
  5519 
       
  5520 
       
  5521 /**
       
  5522 This function tests the writev api
       
  5523 **/
       
  5524 
       
  5525 TInt CTestSyscalls :: WriteV() 
       
  5526 	{
       
  5527    
       
  5528 	TInt cmd = 0 ;
       
  5529 	TBuf8<50> string ;
       
  5530 	TPtrC String ;
       
  5531 
       
  5532 	_LIT( KString, "String" );
       
  5533     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  5534 	if(!res) 
       
  5535 		{
       
  5536    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  5537    		INFO_PRINTF1(Kerr) ;
       
  5538    		return KErrGeneral ;
       
  5539 		}
       
  5540 	string.Copy(String) ;
       
  5541 	char *file = (char *) string.Ptr() ;
       
  5542    
       
  5543 	file[string.Length()] = '\0' ;
       
  5544    
       
  5545 	_LIT( Kcmd, "cmd" );
       
  5546 	res = GetIntFromConfig(ConfigSection(), Kcmd, cmd);
       
  5547     if(!res) 
       
  5548 		{
       
  5549    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  5550    		INFO_PRINTF1(Kerr) ;
       
  5551    		return KErrGeneral ;
       
  5552 		}
       
  5553    
       
  5554 	TInt retVal = 0 ;
       
  5555    
       
  5556 	switch(cmd) 
       
  5557 		{
       
  5558    	
       
  5559    		case  DIRECT_TEST :
       
  5560    			retVal = Writev_Dir_Test(file) ;
       
  5561    			break ;
       
  5562    		   
       
  5563    		case INVALID_FD :
       
  5564    		    retVal = Writev_Invalid_Fd() ;
       
  5565    		    break ;
       
  5566    		    
       
  5567    		case READ_ONLY_FD :
       
  5568    		    retVal = Writev_Readfd_Test(file ) ;
       
  5569    		    break ;
       
  5570    		    
       
  5571    	    case INVALID_COUNT_TEST :
       
  5572    	    	{
       
  5573    	    	TInt retVal1 = Writev_Invalidcount_Test(file , 1) ;
       
  5574    	    	TInt retVal2 = Writev_Invalidcount_Test(file , 0) ;
       
  5575    	    	
       
  5576    	    	if((retVal1 != 0  ) && (retVal2 != 0)) 
       
  5577    	    		{
       
  5578    	    		retVal = KErrGeneral ;
       
  5579    	    		}
       
  5580    	    	else 
       
  5581    				{
       
  5582    	    		retVal = KErrNone ;
       
  5583    	    		}
       
  5584    	    	break ;	
       
  5585    	    	}
       
  5586    	    case  INVALID_ADD_TEST :
       
  5587    			{
       
  5588    	    	TInt retVal1 = Writev_AddInvalid_Test(file , 1) ;
       
  5589    	    	TInt retVal2 = Writev_AddInvalid_Test(file , 0) ;
       
  5590    	    	
       
  5591    	    	if((retVal1 != 0  ) && (retVal2 != 0)) 
       
  5592    	    		{
       
  5593    	    		retVal = KErrGeneral ;
       
  5594    	    		}
       
  5595    	    	else 
       
  5596    				{
       
  5597    	    		retVal = KErrNone ;
       
  5598    	    		}
       
  5599    	    	break ;	
       
  5600    	    	}
       
  5601    	    	
       
  5602    	    case MAX_IOV_MAX :
       
  5603    	        {
       
  5604    	        retVal = Writev_MaxIov_Test(file) ;
       
  5605    	        break;	
       
  5606    	        }	
       
  5607    	     
       
  5608    	    case COUNT_NEGATIVE:
       
  5609    	    	{
       
  5610    	    	TInt retVal1 = Writev_Negativecount_Test(file , 0) ;
       
  5611    	    	TInt retVal2 = Writev_Negativecount_Test(file , 0) ;
       
  5612    	    	
       
  5613    	    	if((retVal1 != 0  ) && (retVal2 != 0)) 
       
  5614    	    		{
       
  5615    	    		retVal = KErrGeneral ;
       
  5616    	    		}
       
  5617    	    	else 
       
  5618    				{
       
  5619    	    		retVal = KErrNone ;
       
  5620    	    		}
       
  5621    	    	break ;	
       
  5622    	    	}
       
  5623    	        
       
  5624    	        case REGULAR_TEST :
       
  5625    	    	{
       
  5626    	    	Writev_Normal(file) ;
       
  5627    	    	retVal = Readv_Normal(file);
       
  5628    	    	unlink(file) ;
       
  5629    	    	break ;
       
  5630    	    	}
       
  5631    	   
       
  5632       }                 //End of switch
       
  5633    return retVal ;
       
  5634    
       
  5635 	}
       
  5636 
       
  5637 TInt CTestSyscalls :: SeekDir() 
       
  5638 	{
       
  5639 	TInt Expected  = 0 ;
       
  5640 	TBuf8<50> string ;
       
  5641 	TPtrC String ;
       
  5642  
       
  5643 	_LIT( KString, "String" );
       
  5644     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  5645     if(!res) 
       
  5646 		{
       
  5647    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  5648    		INFO_PRINTF1(Kerr) ;
       
  5649    		return KErrGeneral ;
       
  5650 		}
       
  5651 	string.Copy(String) ;
       
  5652 	char *file = (char *) string.Ptr() ;
       
  5653    
       
  5654 	file[string.Length()] = '\0' ;
       
  5655    
       
  5656    
       
  5657 	_LIT( KExpected, "Expected" );
       
  5658 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  5659  
       
  5660 	if(!res) 
       
  5661 		{
       
  5662    		_LIT(Kerr, "Failed to Expected value from ini file") ;
       
  5663    		INFO_PRINTF1(Kerr) ;
       
  5664    		return KErrGeneral ;
       
  5665 		}
       
  5666 	char file1[100] =   	{ 0 } ;
       
  5667 	char file2[100] =   	{ 0 } ;
       
  5668 	char file3[100] =   	{ 0 } ;
       
  5669    
       
  5670 	strcpy(file1 , file) ;
       
  5671 	strcat(file1 , "Test_seek1.txt") ;
       
  5672 	strcpy(file2 , file) ;
       
  5673 	strcat(file2 , "Test_seek2.txt") ;
       
  5674 	strcpy(file3 , file) ;
       
  5675 	strcat(file3 , "Test_seek3.txt") ;
       
  5676    
       
  5677 	unlink(file1) ; 
       
  5678 	unlink(file2) ; 
       
  5679 	unlink(file3) ; 
       
  5680 	rmdir(file) ;
       
  5681    
       
  5682 	if(mkdir(file , 0777) < 0 ) 
       
  5683    		{
       
  5684    	
       
  5685    		_LIT(Kerr , "Failed to create the given directory %d") ;
       
  5686    		int n = errno;
       
  5687    		INFO_PRINTF2(Kerr,n) ;
       
  5688    		return KErrGeneral ;
       
  5689    		}
       
  5690    	
       
  5691    
       
  5692 	int fd = open(file1 , O_CREAT | O_RDWR , 0777) ;
       
  5693    
       
  5694 	if(fd < 0 ) 
       
  5695    		{
       
  5696    		_LIT(Kerr , "failed to open create file Test_seek1.txt") ;
       
  5697    		INFO_PRINTF1(Kerr) ;
       
  5698    		return KErrGeneral ;
       
  5699    		}
       
  5700    	
       
  5701    	close (fd) ;
       
  5702    	
       
  5703 	fd = open(file2 , O_CREAT | O_RDWR , 0777) ;
       
  5704    
       
  5705 	if(fd < 0 ) 
       
  5706    		{
       
  5707    		_LIT(Kerr , "failed to open create file Test_seek2.txt") ;
       
  5708    		INFO_PRINTF1(Kerr) ;
       
  5709    		return KErrGeneral ;
       
  5710    		}
       
  5711    	
       
  5712    	close (fd) ; 
       
  5713    	
       
  5714    	
       
  5715     fd = open(file3 , O_CREAT | O_RDWR , 0777) ;
       
  5716    
       
  5717 	if(fd < 0 ) 
       
  5718    		{	
       
  5719    		_LIT(Kerr , "failed to open create file Test_seek3.txt") ;
       
  5720    		INFO_PRINTF1(Kerr) ;
       
  5721    		return KErrGeneral ;
       
  5722    		}
       
  5723    	
       
  5724    	close (fd) ; 
       
  5725    	
       
  5726    	if(Expected < 0 ) 
       
  5727 		{
       
  5728    	    DIR *Handle = opendir (file) ;
       
  5729    		if(!Handle)	 
       
  5730    			{
       
  5731    			_LIT(Kerr , "Failed to open directory ") ;
       
  5732    			INFO_PRINTF1(Kerr) ;
       
  5733    			return KErrGeneral ;	
       
  5734    			}
       
  5735    		seekdir(Handle , telldir(Handle) -1 ) ;
       
  5736    	   
       
  5737    		struct dirent *Dir ;
       
  5738    		Dir = readdir(Handle);
       
  5739    		if(!Dir) 
       
  5740    			{
       
  5741    	   		_LIT(Kok , "invalid seek \n") ;
       
  5742    	   		INFO_PRINTF1(Kok) ;
       
  5743    	   		}
       
  5744    	   	else 
       
  5745    	   		{
       
  5746    	   		_LIT(Kerr , "read from from invalid handle \n") ;
       
  5747    	   		INFO_PRINTF1(Kerr) ;
       
  5748    	   		return KErrGeneral ;
       
  5749    	   		}
       
  5750    	   	rewinddir(Handle ) ;
       
  5751    	   	seekdir(Handle , telldir(Handle) + 2) ;
       
  5752    	   	Dir = readdir(Handle);
       
  5753    	   	if(!Dir) 
       
  5754    	   		{
       
  5755    	   		_LIT(Kerr , "Failed to read from the directory.")  ;
       
  5756    	   		INFO_PRINTF1(Kerr) ;
       
  5757    	   		return KErrGeneral ;
       
  5758    	   		}
       
  5759    		Dir = readdir(Handle);
       
  5760         if(!Dir) 
       
  5761    	   		{
       
  5762    	   		_LIT(Kok , "illegal seek.")  ;
       
  5763    	   		INFO_PRINTF1(Kok) ;
       
  5764    	   		}
       
  5765    	   	 
       
  5766 		rewinddir(Handle) ;
       
  5767    	   	seekdir(Handle , telldir(Handle) + 1) ;
       
  5768    	   	
       
  5769    	   	Dir = readdir(Handle);
       
  5770    	   	if(!Dir) 
       
  5771    	   		{
       
  5772    	   		_LIT(Kerr , "Failed to read from the directory..") ;
       
  5773    	   		INFO_PRINTF1(Kerr) ;
       
  5774    	   		return KErrGeneral ;
       
  5775    	   		}
       
  5776    	   	 
       
  5777    	   	Dir = readdir(Handle);
       
  5778         if(!Dir) 
       
  5779    	   		{
       
  5780    	   		_LIT(Kerr , "Failed to read from the directory... ") ;
       
  5781    	   		INFO_PRINTF1(Kerr) ;
       
  5782    	   		return KErrGeneral ;
       
  5783    	   		}
       
  5784    	   	Dir = readdir(Handle);
       
  5785    	   	if(!Dir) 
       
  5786    	   		{
       
  5787    	   		_LIT(Kok , "Failed to read from the directory.... ") ;
       
  5788    	   		INFO_PRINTF1(Kok) ;
       
  5789    	   		}
       
  5790    	   	 
       
  5791    	   	rewinddir(Handle) ;
       
  5792    	   	seekdir(Handle , telldir(Handle) + 0 ) ;
       
  5793    	   	 
       
  5794    	   	Dir = readdir(Handle);
       
  5795    	   	if(!Dir) 
       
  5796    	   		{
       
  5797    	   		_LIT(Kerr , "Failed to read from the directory..... ") ;
       
  5798    	   		INFO_PRINTF1(Kerr) ;
       
  5799    	   		return KErrGeneral ;
       
  5800    	   		}
       
  5801    	   	Dir = readdir(Handle);
       
  5802    	   	if(!(Dir)) 
       
  5803    	   		{
       
  5804    	   		_LIT(Kerr , "Failed to read from the directory...... ") ;
       
  5805    	   		INFO_PRINTF1(Kerr) ;
       
  5806    	   		return KErrGeneral ;
       
  5807    	   		}
       
  5808    	   	 
       
  5809    	   	Dir = readdir(Handle);
       
  5810    	   	if(!(Dir)) 
       
  5811    	   		{
       
  5812    	   		_LIT(Kerr , "Failed to read from the directory....... ") ;
       
  5813    	   		INFO_PRINTF1(Kerr) ;
       
  5814    	   		return KErrGeneral ;
       
  5815    	   		}
       
  5816    	   	Dir = readdir(Handle);
       
  5817    	   	if(!(Dir)) 
       
  5818    	   		{
       
  5819    	   		_LIT(Kok , "illegal seek.")  ;
       
  5820    	   		INFO_PRINTF1(Kok) ;
       
  5821    	   		}
       
  5822    		rewinddir(Handle)  ;
       
  5823          
       
  5824         seekdir(Handle  , telldir(Handle) + 4) ;
       
  5825         Dir = readdir(Handle);
       
  5826 		if(!(Dir)) 
       
  5827    	   		{
       
  5828    	   		_LIT(Kok , "illegal seek.")  ;
       
  5829    	   		INFO_PRINTF1(Kok) ;
       
  5830    	   		}
       
  5831    	   	closedir(Handle) ;
       
  5832    	   	}
       
  5833    	
       
  5834 	DIR *Handle ;
       
  5835 	//struct dirent *Dir ;
       
  5836    
       
  5837 	if ((Handle = opendir(file)) == NULL) 
       
  5838    		{
       
  5839    		_LIT(Kerr , "Failed to open given directory %d\n") ;
       
  5840    		int n = errno;
       
  5841    		INFO_PRINTF2(Kerr, n) ;
       
  5842    		return KErrGeneral ;
       
  5843    		}
       
  5844    	
       
  5845 	int count = 0 ;
       
  5846    	
       
  5847    	while(/*Dir =*/ readdir(Handle)) 
       
  5848    		{
       
  5849    		count++ ;
       
  5850    		}
       
  5851    	
       
  5852    	if(count != 3) 
       
  5853    		{
       
  5854    		_LIT(Kerr , "Actual entries and read entries differ \n") ;
       
  5855    		INFO_PRINTF1(Kerr) ;
       
  5856    		return KErrGeneral ;
       
  5857    		}
       
  5858    	closedir(Handle);
       
  5859    	return KErrNone ;
       
  5860 }
       
  5861 
       
  5862 TInt CTestSyscalls :: RewindDir() 
       
  5863 	{
       
  5864    
       
  5865 	TBuf8<50> string ;
       
  5866 	TPtrC String ;
       
  5867    
       
  5868 	_LIT(Kinfo , "In RewindDir") ;
       
  5869 	INFO_PRINTF1(Kinfo) ;
       
  5870  
       
  5871 	_LIT( KString, "String" );
       
  5872     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  5873     if(!res) 
       
  5874 		{
       
  5875    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  5876    		INFO_PRINTF1(Kerr) ;
       
  5877    		return KErrGeneral ;
       
  5878 		}
       
  5879    
       
  5880 	string.Copy(String) ;
       
  5881 	char *file = (char *) string.Ptr() ;
       
  5882    
       
  5883 	file[string.Length()] = '\0' ;
       
  5884     
       
  5885 	char file1[100] =   	{ 0 } ;
       
  5886 	char file2[100] =   	{ 0 } ;
       
  5887 	char file3[100] =   	{ 0 } ;
       
  5888    
       
  5889 	strcpy(file1 , file) ;
       
  5890 	strcat(file1 , "\\Test_seek1.txt") ;
       
  5891 	strcpy(file2 , file) ;
       
  5892 	strcat(file2 , "\\Test_seek2.txt") ;
       
  5893 	strcpy(file3 , file) ;
       
  5894 	strcat(file3 , "\\Test_seek3.txt") ;
       
  5895    
       
  5896 	unlink(file1) ; unlink(file2) ; unlink(file3) ; rmdir(file) ;
       
  5897    
       
  5898 	if(mkdir(file , 0777) < 0 ) 
       
  5899    		{
       
  5900    	
       
  5901    		_LIT(Kerr , "Failed to create the given directory") ;
       
  5902    		INFO_PRINTF1(Kerr) ;
       
  5903    		return KErrGeneral ;
       
  5904    		}
       
  5905 	int fd = open(file1 , O_CREAT | O_RDWR , 0777) ;
       
  5906    
       
  5907 	if(fd < 0 ) 
       
  5908    		{
       
  5909    		_LIT(Kerr , "failed to open create file Test_seek1.txt") ;
       
  5910    		INFO_PRINTF1(Kerr) ;
       
  5911    		return KErrGeneral ;
       
  5912    		}
       
  5913    	
       
  5914 	close (fd) ;
       
  5915    	
       
  5916 	fd = open(file2 , O_CREAT | O_RDWR , 0777) ;
       
  5917    
       
  5918 	if(fd < 0 ) 
       
  5919    		{
       
  5920    		_LIT(Kerr , "failed to open create file Test_seek2.txt") ;
       
  5921    		INFO_PRINTF1(Kerr) ;
       
  5922    		return KErrGeneral ;
       
  5923    		}
       
  5924    	
       
  5925    	close (fd) ; 
       
  5926    	
       
  5927    	DIR *Handle = opendir(file) ;
       
  5928    	
       
  5929    	if(!Handle) 
       
  5930    		{
       
  5931    		_LIT(Kerr , "Failed to open the directory ")  ;
       
  5932    		INFO_PRINTF1(Kerr) ;
       
  5933    		return KErrGeneral ;
       
  5934    		}
       
  5935    		
       
  5936 	int count = 0 ;
       
  5937    
       
  5938 	while(/*Dir = */readdir(Handle)) 
       
  5939    		{
       
  5940    		count++ ;
       
  5941    		}
       
  5942    
       
  5943 	if(count != 2) 
       
  5944     	{
       
  5945     	_LIT(Kerr , "expected and returned no of directory entries are different.") ;
       
  5946     	INFO_PRINTF1(Kerr) ;
       
  5947     	closedir(Handle);
       
  5948     	return KErrGeneral ;
       
  5949     	}
       
  5950     
       
  5951     fd = open(file3 , O_CREAT | O_RDWR , 0666) ;
       
  5952     
       
  5953     if(fd < 0 )  
       
  5954     	{
       
  5955     	
       
  5956     	_LIT(Kerr , "Failed to open final file ") ;
       
  5957     	INFO_PRINTF1(Kerr) ;
       
  5958     	closedir(Handle);
       
  5959     	return KErrGeneral ;
       
  5960     	}
       
  5961 	close(fd) ;
       
  5962    
       
  5963 	rewinddir(Handle) ;  	
       
  5964 	count = 0 ;
       
  5965    
       
  5966 	while(/*Dir =*/ readdir(Handle)) 
       
  5967    		{
       
  5968    		count++ ;
       
  5969    		}
       
  5970    
       
  5971     if(count != 3) 
       
  5972     	{
       
  5973     	_LIT(Kerr , "expected and returned no of directory entries are different..") ;
       
  5974     	INFO_PRINTF1(Kerr) ;
       
  5975     	closedir(Handle);
       
  5976     	return KErrGeneral ;
       
  5977     	}
       
  5978   	closedir(Handle);
       
  5979 	return KErrNone ;  	
       
  5980    	}
       
  5981 
       
  5982 TInt CTestSyscalls :: Telldir() 
       
  5983 	{
       
  5984    
       
  5985 	TBuf8<50> string ;
       
  5986 	TPtrC String ;
       
  5987    
       
  5988 	_LIT(Kinfo , "In RewindDir") ;
       
  5989 	INFO_PRINTF1(Kinfo) ;
       
  5990    
       
  5991 	_LIT( KString, "String" );
       
  5992 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  5993 	if(!res) 
       
  5994 		{
       
  5995    		_LIT(Kerr, "Failed to read input file name from ini file ") ;
       
  5996    		INFO_PRINTF1(Kerr) ;
       
  5997    		return KErrGeneral ;
       
  5998 		}
       
  5999    
       
  6000 	string.Copy(String) ;
       
  6001 	char *file = (char *) string.Ptr() ;
       
  6002    
       
  6003 	file[string.Length()] = '\0' ;
       
  6004    
       
  6005    
       
  6006    
       
  6007 	char file1[100] =   	{ 0 } ;
       
  6008 	char file2[100] =   	{ 0 } ;
       
  6009 	char file3[100] =   	{ 0 } ;
       
  6010    
       
  6011 	strcpy(file1 , file) ;
       
  6012 	strcat(file1 , "\\Test_seek1.txt") ;
       
  6013 	strcpy(file2 , file) ;
       
  6014 	strcat(file2 , "\\Test_seek2.txt") ;
       
  6015 	strcpy(file3 , file) ;
       
  6016 	strcat(file3 , "\\Test_seek3.txt") ;
       
  6017    
       
  6018 	unlink(file1) ; 
       
  6019 	unlink(file2) ; 
       
  6020 	unlink(file3) ; 
       
  6021 	rmdir(file) ;
       
  6022    
       
  6023 	if(mkdir(file , 0777) < 0 ) 
       
  6024    		{
       
  6025    	
       
  6026    		_LIT(Kerr , "Failed to create the given directory") ;
       
  6027    		INFO_PRINTF1(Kerr) ;
       
  6028    		return KErrGeneral ;
       
  6029    		}
       
  6030    	
       
  6031    
       
  6032 	int fd = open(file1 , O_CREAT | O_RDWR , 0777) ;
       
  6033    
       
  6034 	if(fd < 0 ) 
       
  6035    		{
       
  6036    		_LIT(Kerr , "failed to open create file Test_seek1.txt") ;
       
  6037    		INFO_PRINTF1(Kerr) ;
       
  6038    		return KErrGeneral ;
       
  6039    		}
       
  6040    	
       
  6041    	close (fd) ;
       
  6042    	
       
  6043 	fd = open(file2 , O_CREAT | O_RDWR , 0777) ;
       
  6044    
       
  6045 	if(fd < 0 ) 
       
  6046    		{
       
  6047    		_LIT(Kerr , "failed to open create file Test_seek2.txt") ;
       
  6048    		INFO_PRINTF1(Kerr) ;
       
  6049    		return KErrGeneral ;
       
  6050    		}
       
  6051    	
       
  6052    	close (fd) ; 
       
  6053    	
       
  6054    	DIR *Handle = opendir(file) ;
       
  6055    	
       
  6056    	if(!Handle) 
       
  6057    		{
       
  6058    		 _LIT(Kerr , "Failed to open the directory ")  ;
       
  6059    		 INFO_PRINTF1(Kerr) ;
       
  6060    		 return KErrGeneral ;
       
  6061    		}
       
  6062    		
       
  6063 	int count = 0 ;
       
  6064    
       
  6065 	do  
       
  6066 		{
       
  6067    		if(count != telldir(Handle)) 
       
  6068    			{
       
  6069    			_LIT(Kerr , "value returned from telldir is not same as expected.");
       
  6070    			INFO_PRINTF1(Kerr) ;
       
  6071    			closedir(Handle);
       
  6072    			return KErrGeneral ;
       
  6073    			}
       
  6074 
       
  6075    		count++ ;
       
  6076    		} while(/*Dir = */readdir(Handle)) ;
       
  6077    
       
  6078     
       
  6079     
       
  6080     fd = open(file3 , O_CREAT | O_RDWR , 0666) ;
       
  6081     
       
  6082     if(fd < 0 )  
       
  6083     	{
       
  6084        	_LIT(Kerr , "Failed to open final file ") ;
       
  6085     	INFO_PRINTF1(Kerr) ;
       
  6086     	closedir(Handle);
       
  6087     	return KErrGeneral ;
       
  6088     	}
       
  6089 	close(fd) ;
       
  6090    
       
  6091 	rewinddir(Handle) ; 
       
  6092     count = 0 ;	
       
  6093   
       
  6094 	while(/*Dir = */readdir(Handle)) 
       
  6095    		{
       
  6096    		count++ ;
       
  6097    		if(count != telldir(Handle)) 
       
  6098    			{
       
  6099    			_LIT(Kerr , "value returned from telldir is not same as expected.");
       
  6100    			INFO_PRINTF1(Kerr) ;
       
  6101    			closedir(Handle);
       
  6102    			return KErrGeneral ;
       
  6103    			}
       
  6104 		}
       
  6105 	closedir(Handle);
       
  6106    return KErrNone ;  	
       
  6107    }
       
  6108 
       
  6109 TInt CTestSyscalls ::TestClock()
       
  6110 	{
       
  6111 	TInt n;
       
  6112 	INFO_PRINTF1(_L("Starting countdown...\n"));
       
  6113 	for (n=10; n>0; n--)
       
  6114 	  {
       
  6115 	  //printf ("%d\n",n);
       
  6116 	  clock_t endwait;
       
  6117   	  endwait = clock () + 1 * CLOCKS_PER_SEC ;
       
  6118       while (clock() < endwait) {}
       
  6119 	  }
       
  6120 	INFO_PRINTF1(_L("1 sec delay!!\n"));
       
  6121 	return 0;
       
  6122 	}
       
  6123 
       
  6124 TInt CTestSyscalls :: Creat2(  ) // negative test case so on errr conditions returning KErrNone
       
  6125 	{
       
  6126     int fd ;
       
  6127    	char mbcbuf[64] = {'\0'};
       
  6128    	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  6129     TPtrC8 outbufstring((TText8*)mbcbuf, strlen(mbcbuf));
       
  6130        TBuf16<100> outbufname;
       
  6131       	outbufname.Copy(outbufstring);
       
  6132       	INFO_PRINTF2(_L("mbcbuf : %S"), &outbufname);
       
  6133     if((fd = creat(mbcbuf,  0666))  < 0) 
       
  6134 		{
       
  6135         _LIT(Kstmt , "creat success") ;
       
  6136         INFO_PRINTF1(Kstmt) ;
       
  6137     	close(fd) ;
       
  6138     	return KErrNone;
       
  6139 		}
       
  6140    
       
  6141 
       
  6142     _LIT(Kstmt , "creat failure") ;
       
  6143     INFO_PRINTF1(Kstmt) ;
       
  6144 	INFO_PRINTF2(_L("The errno set is %d\n"),errno);
       
  6145     return KErrGeneral;
       
  6146     }
       
  6147 TInt CTestSyscalls :: open8() // negative test case so on errr conditions returning KErrNone
       
  6148 	{
       
  6149 	int fd ;
       
  6150    	char mbcbuf[64]= {'\0'};
       
  6151    	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  6152    	INFO_PRINTF2(_L("The errno set is %s\n"),mbcbuf);
       
  6153     if((fd = open(mbcbuf,  O_CREAT|O_RDWR , 0444))  < 0) 
       
  6154 		{
       
  6155         _LIT(Kstmt , "open success") ;
       
  6156         INFO_PRINTF1(Kstmt) ;
       
  6157     	close(fd) ;
       
  6158     	return KErrNone;
       
  6159 		}
       
  6160     _LIT(Kstmt , "open failure") ;
       
  6161 	INFO_PRINTF2(_L("The errno set is %d\n"),errno);
       
  6162     INFO_PRINTF1(Kstmt) ;
       
  6163     return KErrGeneral;
       
  6164     
       
  6165 	}
       
  6166 
       
  6167 TInt CTestSyscalls :: TestStat()
       
  6168 	{
       
  6169 	int ret=KErrNone;
       
  6170 	struct stat buf;
       
  6171 	char *path = "C:\\private\\1028308C";
       
  6172 	
       
  6173 	ret = stat(path, &buf);
       
  6174 	
       
  6175 	if (!ret)
       
  6176 		{
       
  6177 		if(S_ISDIR(buf.st_mode))
       
  6178 			{
       
  6179 			_LIT(KSuccess, "Success");
       
  6180 			INFO_PRINTF1(KSuccess);	
       
  6181 			
       
  6182 			int count=0;
       
  6183 			DIR *handle = opendir(path);
       
  6184 			
       
  6185 			if (handle == NULL)
       
  6186 				{
       
  6187 				INFO_PRINTF1(_L("Failed to open directory"));
       
  6188 				}
       
  6189 			
       
  6190 			while(readdir(handle))
       
  6191 				{
       
  6192 				count++;
       
  6193 				}
       
  6194 			
       
  6195 			closedir(handle);
       
  6196 						
       
  6197 			}
       
  6198 		else if(S_ISREG(buf.st_mode))
       
  6199 			{
       
  6200 			INFO_PRINTF1(_L("Its a file"));	
       
  6201 			}
       
  6202 		
       
  6203 		}
       
  6204 	else
       
  6205 		{
       
  6206 		_LIT(KFailure, "Failure in STAT");
       
  6207 		INFO_PRINTF1(KFailure);
       
  6208 		}
       
  6209 	
       
  6210 	return ret;
       
  6211 	}
       
  6212 	
       
  6213 //-------------------------------------------------------------------------------
       
  6214 
       
  6215 //  Test case : -ve test for lseek() on tty console      
       
  6216 //--------------------------------------------------------------------------------                  
       
  6217 
       
  6218 
       
  6219 TInt CTestSyscalls :: Lseekttytest1()
       
  6220 	{
       
  6221 	TInt res ;
       
  6222 	_LIT( KTsyscalls, "Tsyscalls" );
       
  6223     _LIT( Klseek, "In Lseek for stderr" );
       
  6224     INFO_PRINTF1(KTsyscalls) ;
       
  6225     INFO_PRINTF1( Klseek );    
       
  6226     res =  lseek(2, 0, SEEK_CUR) ;
       
  6227     if(res < 0 )   
       
  6228 		{
       
  6229     	_LIT(Kerr , "lseek always fails on tty") ;
       
  6230     	INFO_PRINTF1(Kerr) ;
       
  6231         }
       
  6232    	return KErrNone ;
       
  6233 	}
       
  6234 	
       
  6235 //-------------------------------------------------------------------------------
       
  6236 
       
  6237 //  Test case : -ve test for lseek() on tty console              
       
  6238 //--------------------------------------------------------------------------------                  
       
  6239 
       
  6240 
       
  6241 TInt CTestSyscalls :: Lseekttytest2()
       
  6242 	{
       
  6243 	TInt res ;
       
  6244 	_LIT( KTsyscalls, "Tsyscalls" );
       
  6245     _LIT( Klseek, "In Lseek for stdout" );
       
  6246     INFO_PRINTF1(KTsyscalls) ;
       
  6247     INFO_PRINTF1( Klseek );    
       
  6248     res =  lseek(1, 0, SEEK_CUR) ;
       
  6249     if(res < 0 )   
       
  6250 		{
       
  6251     	_LIT(Kerr , "lseek always fails on tty") ;
       
  6252     	INFO_PRINTF1(Kerr) ;
       
  6253         }
       
  6254    	return KErrNone ;
       
  6255 	}
       
  6256 	
       
  6257 //-------------------------------------------------------------------------
       
  6258 // Test case : -ve test for waitpid()  
       
  6259 //-------------------------------------------------------------------------
       
  6260 
       
  6261 TInt CTestSyscalls :: WaitPidtest() 
       
  6262 	{
       
  6263 	TInt status ;
       
  6264     TInt ret;
       
  6265 	_LIT( KTsyscalls1, "Tsyscalls" );
       
  6266 	INFO_PRINTF1(KTsyscalls1) ;
       
  6267 	_LIT( Kwaitpid1 , "WaitPid" );
       
  6268 	INFO_PRINTF1(Kwaitpid1);    
       
  6269     ret = waitpid(-1 , &status , WUNTRACED);
       
  6270 	if (ret < 0)
       
  6271 		{
       
  6272 		_LIT( Kwaitinfo , "negative test for waitpid()" );
       
  6273 		INFO_PRINTF1(Kwaitinfo); 	
       
  6274 		}	
       
  6275 	return KErrNone ;
       
  6276 	}
       
  6277 
       
  6278 //-------------------------------------------------------------------------
       
  6279 // Test case : -ve test for wait()
       
  6280 //-------------------------------------------------------------------------
       
  6281 
       
  6282 TInt CTestSyscalls :: Waittest() 
       
  6283 	{
       
  6284 	TInt status ;
       
  6285     TInt ret;
       
  6286 	_LIT( KTsyscalls1, "Tsyscalls" );
       
  6287 	INFO_PRINTF1(KTsyscalls1) ;
       
  6288 	_LIT( Kwait1 , "Wait" );
       
  6289 	INFO_PRINTF1(Kwait1);    
       
  6290     ret = wait(&status);
       
  6291 	if (ret < 0)
       
  6292 		{
       
  6293 		_LIT( Kwaitinfo , "negative test for wait()" );
       
  6294 		INFO_PRINTF1(Kwaitinfo); 	
       
  6295 		}	
       
  6296 	return KErrNone ;
       
  6297 	}
       
  6298 	
       
  6299 	
       
  6300 	/*-----------------------------------------------------------------
       
  6301 	 *Test Case:To Check 256 open file descriptor is supported
       
  6302 	 *-----------------------------------------------------------------
       
  6303 	*/
       
  6304 	
       
  6305 	TInt CTestSyscalls :: Open_FileDes_Test()
       
  6306 		{
       
  6307 		int fd[253];
       
  6308 		TPtrC String ;
       
  6309 		_LIT( KString, "String" );
       
  6310 		TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  6311 		if(res)
       
  6312 			{
       
  6313 			TBuf8<100> string1;
       
  6314 			string1.Copy(String);
       
  6315 			char* file = (char*) string1.Ptr();
       
  6316 			file[string1.Length()]='\0';
       
  6317 	    	_LIT( KOpen3, "In open3" );
       
  6318 	  	    INFO_PRINTF1( KOpen3 );
       
  6319 	    	unlink(file);
       
  6320   			for(TInt i=0;i<253;i++)
       
  6321   				{
       
  6322   				fd[i] = open(file ,O_CREAT | O_WRONLY , 0666);
       
  6323    				if(fd[i]<0) 
       
  6324    					{
       
  6325    					_LIT( KFailedinfo, "Failed to create and open file in current working directory" );
       
  6326       				INFO_PRINTF1(KFailedinfo);
       
  6327       				return KErrGeneral;
       
  6328    					}
       
  6329   				}
       
  6330   			for(int i=0;i<253;i++)
       
  6331 	 			{
       
  6332 	 			close(fd[i]);
       
  6333 	 			}
       
  6334 			}
       
  6335 		return KErrNone ;
       
  6336 		}
       
  6337 
       
  6338 TInt CTestSyscalls :: openuid()
       
  6339 	{
       
  6340 	TInt openret,ret;
       
  6341 	
       
  6342 	ret = mkdir ("c:\\private\\1028308c",S_IRWXU| S_IRWXG); 
       
  6343 	_LIT( KTsyscalls2, "MKDIR passed %d " );
       
  6344 	INFO_PRINTF2(KTsyscalls2,ret);
       
  6345 	openret = open("c:\\Private\\1028308c\\name1_1028308c.db", O_RDWR|O_CREAT|O_BINARY|0, 0600);
       
  6346 	
       
  6347 	if(openret == -1)
       
  6348 		{
       
  6349 		_LIT( KTsyscalls1, "open failed" );
       
  6350 		INFO_PRINTF1(KTsyscalls1);
       
  6351 		return KErrGeneral;
       
  6352 		}
       
  6353 	_LIT( KTsyscalls1, "open passed" );
       
  6354 	INFO_PRINTF1(KTsyscalls1);
       
  6355 	close(openret);
       
  6356 
       
  6357 	return KErrNone;
       
  6358 	}
       
  6359 //-------------------------------------------------------------------------------
       
  6360 
       
  6361 //  Test case : MkDir1 - Tests wheather the mkdir sets the Errno EEXIST for the 
       
  6362 //              path c:\\private\\<UID3>
       
  6363 //            : returns 0 on success
       
  6364 //            : 
       
  6365 //
       
  6366 //--------------------------------------------------------------------------------                  
       
  6367 
       
  6368 TInt CTestSyscalls :: Mkdir1()
       
  6369 	{
       
  6370 	TInt ret1,ret2;
       
  6371 	
       
  6372 	ret1 = mkdir ("c:\\private\\1028308c",S_IRWXU| S_IRWXG); 
       
  6373 	
       
  6374 	if(ret1 == 0)
       
  6375 		{
       
  6376 		ret2 = mkdir ("c:\\private\\1028308c",S_IRWXU| S_IRWXG); 
       
  6377 		_LIT( KTsyscalls2, "mkdir returned %d" );
       
  6378 		INFO_PRINTF2(KTsyscalls2,ret2);
       
  6379 		if(ret2==-1 && errno == EEXIST)
       
  6380 			{
       
  6381 			_LIT( KTsyscalls1, "mkdir passed" );
       
  6382 			INFO_PRINTF1(KTsyscalls1);
       
  6383 			return KErrNone;
       
  6384 			}
       
  6385 		}
       
  6386 	else if(ret1 ==-1 && errno == EEXIST)
       
  6387 		{
       
  6388 		_LIT( KTsyscalls3, "mkdir returned %d and set the proper error code" );
       
  6389 		INFO_PRINTF2(KTsyscalls3,ret1);
       
  6390 		return KErrNone;
       
  6391 		}
       
  6392 	_LIT( KTsyscalls1, "mkdir failed" );
       
  6393 	INFO_PRINTF1(KTsyscalls1);
       
  6394 	
       
  6395 	return KErrGeneral;
       
  6396 	}
       
  6397 
       
  6398 //-------------------------------------------------------------------------------
       
  6399 
       
  6400 //  Test case : MkDir2 - Tests wheather the mkdir sets the Errno EEXIST for the 
       
  6401 //              path c:\\private\\<UID3>\\directory
       
  6402 //            : returns 0 on success
       
  6403 //            : 
       
  6404 //
       
  6405 //--------------------------------------------------------------------------------                  
       
  6406 
       
  6407 
       
  6408 TInt CTestSyscalls :: Mkdir2()
       
  6409 	{
       
  6410 	TInt ret1,ret2;
       
  6411 	
       
  6412 	ret1 = mkdir ("c:\\private\\1028308c\\testcase",S_IRWXU| S_IRWXG); 
       
  6413 	
       
  6414 	if(ret1 == 0)
       
  6415 		{
       
  6416 		ret2 = mkdir ("c:\\private\\1028308c\\testcase",S_IRWXU| S_IRWXG); 
       
  6417 		_LIT( KTsyscalls2, "mkdir returned %d" );
       
  6418 		INFO_PRINTF2(KTsyscalls2,ret2);
       
  6419 		if(ret2==-1 && errno == EEXIST)
       
  6420 			{
       
  6421 			_LIT( KTsyscalls1, "mkdir passed" );
       
  6422 			INFO_PRINTF1(KTsyscalls1);
       
  6423 			return KErrNone;
       
  6424 			}
       
  6425 		}
       
  6426 	else if(ret1 ==-1 && errno == EEXIST)
       
  6427 		{
       
  6428 		_LIT( KTsyscalls3, "mkdir returned %d and set the proper error code" );
       
  6429 		INFO_PRINTF2(KTsyscalls3,ret1);
       
  6430 		return KErrNone;
       
  6431 		}
       
  6432 	_LIT( KTsyscalls1, "mkdir failed" );
       
  6433 	INFO_PRINTF1(KTsyscalls1);
       
  6434 	
       
  6435 	return KErrGeneral;
       
  6436 	}
       
  6437 
       
  6438 //-------------------------------------------------------------------------------
       
  6439 
       
  6440 //  Test case : Chmod for Others and group
       
  6441 //            : Negative Test case 
       
  6442 //            :  
       
  6443 //--------------------------------------------------------------------------------   
       
  6444 
       
  6445 TInt CTestSyscalls :: Chmod1()
       
  6446 	{
       
  6447 	TInt Expected ,Mode ;
       
  6448 	TBuf8<50> string ;
       
  6449 	TPtrC  String  ;
       
  6450    
       
  6451 	_LIT( KTsyscalls, "Tsyscalls" );
       
  6452 	INFO_PRINTF1(KTsyscalls) ;
       
  6453 	_LIT( Kchmod, "In Chmod1" );
       
  6454 	INFO_PRINTF1( Kchmod);
       
  6455    
       
  6456 	//Read input file name 
       
  6457 	_LIT( KString, "String" );
       
  6458 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  6459 	if(!res)  
       
  6460 		{
       
  6461    		_LIT(Kerr , "failed to read input file name ") ;
       
  6462    		INFO_PRINTF1(Kerr) ;
       
  6463    		return KErrGeneral ;
       
  6464 		}
       
  6465 	string.Copy(String) ;
       
  6466    
       
  6467 	char *file = (char *) string.Ptr() ;
       
  6468 	file[string.Length()] = '\0' ;
       
  6469    
       
  6470 	unlink(file) ;
       
  6471 	
       
  6472 	//To read flag bit to be set
       
  6473 	_LIT( KMode, "Mode" );
       
  6474 	res = GetIntFromConfig(ConfigSection(), KMode, Mode );
       
  6475     _LIT(Kerr,"mode value is %d\n");
       
  6476 	INFO_PRINTF2(Kerr,Mode) ;
       
  6477 	if(!res)  
       
  6478 		{
       
  6479    		_LIT(Kerr , "failed to read the file mode bit from ini file ") ;
       
  6480    		INFO_PRINTF1(Kerr) ;
       
  6481    		return KErrGeneral ;
       
  6482 		}
       
  6483 	//Now read expected value 
       
  6484 	_LIT( KExpected, "Expected" );
       
  6485 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  6486     if(!res) 
       
  6487 		{
       
  6488     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  6489     	INFO_PRINTF1(Kerr) ;
       
  6490     	return KErrGeneral ;
       
  6491 		}
       
  6492     if(Expected < 0 ) 
       
  6493 		{
       
  6494    		TInt ret1;
       
  6495        	ret1 = chmod(file , Mode) ;
       
  6496 		if(ret1 == Expected) 
       
  6497 			{
       
  6498 			if(errno != EINVAL) 
       
  6499 				{
       
  6500       			_LIT(Kerr, "Failed to set errno to EINVAL") ;
       
  6501       			INFO_PRINTF1(Kerr) ;
       
  6502       			return KErrGeneral ;
       
  6503 				}
       
  6504 			}
       
  6505 		}
       
  6506 	_LIT(KMsg,"Chmod success");
       
  6507 	INFO_PRINTF1(KMsg) ;
       
  6508 	return KErrNone;
       
  6509 	}
       
  6510 	
       
  6511 	//-----------------------------------------------------------------------------
       
  6512 // This function test rename call for directories
       
  6513 
       
  6514 //------------------------------------------------------------------------------
       
  6515  
       
  6516 TInt CTestSyscalls :: Rename2() 
       
  6517 	{
       
  6518 	int fd ;
       
  6519 	TPtrC String ;
       
  6520 	TBuf8 <50> string ;
       
  6521 	TInt HasFiles ;
       
  6522 	char File1[50] ; 
       
  6523 	char File2[50] ;
       
  6524    
       
  6525 	_LIT( KTsyscalls, "Tsyscalls" );
       
  6526 	INFO_PRINTF1(KTsyscalls) ;
       
  6527 	_LIT( Krename, "In Rename2" );
       
  6528 	INFO_PRINTF1( Krename);
       
  6529    
       
  6530     
       
  6531 	_LIT( KString, "String" );
       
  6532 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  6533 
       
  6534 	if(!res) 
       
  6535 		{
       
  6536    		_LIT(Kerr , "failed to read input file name ") ;
       
  6537    		INFO_PRINTF1(Kerr) ;
       
  6538    		return KErrGeneral ;
       
  6539 		}
       
  6540    
       
  6541 	string.Copy(String) ; 
       
  6542 	char *file = (char *) string.Ptr() ;
       
  6543 	file[string.Length()] = '\0' ;
       
  6544    
       
  6545 	strcpy(File1 , file) ;
       
  6546 	TPtrC theString;
       
  6547 	_LIT( KtheString, "theString" );
       
  6548 	res = GetStringFromConfig(ConfigSection(), KtheString, theString );
       
  6549 	if(!res) 
       
  6550 		{
       
  6551    		_LIT(Kerr , "failed to read input file1 name ") ;
       
  6552    		INFO_PRINTF1(Kerr) ;
       
  6553    		return KErrGeneral ;
       
  6554 		}
       
  6555    
       
  6556 	string.Copy(theString) ; 
       
  6557 	file = (char *) string.Ptr() ;
       
  6558 	file[string.Length()] = '\0' ;
       
  6559    
       
  6560 	strcpy(File2 , file);
       
  6561    
       
  6562 	_LIT( KHasFiles, "HasFiles" );
       
  6563 	res = GetIntFromConfig(ConfigSection(), KHasFiles, HasFiles);
       
  6564  
       
  6565 	if(!res) 
       
  6566 		{
       
  6567     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  6568     	INFO_PRINTF1(Kerr) ;
       
  6569     	return KErrGeneral ;
       
  6570 		}
       
  6571 	switch(HasFiles) 
       
  6572    		{
       
  6573    		case 0 :
       
  6574    		   	{
       
  6575    		   	/*Rename empty directory*/
       
  6576    		   	res = mkdir(File1,0666);	   	
       
  6577 		   	if(res < 0 ) 
       
  6578 		   		{
       
  6579 		   		_LIT(Kerr , "Failed to create directory1\n") ;
       
  6580 		   		INFO_PRINTF1(Kerr) ;
       
  6581 		   		return KErrGeneral ;
       
  6582 		   		}
       
  6583    		   	if(rename(File1 , File2) < 0 ) 
       
  6584    		   		{
       
  6585    		   		_LIT(Kerr , "Rename of directory failed \n") ;
       
  6586    		   		INFO_PRINTF1(Kerr) ;
       
  6587    		   		rmdir(File1);
       
  6588    		   		return KErrGeneral ;
       
  6589    		   		}
       
  6590    		   	rmdir(File2);
       
  6591    		   	break ;
       
  6592    		   	}
       
  6593    		   	
       
  6594    		case 1:
       
  6595    			{ 
       
  6596    			/* Rename a non empty directory*/
       
  6597    			res = mkdir(File1,0666);	   	
       
  6598 			   	if(res < 0 ) 
       
  6599 			   		{
       
  6600 			   		_LIT(Kerr , "Failed to create directory1\n") ;
       
  6601 			   		INFO_PRINTF1(Kerr) ;
       
  6602 			   		return KErrGeneral ;
       
  6603 			   		}
       
  6604    			chdir(File1);
       
  6605    			fd =  open("./abc.txt" , O_CREAT | O_RDWR , 0666) ;  			
       
  6606    			if(fd < 0) 
       
  6607    				{
       
  6608    				_LIT(Kerr , "Failed to open given file2 \n") ;
       
  6609    				INFO_PRINTF1(Kerr) ;
       
  6610    				return KErrGeneral ;
       
  6611    				}
       
  6612    				close(fd);
       
  6613    			chdir("..");
       
  6614    			if(rename(File1 , File2) < 0 ) 
       
  6615    				{
       
  6616    				_LIT(Kerr , "Failed to Rename\n") ;
       
  6617    				printf("%d",errno);
       
  6618    				INFO_PRINTF1(Kerr) ;
       
  6619    				chdir(File1);
       
  6620    				if(unlink("./abc.txt")	< 0)
       
  6621 	   				{
       
  6622 	   				_LIT(Kerr , "Failed to unlinkfile2 \n") ;
       
  6623 	   				INFO_PRINTF1(Kerr) ;
       
  6624 	   				return KErrGeneral ;	
       
  6625 	   				}
       
  6626    				rmdir(File2);
       
  6627    				return KErrGeneral ;
       
  6628    				}
       
  6629    			chdir(File2);
       
  6630    			unlink("./abc.txt")	;
       
  6631    			chdir("..");
       
  6632    			rmdir(File2);
       
  6633    		    break ;	
       
  6634    			}
       
  6635    			case 2:
       
  6636 	   			{ 
       
  6637 	   			/* Try to rename to an nonempty destination*/
       
  6638 	   			res = mkdir(File1,0666);	   	
       
  6639 		   		if(res < 0 ) 
       
  6640 		   		{
       
  6641 		   		_LIT(Kerr , "Failed to create directory1\n") ;
       
  6642 		   		INFO_PRINTF1(Kerr) ;
       
  6643 		   		return KErrGeneral ;
       
  6644 		   		}
       
  6645 	   			res = mkdir(File2,0666);	
       
  6646 			   	if(res < 0 ) 
       
  6647 			   		{
       
  6648 			   		_LIT(Kerr , "Failed to create directory\n") ;
       
  6649 			   		INFO_PRINTF1(Kerr) ;
       
  6650 			   		rmdir(File1);
       
  6651 			   		return KErrGeneral ;
       
  6652 			   		}	
       
  6653 			   	chdir(File1);
       
  6654 		   		fd =  open("./abc.txt" , O_CREAT | O_RDWR , 0666) ;  			
       
  6655 		   		if(fd < 0) 
       
  6656 		   			{
       
  6657 		   			_LIT(Kerr , "Failed to open given file2 \n") ;
       
  6658 		   			INFO_PRINTF1(Kerr) ;
       
  6659 		   			return KErrGeneral ;
       
  6660 		   			}
       
  6661 		   			close(fd);
       
  6662 		   		chdir(File2);
       
  6663 		   		fd =  open("./abc.txt" , O_CREAT | O_RDWR , 0666) ;  			
       
  6664 		   		if(fd < 0) 
       
  6665 		   			{
       
  6666 		   			_LIT(Kerr , "Failed to open given file2 \n") ;
       
  6667 		   			INFO_PRINTF1(Kerr) ;
       
  6668 		   			return KErrGeneral ;
       
  6669 		   			}
       
  6670 		   			close(fd);
       
  6671 		   		if(rename(File1 , File2) == 0 ) 
       
  6672 		   			{
       
  6673 		   			_LIT(Kerr , "Test Case Failed\n") ;
       
  6674 		   			INFO_PRINTF1(Kerr) ;
       
  6675 		   			return KErrGeneral ;
       
  6676 		   			}
       
  6677 		   		chdir(File1);
       
  6678 		   		unlink("./abc.txt");
       
  6679 		   		chdir(File2);
       
  6680 		   		rmdir(File1);
       
  6681 		   		unlink("./abc.txt");
       
  6682 				chdir("..");
       
  6683 				rmdir(File2);
       
  6684 		   		break;
       
  6685 	   			}
       
  6686    		case 3:
       
  6687    			{
       
  6688    				/* Try to rename to an nonempty destination*/
       
  6689 	   			res = mkdir(File1,0666);	   	
       
  6690 		   		if(res < 0 ) 
       
  6691 		   		{
       
  6692 		   		_LIT(Kerr , "Failed to create directory1\n") ;
       
  6693 		   		INFO_PRINTF1(Kerr) ;
       
  6694 		   		return KErrGeneral ;
       
  6695 		   		}
       
  6696 	   			res = mkdir(File2,0666);	
       
  6697 			   	if(res < 0 ) 
       
  6698 			   		{
       
  6699 			   		_LIT(Kerr , "Failed to create directory\n") ;
       
  6700 			   		INFO_PRINTF1(Kerr) ;
       
  6701 			   		rmdir(File1);
       
  6702 			   		return KErrGeneral ;
       
  6703 			   		}	
       
  6704 			   	chdir(File1);
       
  6705 		   		fd =  open("./abc.txt" , O_CREAT | O_RDWR , 0666) ;  			
       
  6706 		   		if(fd < 0) 
       
  6707 		   			{
       
  6708 		   			_LIT(Kerr , "Failed to open given file2 \n") ;
       
  6709 		   			INFO_PRINTF1(Kerr) ;
       
  6710 		   			return KErrGeneral ;
       
  6711 		   			}
       
  6712 		   			close(fd);
       
  6713 		   		if(rename(File1 , File2) < 0 ) 
       
  6714 		   			{
       
  6715 		   			_LIT(Kerr , "Test Case Failed\n") ;
       
  6716 		   			INFO_PRINTF1(Kerr) ;
       
  6717 		   			return KErrGeneral ;
       
  6718 		   			}
       
  6719 		   		chdir(File2);
       
  6720 		   		unlink("./abc.txt");
       
  6721 				chdir("..");
       
  6722 				rmdir(File2);
       
  6723 		   		break;	
       
  6724    			}
       
  6725 		}	
       
  6726    	return KErrNone ;
       
  6727 	}
       
  6728 
       
  6729 //-------------------------------------------------------------------------------
       
  6730 
       
  6731 //  Test case : mkdir  makes a directory and checks with the expected value 
       
  6732 //            : returns 0 on success
       
  6733 //           
       
  6734 //
       
  6735 //--------------------------------------------------------------------------------                  
       
  6736 
       
  6737 TInt CTestSyscalls :: Mk_dir()
       
  6738 	{
       
  6739     TBuf8<50> string ;
       
  6740     TPtrC  String ;
       
  6741     TInt Expected , ret , Expected_Errno;     //To store expected and return values
       
  6742     
       
  6743     _LIT( KTsyscalls, "Tsyscalls" );
       
  6744     INFO_PRINTF1(KTsyscalls) ;
       
  6745     _LIT( Kmkdir, "In Mk_dir" );
       
  6746     INFO_PRINTF1( Kmkdir);
       
  6747     
       
  6748     
       
  6749     //First read input directory name
       
  6750     _LIT( KString, "String" );
       
  6751     TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  6752 
       
  6753     if(!res) 
       
  6754 		{
       
  6755 		_LIT(Kerr , "Failed to read input dir name from ini file") ;
       
  6756 		INFO_PRINTF1(Kerr) ;
       
  6757 		return KErrGeneral;
       
  6758 		}
       
  6759     string.Copy(String) ;
       
  6760     
       
  6761     char *DirName = (char *)string.Ptr() ;
       
  6762     
       
  6763     DirName[string.Length()] = '\0' ;
       
  6764      
       
  6765     //Read Expected value  
       
  6766     _LIT( KExpected, "Expected" );
       
  6767 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  6768  
       
  6769     if(!res) 
       
  6770 		{
       
  6771     	_LIT(Kerr , "Failed to read expected value from the ini file") ;
       
  6772     	INFO_PRINTF1(Kerr) ;
       
  6773     	return KErrGeneral ;
       
  6774 		}
       
  6775         
       
  6776     //errno Expected value  
       
  6777     _LIT( KExpected_Errno, "Expected_Errno" );
       
  6778 	res = GetIntFromConfig(ConfigSection(), KExpected_Errno, Expected_Errno);
       
  6779  
       
  6780     if(!res) 
       
  6781 		{
       
  6782     	_LIT(Kerr , "Failed to read expected errno value from the ini file") ;
       
  6783     	INFO_PRINTF1(Kerr) ;
       
  6784     	return KErrGeneral ;
       
  6785 		}
       
  6786     rmdir(DirName) ;
       
  6787      
       
  6788     ret = mkdir(DirName , S_IWUSR) ;
       
  6789     
       
  6790     if(ret == Expected ) 
       
  6791 		{
       
  6792     	if(errno == Expected_Errno)
       
  6793     		{
       
  6794     		_LIT(KSuccess, "Success in setting the errno value");
       
  6795     		INFO_PRINTF1(KSuccess);
       
  6796     		return KErrNone;
       
  6797     		}
       
  6798     	else
       
  6799     		{
       
  6800     		_LIT(KErr,"Failure in setting the errno value");
       
  6801     		INFO_PRINTF1(KErr);	
       
  6802     		return KErrGeneral;
       
  6803     		}
       
  6804 		}
       
  6805 	else
       
  6806 		{
       
  6807 		_LIT(KError,"Error in returning the value");
       
  6808     	INFO_PRINTF1(KError);
       
  6809     	return KErrGeneral;
       
  6810 		}
       
  6811 	}
       
  6812 
       
  6813 //-------------------------------------------------------------------------------
       
  6814 
       
  6815 //  Test case : rm_dir  removes the given direcorty and checks with the expected value 
       
  6816 //				Contains both positive and negative test cases	
       
  6817 //            : returns 0 on success
       
  6818 //            : -1 on failure  
       
  6819 //
       
  6820 //--------------------------------------------------------------------------------                  
       
  6821 
       
  6822 TInt CTestSyscalls :: Rm_dir()
       
  6823 	{
       
  6824 	_LIT( KTsyscalls, "Tsyscalls" );
       
  6825 	INFO_PRINTF1(KTsyscalls) ;
       
  6826 	_LIT( Krm_dir, "In Rm_dir" );
       
  6827 	INFO_PRINTF1( Krm_dir);
       
  6828    
       
  6829 	TInt Expected , Expected_Errno ;
       
  6830 	TPtrC String ;
       
  6831 	TBuf8<50>string ;
       
  6832 	TInt ret1 ;
       
  6833 
       
  6834 	_LIT( KString, "String" );
       
  6835 	TBool res = GetStringFromConfig(ConfigSection(), KString, String );
       
  6836 	if(!res) 
       
  6837 		{
       
  6838    		_LIT(Kerr , "Failed to read input dir name from ini file ") ;
       
  6839    		INFO_PRINTF1(Kerr) ;
       
  6840    		return KErrGeneral ;
       
  6841 		}
       
  6842 	string.Copy(String) ;
       
  6843    
       
  6844 	char *DirName = (char *) string.Ptr() ;
       
  6845 	DirName[string.Length()] = '\0' ;
       
  6846    
       
  6847 	_LIT( KExpected, "Expected" );
       
  6848 	res = GetIntFromConfig(ConfigSection(), KExpected, Expected);
       
  6849 	if(!res) 
       
  6850 		{
       
  6851    		_LIT(Kerr , "Failed to read input expected value ini file") ;
       
  6852    		INFO_PRINTF1(Kerr) ;
       
  6853    		return KErrGeneral ;
       
  6854 		}
       
  6855 		
       
  6856 	_LIT( KExpected_Errno, "Expected_Errno" );
       
  6857 	res = GetIntFromConfig(ConfigSection(), KExpected_Errno, Expected_Errno);
       
  6858 	if(!res) 
       
  6859 		{
       
  6860    		_LIT(Kerr , "Failed to read input expected value ini file") ;
       
  6861    		INFO_PRINTF1(Kerr) ;
       
  6862    		return KErrGeneral ;
       
  6863 		}
       
  6864 	if(Expected_Errno == 20)
       
  6865 	  	{
       
  6866 		int fd = open(DirName,O_WRONLY|O_CREAT);
       
  6867 		if(fd == -1)
       
  6868 			{
       
  6869 			_LIT(KErr,"failed to create a file and the errno is %d");
       
  6870 			INFO_PRINTF2(KErr,errno);
       
  6871 			return KErrGeneral;
       
  6872 			}
       
  6873 	  	}
       
  6874   	if(Expected < 0)
       
  6875 	  	{
       
  6876 	  	//negative test case
       
  6877 	  	ret1 = rmdir(DirName) ;
       
  6878 	   	if(ret1 == Expected ) 
       
  6879 	   		{   
       
  6880 	   	    if(errno == Expected_Errno)
       
  6881 	   		 	{
       
  6882 	   	        _LIT(Kmsg , "rmdir successfully passed") ;
       
  6883 	   			INFO_PRINTF1(Kmsg);
       
  6884 	   			return KErrNone;
       
  6885 	   			}
       
  6886 	   		else
       
  6887 	   			{
       
  6888 	   			_LIT(Kerr , "Failed to set errno value") ;
       
  6889 	   	       	INFO_PRINTF1(Kerr) ;
       
  6890 	   	       	return KErrGeneral ;
       
  6891 	   			}
       
  6892 	   		}
       
  6893 	   	else 
       
  6894 	   		{
       
  6895 	  		_LIT(Kerr , "Expected and actual values are different ") ;
       
  6896 	   		INFO_PRINTF1(Kerr) ;
       
  6897 	       	return KErrGeneral ;
       
  6898 	  		}
       
  6899 	   	}
       
  6900 	else
       
  6901 		{
       
  6902 		//to check only pass scenerio of rmdir
       
  6903 		mkdir(DirName,S_IWUSR);
       
  6904 		ret1 = rmdir(DirName);
       
  6905 		if(ret1 == 0)
       
  6906 			{
       
  6907 			_LIT(Kmsg1,"positive case of rmdir is success");
       
  6908 			INFO_PRINTF1(Kmsg1);
       
  6909 			return KErrNone;
       
  6910 			}
       
  6911 		else
       
  6912 			{
       
  6913 			_LIT(Kerr1,"failed to delete the directory");
       
  6914 			INFO_PRINTF1(Kerr1);
       
  6915 			return KErrGeneral;
       
  6916 			}
       
  6917 		}
       
  6918 	}
       
  6919 
       
  6920 /*
       
  6921  * Test case to verify the thread safety of the lseek & fsync api when the file is buffered.
       
  6922  */
       
  6923 
       
  6924 int fd;
       
  6925 
       
  6926 void* handler(void *)
       
  6927 	{
       
  6928 	int ret;
       
  6929 	ret = fsync(fd);
       
  6930 	ret = ret;
       
  6931 	return 0;
       
  6932 	}
       
  6933 
       
  6934 
       
  6935 void* handler1(void *)
       
  6936 	{
       
  6937 	int ret;
       
  6938 	lseek(fd, 2, SEEK_SET);
       
  6939 	ret = fsync(fd);   //only one fsync should be able to sync the data.
       
  6940 	ret = ret;
       
  6941 	return 0;
       
  6942 	}
       
  6943 
       
  6944 TInt CTestSyscalls :: sync_safe()
       
  6945 	{
       
  6946 	int fd1,ret;
       
  6947 	char buf[5];
       
  6948 	pthread_t thread_a, thread_b;
       
  6949 	unlink("c:\\readfrom.txt");
       
  6950 	unlink("c:\\writeto.txt");
       
  6951 	fd1 = open("c:\\readfrom.txt", O_RDWR | O_CREAT, 0666);
       
  6952 	write(fd1,"hello",5);
       
  6953 	lseek(fd1,0,SEEK_SET);
       
  6954 	fd = open("c:\\writeto.txt",O_RDWR | O_CREAT | O_BUFFERED);
       
  6955 	ret = read(fd1, buf, sizeof(buf));
       
  6956  	ret = write(fd,buf,sizeof(buf));
       
  6957 	pthread_create (&thread_a, 0 , handler, 0);
       
  6958 	pthread_create (&thread_b, 0 , handler1, 0);
       
  6959 	
       
  6960 	pthread_join(thread_a, NULL);
       
  6961 	pthread_join(thread_b, NULL);
       
  6962 	lseek(fd, 0, SEEK_SET);
       
  6963 	ret = read(fd, buf, sizeof(buf));
       
  6964 	if(ret == -1)
       
  6965 	{
       
  6966 		INFO_PRINTF2(_L("The errno set from read api is %d"),errno);
       
  6967 		unlink("c:\\readfrom.txt");
       
  6968 		unlink("c:\\writeto.txt");
       
  6969 		return KErrGeneral;
       
  6970 	}
       
  6971 	if(strncmp(buf,"hello",5)!=0)
       
  6972 	{
       
  6973 		INFO_PRINTF1(_L("The test has failed"));
       
  6974 		unlink("c:\\readfrom.txt");
       
  6975 		unlink("c:\\writeto.txt");
       
  6976 		return KErrGeneral;
       
  6977 	}
       
  6978 		
       
  6979 	close(fd1);
       
  6980 	close(fd);
       
  6981 	unlink("c:\\readfrom.txt");
       
  6982 	unlink("c:\\writeto.txt");
       
  6983 	return KErrNone;
       
  6984 	}
       
  6985 
       
  6986 
       
  6987 TInt CTestSyscalls :: testfsync() // negative test case so on errr conditions returning KErrNone
       
  6988 	{
       
  6989 	
       
  6990 	int x = 0,res=KErrNone;
       
  6991 	x=fsync(0);
       
  6992 	if(x<0)
       
  6993 		{
       
  6994 		INFO_PRINTF1(_L("fsync failed on STDIN"));
       
  6995 		res=KErrGeneral;
       
  6996 		}
       
  6997 	else 
       
  6998 		{
       
  6999 		INFO_PRINTF1(_L("fsync passed on STDIN"));
       
  7000 		}
       
  7001 	return res;
       
  7002 	}
       
  7003 
       
  7004 
       
  7005 	
       
  7006 /*********************************************/
       
  7007 /*negative test case for Rename()
       
  7008 To check whether the errno set in the case where we try to rename
       
  7009 C:\\orig to C:\\\orig\\dest is EINVAL or not*/
       
  7010 /*********************************************/
       
  7011 
       
  7012 TInt CTestSyscalls :: testrename() 
       
  7013 	{	
       
  7014 	int err = 0;
       
  7015 	int res = mkdir("C:\\Orig\\", 0666)	;
       
  7016 	if (res < 0)
       
  7017 		{
       
  7018 		INFO_PRINTF1(_L("mkdir() for parent directory failed\n"));
       
  7019 		return res;
       
  7020 		}
       
  7021 	/*check for Rename() when old path present and new path absent
       
  7022 	  and new path is the child directory of old path*/
       
  7023 	res = rename("C:\\Orig\\", "C:\\Orig\\Dest"); 
       
  7024 	err = errno;
       
  7025 	if (err != 22)
       
  7026 		{
       
  7027 		INFO_PRINTF4(_L("%d, %d , %s\n"), res, err, strerror(err));
       
  7028 		}
       
  7029 	else
       
  7030 		{
       
  7031 		INFO_PRINTF1(_L("Rename() set the correct errno when C:\\Orig\\Dest\\ is not present\n"));
       
  7032 		}
       
  7033 	/*check for Rename() when old path present and new path present
       
  7034 	  and new path is the child directory of old path*/
       
  7035 	res = mkdir("C:\\Orig\\Dest\\", 0666)	;
       
  7036 	if (res < 0)
       
  7037 		{
       
  7038 		INFO_PRINTF1(_L("mkdir() for child directory failed\n"));
       
  7039 		return res;
       
  7040 		}
       
  7041 	res = rename("C:\\Orig\\", "C:\\Orig\\Dest"); 
       
  7042 	err = errno;
       
  7043 	if (err != 22)
       
  7044 		{
       
  7045 		INFO_PRINTF4(_L("%d, %d , %s\n"), res, err, strerror(err));
       
  7046 		}
       
  7047 	else
       
  7048 		{
       
  7049 		INFO_PRINTF1(_L("Rename() set the correct errno when C:\\Orig\\Dest\\ is present\n"));
       
  7050 		}
       
  7051 	res = rmdir("C:\\Orig\\Dest\\");
       
  7052 	if (res < 0)
       
  7053 		{
       
  7054 		INFO_PRINTF1(_L("rmdir() for child directory failed\n"));
       
  7055 		return res;
       
  7056 		}
       
  7057 	res = rmdir("C:\\Orig\\");
       
  7058 	if (res < 0)
       
  7059 		{
       
  7060 		INFO_PRINTF1(_L("rmdir() for parent directory failed\n"));
       
  7061 		return res;
       
  7062 		}
       
  7063 	return res;
       
  7064 	}
       
  7065 
       
  7066 /**************************************************************
       
  7067 negative test case for Open()
       
  7068 To check whether the errno set in the case where 
       
  7069 we try to open a file in read only mode with O_TRUNC
       
  7070 errno = EACCES
       
  7071 we try to open a existing file with O_CREAT and O_EXCL
       
  7072 errno = EXIST
       
  7073 we try to open a existing file with O_CREAT, O_EXCL and O_APPEND
       
  7074 errno = EXIST
       
  7075 we try to open a existing file with O_CREAT, O_EXCL and O_TRUNC
       
  7076 errno = EXIST
       
  7077 ****************************************************************/
       
  7078 
       
  7079 TInt CTestSyscalls :: testopenvalidate() 
       
  7080 	{
       
  7081 	INFO_PRINTF1(_L("open a file in read-only mode\n"));
       
  7082 	int fd = open("c:\\opentest.txt",O_CREAT, S_IRUSR);
       
  7083 	if (fd < 0)
       
  7084 		{
       
  7085 		INFO_PRINTF1(_L("open() a file in read-only mode failed\n"));
       
  7086 		return fd;
       
  7087 		}	
       
  7088 	INFO_PRINTF1(_L("open the existing read-only file with O_TRUNC mode\n"));
       
  7089 	int fd1 = open("c:\\opentest.txt",O_TRUNC);
       
  7090 	if (fd1 < 0)
       
  7091 		{
       
  7092 		INFO_PRINTF1(_L("open the existing read-only file with O_TRUNC mode failed\n"));
       
  7093 		if (errno != EACCES)
       
  7094 			{
       
  7095 			INFO_PRINTF1(_L("open() doesn't set errno correctly for the existing read-only file opened with O_TRUNC mode\n"));
       
  7096 			return fd1;
       
  7097 			}
       
  7098 		INFO_PRINTF2(_L("open() set errno correctly for the existing read-only file opened with O_TRUNC mode to %d\n"), errno);
       
  7099 		}
       
  7100 	int ret = close(fd);
       
  7101 	if (ret < 0)
       
  7102 		{
       
  7103 		INFO_PRINTF1(_L("close() for the file fd failed\n"));
       
  7104 		return ret;
       
  7105 		}
       
  7106 	ret = unlink("c:\\opentest.txt");
       
  7107 	if (ret < 0)
       
  7108 		{
       
  7109 		INFO_PRINTF1(_L("unlink() for the file failed\n"));
       
  7110 		return ret;
       
  7111 		}
       
  7112 	INFO_PRINTF1(_L("open a file in read-write mode\n"));
       
  7113 	int fd2 = open("c:\\opentest.txt",O_CREAT, 0600);
       
  7114 	if (fd2 < 0)
       
  7115 		{
       
  7116 		INFO_PRINTF1(_L("open() for the file in read-write mode failed\n"));
       
  7117 		return fd2;
       
  7118 		}	
       
  7119 	INFO_PRINTF1(_L("open the existing file with O_CREAT and O_EXCL mode\n"));
       
  7120 	int fd3 = open("c:\\opentest.txt",O_CREAT|O_EXCL);
       
  7121 	if (fd3 < 0)
       
  7122 		{
       
  7123 		INFO_PRINTF1(_L("open the existing file with O_CREAT|O_EXCL mode failed\n"));
       
  7124 		if (errno != EEXIST)
       
  7125 			{
       
  7126 			INFO_PRINTF1(_L("open() doesn't set errno correctly for the existing file opened with O_CREAT|O_EXCL mode\n"));
       
  7127 			return fd3;
       
  7128 			}
       
  7129 		INFO_PRINTF2(_L("open() set errno correctly for the existing file opened with O_CREAT|O_EXCL mode to %d\n"), errno);
       
  7130 		}
       
  7131 	INFO_PRINTF1(_L("open the existing file with O_CREAT,O_EXCL and O_APPEND mode\n"));
       
  7132 	int fd4 = open("c:\\opentest.txt",O_CREAT|O_EXCL|O_APPEND);
       
  7133 	if (fd4 < 0)
       
  7134 		{
       
  7135 		INFO_PRINTF1(_L("open the existing file with O_CREAT|O_EXCL|O_APPEND mode failed\n"));
       
  7136 		if (errno != EEXIST)
       
  7137 			{
       
  7138 			INFO_PRINTF1(_L("open() doesn't set errno correctly for the existing file opened with O_CREAT|O_EXCL|O_APPEND mode\n"));
       
  7139 			return fd4;
       
  7140 			}
       
  7141 		INFO_PRINTF2(_L("open() set errno correctly for the existing file opened with O_CREAT|O_EXCL mode to %d\n"), errno);
       
  7142 		}
       
  7143 	INFO_PRINTF1(_L("open the existing file with O_CREAT,O_EXCL and O_TRUNC mode\n"));
       
  7144 	int fd5 = open("c:\\opentest.txt",O_CREAT|O_EXCL|O_TRUNC);
       
  7145 	if (fd5 < 0)
       
  7146 		{
       
  7147 		INFO_PRINTF1(_L("open the existing file with O_CREAT|O_EXCL|O_TRUNC mode failed\n"));
       
  7148 		if (errno != EEXIST)
       
  7149 			{
       
  7150 			INFO_PRINTF1(_L("open() doesn't set errno correctly for the existing file opened with O_CREAT|O_EXCL|O_TRUNC mode\n"));
       
  7151 			return fd5;
       
  7152 			}
       
  7153 		INFO_PRINTF2(_L("open() set errno correctly for the existing file opened with O_CREAT|O_EXCL|O_TRUNC mode to %d\n"), errno);
       
  7154 		}
       
  7155 	ret = close(fd2);
       
  7156 	if (ret < 0)
       
  7157 		{
       
  7158 		INFO_PRINTF1(_L("close() for the file fd failed\n"));
       
  7159 		return ret;
       
  7160 		}
       
  7161 	ret = unlink("c:\\opentest.txt");
       
  7162 	if (ret < 0)
       
  7163 		{
       
  7164 		INFO_PRINTF1(_L("unlink() for the file failed\n"));
       
  7165 		return ret;
       
  7166 		}
       
  7167 	return 0;
       
  7168 	}
       
  7169 TInt CTestSyscalls :: Fstat1() 
       
  7170 	{
       
  7171 	int fd ,ret;
       
  7172 	char* file = "C:\\Test\\Fstatt57.txt";
       
  7173 	if((fd = open(file , O_CREAT | O_RDWR | O_TRUNC , 0666)) < 0) 
       
  7174 		{
       
  7175    		_LIT(Kerr , "Failed to open specified file ") ;
       
  7176    		INFO_PRINTF1(Kerr) ;
       
  7177    		return KErrGeneral ;
       
  7178 		}
       
  7179 	ret = fstat(fd,NULL);
       
  7180 	if(ret == -1)
       
  7181 		{
       
  7182 		return KErrNone;
       
  7183 		}
       
  7184 	else
       
  7185 		{
       
  7186 		return KErrGeneral;
       
  7187 		}
       
  7188 	}
       
  7189 
       
  7190 TInt CTestSyscalls :: Utimes1()
       
  7191 	{
       
  7192     
       
  7193     TBuf8<50>string ;
       
  7194     TPtrC String ;
       
  7195  
       
  7196     _LIT( KTsyscalls, "Tsyscalls" );
       
  7197     INFO_PRINTF1(KTsyscalls) ;
       
  7198     _LIT( Kutimes, "In Utimes" );
       
  7199     INFO_PRINTF1(Kutimes);
       
  7200    
       
  7201 	struct timeval tim[2] ;
       
  7202 
       
  7203 	tim[0].tv_sec = 0 ; tim[0].tv_usec = 0;
       
  7204 	tim[1].tv_sec = 0 ; tim[1].tv_usec = 0;
       
  7205 
       
  7206 	if(utimes(NULL,tim) < 0 ) 
       
  7207 		{
       
  7208      
       
  7209 		_LIT(Kstmt, "Utime Successful") ;
       
  7210 		INFO_PRINTF1(Kstmt) ;
       
  7211 		return KErrNone ;
       
  7212 		}
       
  7213 	return KErrGeneral ;
       
  7214 	}
       
  7215 TInt CTestSyscalls :: Mkdir_test1()
       
  7216 	{
       
  7217 	
       
  7218 	TInt ret,ret1;
       
  7219      
       
  7220     ret1 = mkdir(NULL, S_IWUSR) ;
       
  7221     
       
  7222     if(ret1 == -1 ) 
       
  7223     	{
       
  7224     	_LIT(Kstmt , "mkdir success") ;
       
  7225     	INFO_PRINTF1(Kstmt);
       
  7226         ret=  KErrNone ;
       
  7227     	}
       
  7228 	else 
       
  7229 		{
       
  7230     	 _LIT(Kerr , "Expected and the return values are different ") ;
       
  7231     	 ERR_PRINTF1(Kerr) ;
       
  7232     	 ret = KErrGeneral; 
       
  7233 		}
       
  7234     return ret;
       
  7235     }
       
  7236 
       
  7237 TInt CTestSyscalls :: Chmod_test()
       
  7238 	{
       
  7239 	TInt ret1;
       
  7240 	ret1 = chmod(NULL, S_IWUSR) ;
       
  7241     
       
  7242     if(ret1 == -1) 
       
  7243 		{
       
  7244 		_LIT(Kstmt, "chmod Success") ;
       
  7245       	INFO_PRINTF1(Kstmt) ;
       
  7246       	return KErrNone ;
       
  7247 		}
       
  7248     
       
  7249     else
       
  7250     	{
       
  7251     	_LIT(Kerr , "Failed to change the modes of the file ") ;
       
  7252 		INFO_PRINTF1(Kerr) ;
       
  7253 		return KErrGeneral ;
       
  7254 		}
       
  7255 	}
       
  7256 TInt CTestSyscalls :: Chdir1()
       
  7257 	{
       
  7258 	TInt ret ;
       
  7259    
       
  7260 	ret = chdir(NULL) ;
       
  7261   
       
  7262 	if(ret  == -1)   
       
  7263 		{
       
  7264 		_LIT(Kerr , "Chdir Success") ;
       
  7265    	  	INFO_PRINTF1(Kerr) ;
       
  7266    	  	return KErrNone;
       
  7267    		}
       
  7268 	else
       
  7269 		{
       
  7270 		_LIT(Kerr, "Expected and return value are different") ;
       
  7271  		INFO_PRINTF1(Kerr);
       
  7272 		return KErrGeneral ;
       
  7273 		}
       
  7274     }
       
  7275 
       
  7276 TInt CTestSyscalls :: Rmdir2()
       
  7277 	{
       
  7278 	    
       
  7279     if(rmdir(NULL)  < 0) 
       
  7280 		{
       
  7281 		_LIT(Kerr , "rmdir success") ;
       
  7282     	INFO_PRINTF1(Kerr) ;
       
  7283     	return KErrNone ;
       
  7284 		}
       
  7285     return KErrGeneral ;
       
  7286 	}
       
  7287 
       
  7288 TInt CTestSyscalls :: Rename_test()
       
  7289 	{
       
  7290 	int ret; 
       
  7291 	ret =  rename(NULL,"C:\\Test\\Fstatt57.txt") ;
       
  7292        
       
  7293 	if(ret<1)
       
  7294 		{
       
  7295 		_LIT(Kerr , "rename success") ;
       
  7296     	INFO_PRINTF1(Kerr) ;
       
  7297     	return KErrNone ;
       
  7298 		}
       
  7299     return KErrGeneral ;
       
  7300 	}
       
  7301 TInt CTestSyscalls :: Rename3()
       
  7302 	{
       
  7303 	int ret; 
       
  7304 	ret =  rename("C:\\Test\\Fstatt57.txt",NULL) ;
       
  7305        
       
  7306 	if(ret<1)
       
  7307 		{
       
  7308 		_LIT(Kerr , "rename success") ;
       
  7309     	INFO_PRINTF1(Kerr) ;
       
  7310     	return KErrNone ;
       
  7311 		}
       
  7312     return KErrGeneral ;
       
  7313     
       
  7314 	}
       
  7315 
       
  7316 TInt CTestSyscalls :: Creat1(  )
       
  7317 	{
       
  7318     int fd ;
       
  7319    
       
  7320     if((fd = creat(NULL,  0666))  < 0) 
       
  7321 		{
       
  7322         _LIT(Kstmt , "creat success") ;
       
  7323         INFO_PRINTF1(Kstmt) ;
       
  7324     	return KErrNone ;
       
  7325 		}
       
  7326     close(fd) ;
       
  7327     return KErrGeneral ;
       
  7328     }
       
  7329 
       
  7330 TInt CTestSyscalls :: ReadV1()
       
  7331 	{
       
  7332 	char Buf1[20]  ;    //= "Hello World";
       
  7333 	char Buf2[20]  ;     //=  "By ritche" ; 
       
  7334 	struct iovec Iovec[2] ;
       
  7335 	TInt ret=KErrNone;
       
  7336 	Iovec[0].iov_base = Buf1 ;
       
  7337 	Iovec[0].iov_len = sizeof("Hello World")  ;
       
  7338 	Iovec[1].iov_base = Buf2 ;
       
  7339 	Iovec[1].iov_len = sizeof("By ritche") ;
       
  7340    
       
  7341    	char *file = "c:\\logs\\temp.txt";
       
  7342 	TInt fd = open(file , O_CREAT | O_RDWR  , 0666) ;
       
  7343    
       
  7344 	if(fd < 0) 
       
  7345 		{
       
  7346 		_LIT(Kerr , "failed to open the given file ") ;
       
  7347 		INFO_PRINTF1(Kerr) ;
       
  7348 		ret = KErrGeneral ;	
       
  7349 		}
       
  7350    
       
  7351    
       
  7352 	if(readv(fd , Iovec , -1) < 0 && errno == EINVAL ) 
       
  7353 		{
       
  7354 		_LIT(Kstmt , "readv success") ;
       
  7355 		INFO_PRINTF1(Kstmt) ;
       
  7356 		ret = KErrNone ;	
       
  7357 		}
       
  7358    
       
  7359 	else
       
  7360 		{
       
  7361    		_LIT(Kerr, "readv failure") ;
       
  7362    		INFO_PRINTF1(Kerr) ;
       
  7363    		ret = KErrGeneral ;
       
  7364 		}
       
  7365   	return ret;
       
  7366 
       
  7367 	}
       
  7368 
       
  7369  TInt CTestSyscalls :: Utimes2()
       
  7370  	{
       
  7371      
       
  7372      char mbcbuf[64];
       
  7373      mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7374     	
       
  7375      _LIT( KTsyscalls, "Tsyscalls" );
       
  7376      INFO_PRINTF1(KTsyscalls) ;
       
  7377      _LIT( Kutimes, "In Utimes" );
       
  7378      INFO_PRINTF1(Kutimes);
       
  7379     
       
  7380  	struct timeval tim[2] ;
       
  7381  
       
  7382  	tim[0].tv_sec = 0 ; tim[0].tv_usec = 0;
       
  7383  	tim[1].tv_sec = 0 ; tim[1].tv_usec = 0;
       
  7384  
       
  7385  	if(utimes(mbcbuf,tim) < 0 ) 
       
  7386  		{
       
  7387       
       
  7388  		_LIT(Kstmt, "Utime Successful") ;
       
  7389  		INFO_PRINTF1(Kstmt) ;
       
  7390  		return KErrNone ;
       
  7391  		}
       
  7392  	return KErrGeneral ;
       
  7393  	}
       
  7394  	
       
  7395  TInt CTestSyscalls :: Stat_test() 
       
  7396  	{
       
  7397  	
       
  7398  	char mbcbuf[64];
       
  7399     	int result,ret=KErrNone;
       
  7400     	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7401     	
       
  7402  	struct stat statbuf ;
       
  7403     	result = stat(mbcbuf , &statbuf) ;
       
  7404     	
       
  7405     	if(result<0)
       
  7406     		{
       
  7407     		_LIT(Kstmt, "stat Successful") ;
       
  7408  		INFO_PRINTF1(Kstmt) ;
       
  7409  		}
       
  7410     	else
       
  7411     		{	
       
  7412     		_LIT(Kstmt, "stat failure") ;
       
  7413  		INFO_PRINTF1(Kstmt) ;
       
  7414  		ret = KErrGeneral ;
       
  7415     		}		   
       
  7416  	return ret;
       
  7417  	}
       
  7418  
       
  7419  TInt CTestSyscalls :: Mkdir_test2()
       
  7420  	{
       
  7421  	
       
  7422  	TInt ret,ret1;
       
  7423      char mbcbuf[64];
       
  7424      mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7425      ret1 = mkdir(mbcbuf, S_IWUSR) ;
       
  7426      
       
  7427      if(ret1 == -1 ) 
       
  7428      	{
       
  7429      	_LIT(Kstmt , "mkdir success") ;
       
  7430      	INFO_PRINTF1(Kstmt);
       
  7431          ret=  KErrNone ;
       
  7432      	}
       
  7433  	else 
       
  7434  		{
       
  7435      	 _LIT(Kerr , "Expected and the return values are different ") ;
       
  7436      	 ERR_PRINTF1(Kerr) ;
       
  7437      	 ret = KErrGeneral; 
       
  7438  		}
       
  7439      return ret;
       
  7440      }
       
  7441  
       
  7442  TInt CTestSyscalls :: Chmod2()
       
  7443  	{
       
  7444  	TInt ret1;
       
  7445  	char mbcbuf[64];
       
  7446  	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7447  	ret1 = chmod(mbcbuf, S_IWUSR) ;
       
  7448      
       
  7449      if(ret1 == -1) 
       
  7450  		{
       
  7451  		_LIT(Kstmt, "chmod Success") ;
       
  7452        	INFO_PRINTF1(Kstmt) ;
       
  7453        	return KErrNone ;
       
  7454  		}
       
  7455      
       
  7456      else
       
  7457      	{
       
  7458      	_LIT(Kerr , "Failed to change the modes of the file ") ;
       
  7459  		INFO_PRINTF1(Kerr) ;
       
  7460  		return KErrGeneral ;
       
  7461  		}
       
  7462  	}
       
  7463  TInt CTestSyscalls :: Chdir2()
       
  7464  	{
       
  7465  	TInt ret ;
       
  7466  	char mbcbuf[64];
       
  7467  	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7468  	ret = chdir(mbcbuf) ;
       
  7469    
       
  7470  	if(ret  == -1)   
       
  7471  		{
       
  7472  		_LIT(Kerr , "Chdir Success") ;
       
  7473     	  	INFO_PRINTF1(Kerr) ;
       
  7474     	  	return KErrNone;
       
  7475     		}
       
  7476  	else
       
  7477  		{
       
  7478  		_LIT(Kerr, "Expected and return value are different") ;
       
  7479   		INFO_PRINTF1(Kerr);
       
  7480  		return KErrGeneral ;
       
  7481  		}
       
  7482      }
       
  7483  
       
  7484  TInt CTestSyscalls :: Rename4()
       
  7485  	{
       
  7486  	int ret; 
       
  7487  	char mbcbuf[64];
       
  7488  	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7489  	ret =  rename(mbcbuf,"C:\\Test\\rename1.txt") ;
       
  7490         
       
  7491  	if(ret<0)
       
  7492  		{
       
  7493  		_LIT(Kerr , "rename success") ;
       
  7494      	INFO_PRINTF1(Kerr) ;
       
  7495      	return KErrNone ;
       
  7496  		}
       
  7497      return KErrGeneral ;
       
  7498      
       
  7499  	}
       
  7500  TInt CTestSyscalls :: Rename5()
       
  7501  	{
       
  7502  	int ret; 
       
  7503  	char mbcbuf[64];
       
  7504  	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7505  	ret =  rename("C:\\Test\\rename1.txt",mbcbuf) ;
       
  7506         
       
  7507  	if(ret<0)
       
  7508  		{
       
  7509  		_LIT(Kerr , "rename success") ;
       
  7510      	INFO_PRINTF1(Kerr) ;
       
  7511      	return KErrNone ;
       
  7512  		}
       
  7513      return KErrGeneral ;
       
  7514      
       
  7515  	}
       
  7516  TInt CTestSyscalls :: Rmdir3()
       
  7517  	{
       
  7518  	char mbcbuf[64];
       
  7519  	mbcbuf[0] = (unsigned char)0x3A;// colon :
       
  7520 
       
  7521      if(rmdir(mbcbuf)  < 0) 
       
  7522  		{
       
  7523  		_LIT(Kerr , "rmdir success") ;
       
  7524      	INFO_PRINTF1(Kerr) ;
       
  7525      	return KErrNone ;
       
  7526  		}
       
  7527      return KErrGeneral ;
       
  7528  	}
       
  7529  
       
  7530  TInt CTestSyscalls :: read5()
       
  7531  	{
       
  7532   	
       
  7533   	int fd; 
       
  7534      int ret=KErrNone;
       
  7535      char Buf[20] ;
       
  7536      if((fd = open("C:\\Test\\rename1.txt" , O_CREAT | O_WRONLY , 0666))  < 0) 
       
  7537  		{
       
  7538  		_LIT(Kopen , "Failed to open file " ) ;
       
  7539  		INFO_PRINTF1(Kopen) ;
       
  7540  		return KErrGeneral  ;
       
  7541  		}
       
  7542      
       
  7543      if(read(fd , Buf , 0)  == 0) 
       
  7544  		{
       
  7545      	if(errno != EBADF) 
       
  7546      		{
       
  7547      		_LIT(Kstmt , "read success \n") ;
       
  7548      		INFO_PRINTF1(Kstmt) ;
       
  7549      		ret = KErrNone ;
       
  7550      		}
       
  7551  		}
       
  7552      
       
  7553  	else   
       
  7554  		{
       
  7555  		_LIT(Kerr , "Read failed") ;
       
  7556  		INFO_PRINTF1(Kerr) ;
       
  7557  		ret = KErrGeneral ;
       
  7558  		}
       
  7559      
       
  7560      return ret ; 
       
  7561  
       
  7562  	}
       
  7563  	
       
  7564  
       
  7565 //---------------------------------------------------------------------------
       
  7566 //Stat Test cases 
       
  7567 //---------------------------------------------------------------------------
       
  7568 
       
  7569 
       
  7570 TInt CTestSyscalls :: Stat3() 
       
  7571 	{
       
  7572 
       
  7573 		struct stat buf;
       
  7574        		if(stat("Y:\\"  , &buf) < 0 )	 //return -1,if memory card not mounted
       
  7575        
       
  7576        		printf("Failed to stat Y:\\n");          
       
  7577           
       
  7578        		printf("Stat system call succeeded \n"); 
       
  7579        		getchar();
       
  7580        		return 0; 
       
  7581 	}
       
  7582 
       
  7583 
       
  7584