Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

In my C++ application, wherein, I am trying to allocate Buffer and Read the buffer allocated, and ensure Read SCSI() returns successfully(Good Status)

my Steps. 1. Write Some buffer check write buffer successfull assume 512 bytes
2. Read the same buffer written ensure ReadSCSI is successfull.
3. Ultimately ensure Write buffer and Read buffer comparison is identical,

I need a snippet of code(directly compares Write Buffer/Read Buffer without convolutions) where in Compare(Read/Write)buffer is same, if not otherwise throw an exception?

I am using VS2008 IDE, VC++ environment.(Windows 7 o/s).

With Regards,
Vishalk_90





<pre lang="c++">SaveToLog(LOG_POS1, Write(write_Buffer,lba,num_of_sect,0,0);
	if((ec = ProjCmd.Write(lba,write_buffer,1,0,0) != EC_NOERROR)
	{
		SaveToLog(LOG_ERR1, "Write Wrapper failed. Unexpected ec: 0x%x", ec);
		return false;
	}

	SAVEToLog(LOG_STEP, "Verify if Write Command Successfully Completed");

	ProjCmd.Sensekey(EC_NOERROR, "Write Command did not return Good Status");
	SaveToLog(LOG_MSG1, "Write command erturned Good Status");


	SaveToLog(LOG_STEP2, "Issue Read Command by giving the input parameters");

	if((ec= ProjCmd.Read(lba,Read_buffer,num_of_sect,0,0) != EC_NOERROR)
	{
		SaveToLog(LOG_ERR, "Read Wrapper failed, Unexpected ec: 0x%x",ec);
		return false;
	}
	ProjCmd.parser.AssertSenseKey(EC_NOERROR, "Read Command did not return Good Status");
	SaveToLog(LOG_STEP,"Verify if Read returned  correct amount of data");
	
	ProjCmd.parser.GetReturnLength(dataTransLen);

	if(dataTransLen != 512)
	{

		SaveToLog(LOG_ERR, "Read Command did not transfer the correct amount of data");
        return false;
	}

	SaveToLog(LOG_MSG, "Read Buffer & Write Buffer is same");

	return true;
Posted
Updated 18-Jun-12 5:37am
v2

1 solution

http://www.cplusplus.com/reference/clibrary/cstring/memcmp/[^]

XML
<pre lang="c++">

if ( memcmp ( read_Buffer, write_Buffer, len ) != 0 )
   throw -1;  // Or whatever you want to throw...

</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900