Esempio n. 1
0
File: ired.c Progetto: radare/ired
int main(int argc, char **argv) {
    int i, ret = 1;
    argc++;
    cmdn = 0;
    scriptn = 0;
    scripts = malloc(sizeof(const char*)*argc);
    cmds = malloc(sizeof(const char*)*argc);
    if(argc>1 && argv[1])
        for(i=1; i<argc; i++) {
            if(argv[i] && argv[i][0]=='-')
                switch(argv[i][1]) {
                case 'q':
                    earlyquit = 1;
                    break;
                case 'i':
                    scripts[scriptn++] = argv[++i];
                    break;
                case 'c':
                    cmds[cmdn++] = argv[++i];
                    break;
                case 'n':
                    verbose = 0;
                    break;
                case 'v':
                    puts(VERSION);
                    ret = 0;
                    break;
                case 'h':
                    ret = red_help();
                    break;
                case 0x0:
                    red_slurpin();
                    ret = 0;
                    break;
                }
            else {
                if (!argv[i]) break;
                ret = red_open(argv[i]);
            }
        }
    else ret = red_help();
    free(scripts);
    return ret;
}
Esempio n. 2
0
static void prvVerifyDemoFiles( void )
{
BaseType_t xFileNumber, xReadNumber;
char cFilePath[ 64 ];
const BaseType_t xMaxFiles = 5;
long lChar;
int32_t lBytesRead, lFildes, lStatus;
int iByte;

	/* Read back the files that were created by prvCreateDemoFiles(). */
	for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
	{
		/* Generate the file name. */
		sprintf( cFilePath, "/root%03d.txt", xFileNumber );

		/* Print out the file name and the directory from which the file is
		being read. */
		printf( "Reading file %s\r\n", cFilePath );

		/* Open the file for reading. */
		lFildes = red_open( cFilePath, RED_O_RDONLY );
		configASSERT( lFildes != -1 );

		/* Read the file into the RAM buffer, checking the file contents are as
		expected.  The size of the file depends on the file number. */
		for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ )
		{
			/* Start with the RAM buffer clear. */
			memset( cRAMBuffer, 0x00, fsRAM_BUFFER_SIZE );

			lBytesRead = red_read( lFildes, cRAMBuffer, fsRAM_BUFFER_SIZE );
			configASSERT( lBytesRead == fsRAM_BUFFER_SIZE );

			/* Check the RAM buffer is filled with the expected data.  Each
			file contains a different repeating ascii character that indicates
			the number of the file. */
			for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ )
			{
				configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) );
			}
		}

		/* Close the file. */
		lStatus = red_close( lFildes );
		configASSERT( lStatus == 0 );
	}

	/* Generate the file name. */
	sprintf( cFilePath, "%s/file.txt", pcDirectory2 );

	/* Print out the file name and the directory from which the file is being
	read. */
	printf( "Reading file %s\r\n", cFilePath );

	/* This time the file is opened for reading. */
	lFildes = red_open( cFilePath, RED_O_RDONLY );
	configASSERT( lFildes != -1 );

	/* Read the file. */
	lBytesRead = red_read( lFildes, cRAMBuffer, fsRAM_BUFFER_SIZE );
	configASSERT( lBytesRead == fsRAM_BUFFER_SIZE );

	/* Verify the file 1 byte at a time. */
	for( iByte = 0; iByte < fsRAM_BUFFER_SIZE; iByte++ )
	{
		configASSERT( cRAMBuffer[ iByte ] == ( char ) ( ( int ) '0' + iByte ) );
	}

	/* Finished so close the file. */
	lStatus = red_close( lFildes );
	configASSERT( lStatus == 0 );
}
Esempio n. 3
0
static void prvCreateDemoFiles( void )
{
BaseType_t xFileNumber, xWriteNumber;
char cFilePath[ 64 ];
const BaseType_t xMaxFiles = 5;
uint32_t ulEventMask;
int32_t lBytesWritten, lFildes, lStatus;
int iByte;

	/* Save the current transaction point settings. */
	lStatus = red_gettransmask( fsVOLUME_NAME, &ulEventMask );
	configASSERT( lStatus == 0 );

	/* Disable automatic transaction points so that all of the files can be
	created in one atomic operation. */
	lStatus = red_settransmask( fsVOLUME_NAME, RED_TRANSACT_MANUAL );
	configASSERT( lStatus == 0 );

	/* Create xMaxFiles files.  Each created file will be
	( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled
	with a different repeating character. */
	for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
	{
		/* Generate a file name. */
		sprintf( cFilePath, "/root%03d.txt", xFileNumber );

		/* Print out the file name and the directory into which the file is
		being written. */
		printf( "Creating file %s\r\n", cFilePath );

		/* Open the file, creating the file if it does not already exist. */
		lFildes = red_open( cFilePath, RED_O_CREAT|RED_O_TRUNC|RED_O_WRONLY );
		configASSERT( lFildes != -1 );

		/* Fill the RAM buffer with data that will be written to the file.  This
		is just a repeating ascii character that indicates the file number. */
		memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE );

		/* Write the RAM buffer to the opened file a number of times.  The
		number of times the RAM buffer is written to the file depends on the
		file number, so the length of each created file will be different. */
		for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ )
		{
			lBytesWritten = red_write( lFildes, cRAMBuffer, fsRAM_BUFFER_SIZE );
			configASSERT( lBytesWritten == fsRAM_BUFFER_SIZE );
		}

		/* Close the file so another file can be created. */
		lStatus = red_close( lFildes );
		configASSERT( lStatus == 0 );
	}

	/* Commit a transaction point, atomically adding the set of files to the
	transacted state. */
	lStatus = red_transact( fsVOLUME_NAME );
	configASSERT( lStatus == 0 );

	/* Create a sub directory. */
	printf( "Creating directory %s\r\n", pcDirectory1 );

	lStatus = red_mkdir( pcDirectory1 );
	configASSERT( lStatus == 0 );

	/* Create a subdirectory in the new directory. */
	printf( "Creating directory %s\r\n", pcDirectory2 );

	lStatus = red_mkdir( pcDirectory2 );
	configASSERT( lStatus == 0 );

	/* Generate the file name. */
	sprintf( cFilePath, "%s/file.txt", pcDirectory2 );

	/* Print out the file name and the directory into which the file is being
	written. */
	printf( "Writing file %s\r\n", cFilePath );

	lFildes = red_open( cFilePath, RED_O_CREAT|RED_O_TRUNC|RED_O_WRONLY );

	/* Write the file.  It is filled with incrementing ascii characters starting
	from '0'. */
	for( iByte = 0; iByte < fsRAM_BUFFER_SIZE; iByte++ )
	{
		cRAMBuffer[ iByte ] = ( char ) ( ( int ) '0' + iByte );
	}

	lBytesWritten = red_write( lFildes, cRAMBuffer, fsRAM_BUFFER_SIZE );
	configASSERT( lBytesWritten == fsRAM_BUFFER_SIZE );

	/* Finished so close the file. */
	lStatus = red_close( lFildes );
	configASSERT( lStatus == 0 );

	/* Commit a transaction point, atomically adding the set of files and
	directories to the transacted state. */
	lStatus = red_transact( fsVOLUME_NAME );
	configASSERT( lStatus == 0 );

	/* Restore previous transaction point settings. */
	lStatus = red_settransmask( fsVOLUME_NAME, ulEventMask );
	configASSERT( lStatus == 0 );
}