Example #1
0
void GetHighScoreDeleteForm::generateResponse(Poco::Net::HTTPServerRequest& inRequest, Poco::Net::HTTPServerResponse& outResponse)
{
    std::string body;
    ReadEntireFile("html/delete.html", body);
    outResponse.setContentLength(body.size());
    outResponse.send() << body;
}
static int ReadEntireFileSafely( char *filename , char *mode , char **pbuf , long *pbufsize )
{
	long	filesize ;
	
	int	nret ;
	
	filesize = _GetFileSize( filename );
	
	(*pbuf) = (char*)malloc( filesize + 1 ) ;
	if( (*pbuf) == NULL )
		return -1;
	memset( (*pbuf) , 0x00 , filesize + 1 );
	
	nret = ReadEntireFile( filename , mode , (*pbuf) , & filesize ) ;
	if( nret )
	{
		free( (*pbuf) );
		(*pbuf) = NULL ;
		return nret;
	}
	else
	{
		if( pbufsize )
			(*pbufsize) = filesize ;
		return 0;
	}
}
void FileSystemExperiment::ReadEntireFile(const std::wstring& path, uint32_t startPosition)
{
	// open file
	HANDLE hFile = (HANDLE) FileSystemExperiment::OpenFileNoBuffering(path.c_str());
	assert(hFile != INVALID_HANDLE_VALUE);

	// read
	StopwatchStack stopwatchDummy;
	ReadEntireFile(hFile, DefaultBufferSize, stopwatchDummy, 0, startPosition);

	// close
	FileSystemExperiment::CloseFile(hFile);
}
Example #4
0
  std::string GetCapturedString() {
    if (uncaptured_fd_ != -1) {
      // Restores the original stream.
      fflush(NULL);
      dup2(uncaptured_fd_, fd_);
      close(uncaptured_fd_);
      uncaptured_fd_ = -1;
    }

    FILE* const file = posix::FOpen(filename_.c_str(), "r");
    const std::string content = ReadEntireFile(file);
    posix::FClose(file);
    return content;
  }
Example #5
0
static inline
int ParseFile(char* Filename, GLArbToken* ArbHash,
               GLToken* FunctionsHash, unsigned int* FunctionCount,
               GLToken* DefinesHash, unsigned int* DefinesCount,
               GLSettings* Settings)
{
  char* Data = ReadEntireFile(Filename);
  int Success = 0;
  if (Data)
  {
    GLTokenizer Tokenizer;
    Tokenizer.At = Data;
    while(*Tokenizer.At)
    {
      GLToken Token = ParseToken(&Tokenizer);
      if (StartsWith(Token.Value, "gl") && IsUpperCase(Token.Value.Chars[2]))
      {
        if (!Contains(FunctionsHash, Token) && IsKnownOrIgnoredToken(ArbHash, &Token, Settings))
        {
          AddToken(FunctionsHash, Token);
          *FunctionCount += 1;
        }
      }
      if (StartsWith(Token.Value, "GL_"))
      {
        if (!Contains(DefinesHash, Token) && IsKnownOrIgnoredToken(ArbHash, &Token, Settings))
        {
          AddToken(DefinesHash, Token);
          *DefinesCount += 1;
        }
      }
    }
    free(Data);
    Success = 1;
  }
  else
  {
    fprintf(stderr, "Couldn't open file %s", Filename);
  }
  return Success;
}
internal loaded_bitmap
LoadBMP(char *FileName)
{
    loaded_bitmap Result = {};
    
    entire_file ReadResult = ReadEntireFile(FileName);
    if(ReadResult.ContentsSize != 0)
    {
        Result.Free = ReadResult.Contents;
        
        bitmap_header *Header = (bitmap_header *)ReadResult.Contents;
        uint32 *Pixels = (uint32 *)((uint8 *)ReadResult.Contents + Header->BitmapOffset);
        Result.Memory = Pixels;
        Result.Width = Header->Width;
        Result.Height = Header->Height;
        
        Assert(Result.Height >= 0);
        Assert(Header->Compression == 3);

        // NOTE(casey): If you are using this generically for some reason,
        // please remember that BMP files CAN GO IN EITHER DIRECTION and
        // the height will be negative for top-down.
        // (Also, there can be compression, etc., etc... DON'T think this
        // is complete BMP loading code because it isn't!!)

        // NOTE(casey): Byte order in memory is determined by the Header itself,
        // so we have to read out the masks and convert the pixels ourselves.
        uint32 RedMask = Header->RedMask;
        uint32 GreenMask = Header->GreenMask;
        uint32 BlueMask = Header->BlueMask;
        uint32 AlphaMask = ~(RedMask | GreenMask | BlueMask);        
        
        bit_scan_result RedScan = FindLeastSignificantSetBit(RedMask);
        bit_scan_result GreenScan = FindLeastSignificantSetBit(GreenMask);
        bit_scan_result BlueScan = FindLeastSignificantSetBit(BlueMask);
        bit_scan_result AlphaScan = FindLeastSignificantSetBit(AlphaMask);
        
        Assert(RedScan.Found);
        Assert(GreenScan.Found);
        Assert(BlueScan.Found);
        Assert(AlphaScan.Found);

        int32 RedShiftDown = (int32)RedScan.Index;
        int32 GreenShiftDown = (int32)GreenScan.Index;
        int32 BlueShiftDown = (int32)BlueScan.Index;
        int32 AlphaShiftDown = (int32)AlphaScan.Index;
        
        uint32 *SourceDest = Pixels;
        for(int32 Y = 0;
            Y < Header->Height;
            ++Y)
        {
            for(int32 X = 0;
                X < Header->Width;
                ++X)
            {
                uint32 C = *SourceDest;

                v4 Texel = {(real32)((C & RedMask) >> RedShiftDown),
                            (real32)((C & GreenMask) >> GreenShiftDown),
                            (real32)((C & BlueMask) >> BlueShiftDown),
                            (real32)((C & AlphaMask) >> AlphaShiftDown)};

                Texel = SRGB255ToLinear1(Texel);
#if 1
                Texel.rgb *= Texel.a;
#endif
                Texel = Linear1ToSRGB255(Texel);
                
                *SourceDest++ = (((uint32)(Texel.a + 0.5f) << 24) |
                                 ((uint32)(Texel.r + 0.5f) << 16) |
                                 ((uint32)(Texel.g + 0.5f) << 8) |
                                 ((uint32)(Texel.b + 0.5f) << 0));
            }
        }
    }
Example #7
0
B32 CopyFile(std::string src, std::string dest, B32 ignoreFailure) {
    File srcFile = ReadEntireFile(src, ignoreFailure);
    return WriteEntireFile(dest, srcFile.size, srcFile.data, ignoreFailure);
}