genericopenlibs/openenvcore/libc/test/testsysunistd/src/tsysunistdblocks.cpp
changeset 18 47c74d1534e1
parent 0 e4d67989cc36
child 45 4b03adbd26ca
child 57 2efc27d87e1c
equal deleted inserted replaced
0:e4d67989cc36 18:47c74d1534e1
  1399 	char* filedir = "c:\\largefile.txt";
  1399 	char* filedir = "c:\\largefile.txt";
  1400 	off_t length = 0xFF;//255
  1400 	off_t length = 0xFF;//255
  1401 	int fd = open(filedir, O_CREAT|O_RDWR, 0666);
  1401 	int fd = open(filedir, O_CREAT|O_RDWR, 0666);
  1402 	int val = ftruncate(fd, length);
  1402 	int val = ftruncate(fd, length);
  1403 	int thirdarg = 7;
  1403 	int thirdarg = 7;
       
  1404 	
       
  1405 	int ret;
  1404 	int fd2 = fcntl(fd, F_DUPFD, thirdarg);
  1406 	int fd2 = fcntl(fd, F_DUPFD, thirdarg);
  1405 	INFO_PRINTF2(_L("first fcntl call returns = %d"), fd2);
  1407 	INFO_PRINTF2(_L("first fcntl call returns = %d"), fd2);
  1406 	if(fd2 >= thirdarg)
  1408 	if(fd2 >= thirdarg)
  1407 		{
  1409 		{
  1408 		INFO_PRINTF2(_L("Passed, the file descriptor is >=  third argument i.e %d"), thirdarg); 
  1410 		INFO_PRINTF2(_L("Passed, the file descriptor is >=  third argument i.e %d"), thirdarg); 
  1409 		}
  1411 		}
  1410 	else
  1412 	else
  1411 		{
  1413 		{
  1412 		ERR_PRINTF2(_L("Failed, the file descriptor is < third argument i.e %d"), thirdarg);
  1414 		ERR_PRINTF2(_L("Failed, the file descriptor is < third argument i.e %d"), thirdarg);
  1413 		retVal = -1;
  1415 		retVal = -1;
  1414 		goto cleanup;
  1416 		close(fd);
       
  1417         close(fd2);
       
  1418         unlink(filedir);
       
  1419         return retVal;
  1415 		}
  1420 		}
  1416 	thirdarg = 10;
  1421 	thirdarg = 10;
  1417 	int fd3 = fcntl(fd, F_DUPFD, thirdarg);
  1422 	int fd3 = fcntl(fd, F_DUPFD, thirdarg);
  1418 	INFO_PRINTF2(_L("second fcntl call returns = %d"), fd3);	
  1423 	INFO_PRINTF2(_L("second fcntl call returns = %d"), fd3);	
  1419 	if(fd3 >= thirdarg)
  1424 	if(fd3 >= thirdarg)
  1425 		ERR_PRINTF2(_L("Failed, the file descriptor is < third argument i.e %d"), thirdarg);
  1430 		ERR_PRINTF2(_L("Failed, the file descriptor is < third argument i.e %d"), thirdarg);
  1426 		retVal = -1;
  1431 		retVal = -1;
  1427 		goto cleanup;
  1432 		goto cleanup;
  1428 		}
  1433 		}
  1429 	//making use of the duplicate fd3 obtained by the fcntl call
  1434 	//making use of the duplicate fd3 obtained by the fcntl call
  1430 	int ret = write(fd3, "merlyn", 6);
  1435 	ret = write(fd3, "merlyn", 6);
  1431 	if (6 == ret)
  1436 	if (6 == ret)
  1432 		{
  1437 		{
  1433 		INFO_PRINTF2(_L("write returns = %d"), ret);
  1438 		INFO_PRINTF2(_L("write returns = %d"), ret);
  1434 		}
  1439 		}
  1435 	else
  1440 	else