github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/webp/libwebp/test/test_util.cc (about)

     1  // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "test_util.h"
     6  
     7  #include <stdio.h>
     8  
     9  bool LoadFileData(const char* name, std::string* data) {
    10  	FILE* fp = fopen(name, "rb");
    11  	if(!fp) return false;
    12  
    13  	fseek(fp, 0, SEEK_END);
    14  	data->resize(ftell(fp));
    15  
    16  	rewind(fp);
    17  	int n = fread((void*)data->data(), 1, data->size(), fp);
    18  	fclose(fp);
    19  	return (n == data->size());
    20  }
    21  
    22  bool SaveFileData(const char* name, const char* data, int size) {
    23  	FILE* fp = fopen(name, "wb");
    24  	if(!fp) return false;
    25  	int n = fwrite((void*)data, 1, size, fp);
    26  	fclose(fp);
    27  	return (n == size);
    28  }
    29