コード例 #1
0
ファイル: io.c プロジェクト: mmcx/cegcc
_ssize_t
_read_r(struct _reent *reent, int fd, void *buf, size_t count)
{
  int nread;
  int error;

  WCETRACE(WCE_IO, "read(fd = %d, count = %d, hnd %x)", fd, count, _fdtab[fd].hnd);

  if ((!__StdioInited) && (fd >= 0) && (fd <= 2))
  {
    WCETRACE(WCE_IO, "read from fd = %d with stdio uninitialized", fd);
	return count;
  }

  FDCHECK(fd, 0);

  if (_fdtab[fd].devops == NULL) {
    if (_fdtab[fd].type == IO_FILE_TYPE_FILE || _fdtab[fd].type == IO_FILE_TYPE_CONSOLE) {
      if (_ReadFile(_fdtab[fd].hnd, buf, count, (DWORD *)&nread, NULL) == FALSE) {
        WCETRACE(WCE_IO, "_ReadFile: %d", GetLastError());
        errno = EIO;
        return(-1);
      }
    } else if (_fdtab[fd].type == IO_FILE_TYPE_SOCKET) {
      if ((nread = recv(fd, buf, count, 0)) == SOCKET_ERROR) {
        /* error = WSAGetLastError(); */ 
		error = 1;
        WCETRACE(WCE_IO, "read: recv failed %d\n", error);
        if (error == WSAEWOULDBLOCK) {
          errno = EAGAIN;
          return(-1);
        }

        errno = _winerr2errno(error);
        return(-1);
      }
    } else if (_fdtab[fd].type == IO_FILE_TYPE_NULL) {
      WCETRACE(WCE_IO, "warning - read called w/IO_FILE_TYPE_NULL");
      nread = 0;
    }
  } else {
    nread = _fdtab[fd].devops->read_r(reent, _fdtab[fd].fd, buf, count, _fdtab[fd].cxt);
  }

  return(nread);
}
コード例 #2
0
ファイル: _read.c プロジェクト: b409/b409
void main(int argc,char **argv)
{
    int n = 0;
    int fd;
    char *path;
    char buf[BUFSIZ];
    if(argc != 2){
        printf("invalid argument!\n");
        exit(1);
    }
    path = argv[1];
    fd = _OpenFile(path,O_RDONLY);
    printf("readfile fd -- %d\n",fd);
    if(fd != -1){
        bzero(buf,BUFSIZ);
        n = _ReadFile(fd,buf,BUFSIZ,0);
        printf("read -- %s\n",buf);
        _CloseFile(fd);
    }
    exit(0);
}
コード例 #3
0
ファイル: Effect.cpp プロジェクト: Nicussus/3dengine
bool Effect::AddShader(SHADER_TYPE shaderType, const char *fileName)
{
	char *source = _ReadFile(fileName);
	if(source == NULL)
	{
		fprintf(stderr, "Effect::AddShader: Error parsing shader file %s\n", fileName);
		return false;
	}
	
	GLenum type = shaderType == VERTEX_SHADER? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER;
	GLuint shaderObj = glCreateShader(type);
	if(shaderObj == 0)
	{
		fprintf(stderr, "Effect::AddShader: Error creating shader object\n");
		return false;
	}

	const GLchar *textArray[1];
	textArray[0] = source;
	GLint length[1];
	length[0] = strlen(source);
	glShaderSource(shaderObj, 1, textArray, length);

	glCompileShader(shaderObj);

	GLint success;
	glGetShaderiv(shaderObj, GL_COMPILE_STATUS, &success);
	if(success == 0)
	{
		GLchar log[1024];
		glGetShaderInfoLog(shaderObj, 1024, NULL, log);
		fprintf(stderr, "Effect::AddShader: Error compiling shader type %s : '%s'\n", _Shader_type_2_string(type), log);
		return false;
	}

	free(source);
	glAttachShader(m_shaderProgram, shaderObj);
	m_shaderObjList.push_back(shaderObj);
	return true;
}
コード例 #4
0
void MainTask(void) {
  unsigned i;
  U32 Space;
  U32 NumLoops;
  U32 NumBytes;
  U32 NumBytesAtOnce;
  FS_FILE * pFile;
  I32 t;

  FS_Init();
  _TestNo = -1;
  //
  // Check if we need to low-level format the volume
  //
  if (FS_IsLLFormatted(VOLUME_NAME) == 0) {
    FS_X_Log("Low level formatting\n");
    FS_FormatLow(VOLUME_NAME);  /* Erase & Low-level  format the flash */
  }
  //
  // Volume is always high level formatted
  // before doing any performance tests.
  //
  FS_X_Log("High level formatting\n");
#if FS_SUPPORT_FAT
  if (FS_FormatSD(VOLUME_NAME) == 0) {
#else
  if (FS_Format(VOLUME_NAME, NULL) == 0) {
#endif
    //
    // Disable that the directory entry is every time
    // updated after a write operation
    //
    FS_ConfigUpdateDirOnWrite(0);
    //
    // Fill the buffer with data
    //
    FS_MEMSET((void*)_aBuffer, 'a', sizeof(_aBuffer));
    //
    // Get some general info
    //
    Space          = FS_GetVolumeFreeSpace(VOLUME_NAME);
    Space          = MIN(Space, FILE_SIZE);
    NumBytes       = BLOCK_SIZE * NUM_BLOCKS_MEASURE;
    NumBytesAtOnce = BLOCK_SIZE;
    NumLoops       = Space / NumBytes;

    //
    // Create file of full size
    //
    _StartTest("W", NumBytes);
    pFile = FS_FOpen(FILE_NAME, "w");
    //
    // Preallocate the file, setting the file pointer to the highest position
    // and declare it as the end of the file.
    //
    FS_SetFilePos(pFile, Space, FS_FILE_BEGIN);
    FS_SetEndOfFile(pFile);
    //
    // Set file position to the beginning
    //
    FS_SetFilePos(pFile, 0, FS_FILE_BEGIN);
    //
    // Check write performance with clusters/file size preallocated
    //
    sprintf(_ac, "Writing %lu chunks of %lu Bytes: ", NumLoops, NumBytes);
    FS_X_Log(_ac);
    for (i = 0; i < NumLoops ; i++) {
      t = _WriteFile(pFile, &_aBuffer[0], NumBytesAtOnce);
      _StoreResult(t);
      FS_X_Log(".");
    }
    FS_X_Log("OK\n");
    FS_FClose(pFile);
    //
    // Check read performance
    //
    _StartTest("R", NumBytes);
    sprintf(_ac, "Reading %lu chunks of %lu Bytes: " , NumLoops, NumBytes);
    FS_X_Log(_ac);
    pFile = FS_FOpen(FILE_NAME, "r");
    for (i = 0; i < NumLoops; i++) {
      t = _ReadFile(pFile, _aBuffer, NumBytesAtOnce);
      _StoreResult(t);
      FS_X_Log(".");
    }
    FS_X_Log("OK\n\n");
    FS_FClose(pFile);
    //
    // Show results for performance list
    //
    for (i = 0; i <= (unsigned)_TestNo; i++) {
      sprintf(_ac, "%s Speed: %f kByte/s\n", _aResult[i].sName, _GetAverage(i));
      FS_X_Log(_ac);
    }
    FS_X_Log("Finished\n");
    FS_Unmount(VOLUME_NAME);
  } else {
    FS_X_Log("Volume could not be formatted!\n");
  }
  while (1) {
    ;
  }
}
コード例 #5
0
int CGenerateSQLFile::_GeneralSQLFiles()
{
	int nFunRes = 0;

	nFunRes = _RemoveOldSQLFiles();
	if (0 != nFunRes)
	{
		_SysLog(SourceFLInfo, DebugError, "error! remove OldSQLFiles: %s %s",
				m_strDirSqlH.c_str(), m_strDirSqlMacrodefH.c_str());
		nFunRes = -1;
		return nFunRes;
	}

	//read file
	nFunRes =  _ReadFile(m_strDirSqlCodeTxt, m_vrtDataInFile);
	if (0 != nFunRes)
	{
		_SysLog(SourceFLInfo, DebugError, "error! _ReadAllLineFromFile()");
		nFunRes = -1;
		return nFunRes;
	}

	//check file data
	nFunRes =  _CheckLine(m_vrtDataInFile);
	if (0 != nFunRes)
	{
		_SysLog(SourceFLInfo, DebugError, "error! _CheckLine()");
		nFunRes = -1;
		return nFunRes;
	}
	
	//process data
	nFunRes =  _MutiLinesToSingleLine(m_vrtDataInFile);
	nFunRes =  _RemoveBlackLine(m_vrtDataInFile);
	
	//m_strDirSqlCodeTxt
	nFunRes = m_pSQLCodeInfo->setFileName(m_strDirSqlCodeTxt);	
	nFunRes =  m_pSQLCodeInfo->analyzeData(m_vrtDataInFile);
	if (0 != nFunRes)
	{
		_SysLog(SourceFLInfo, DebugError, "error! CSQLCodeInfo analyzeData()");
		nFunRes = -1;
		return nFunRes;
	}
	
	//check Oracle and Mysql sql Num
	nFunRes = m_pSQLCodeInfo->checkOracleAndMysqlSqlNum();
	if (0 != nFunRes)
	{
		_SysLog(SourceFLInfo, DebugError, "error! checkOracleAndMysqlSqlNum()");
		nFunRes = -1;
		return nFunRes;
	}

	nFunRes = m_pSQLCodeInfo->analyzeDataToFiles();
	if (0 != nFunRes)
	{
		_SysLog(SourceFLInfo, DebugError, "error! analyzeDataToFiles()");
		nFunRes = -1;
		return nFunRes;
	} 

	//write data to sql.h sqlmacrodef.h
	nFunRes = _WriteDataToFiles();

	//clear data
	if (NULL != m_pSQLCodeInfo)
	{
		delete m_pSQLCodeInfo;
		m_pSQLCodeInfo = NULL;
	}
	m_vrtDataInFile.clear();

	//remove file ErrorReport.log
	if (0 == nFunRes)
	{
		CLogger::getInstance().deletelogFile();
	}

	return nFunRes;	 
}