Ejemplo n.º 1
0
size_t getfsize(const std::string & filename){
    std::fstream file(filename.c_str(),std::ios::in);
    if (file.bad())
        return 0;
    size_t ret = getfsize(file);
    file.close();
    return ret;
}
Ejemplo n.º 2
0
int loadfile(const std::string&filename, std::string& str){
    std::fstream file(filename.c_str(),std::ios::in|std::ios::binary);
    if (file.is_open()){
        int sz = getfsize(file);
        str.resize(sz);
        file.read(&str[0],sz);
        file.close();
        return 1;
    }
    return 0;
}
Ejemplo n.º 3
0
int loadfile(const std::string& filename, std::vector<unsigned char>& vec){
    std::fstream file(filename.c_str(),std::ios::in|std::ios::binary);
    if (file.is_open()){
        int sz = getfsize(file);
        vec.resize(sz);
        file.read((char*)&vec[0],sz);
        file.close();
        return 1;
    }
    return 0;
}
Ejemplo n.º 4
0
Archivo: sar.c Proyecto: mpolitzer/sar
int sar_create(const char *fout, int argc, const char *argv[])
{
	int i;
	FILE *in, *out;
	struct sar_header header;
	struct sar_entry entry;

	assert(out = fopen(fout, "wb"));

	/* copy header */
	memset(&header, 0, sizeof(header));
	header.n = argc;
	strncpy(header.sar, "SAR", 4);
	assert(fwrite(&header, sizeof(header), 1, out) == 1);

	/* copy files */
	for (i=0; i<argc; i++) {
		assert(in = fopen(argv[i], "rb"));
		docpy(in, out, getfsize(in));
		assert(!fclose(in));
	}

	/* make index & md5 */
	for (i=0, entry.beg = sizeof(header);
			i < argc;
			i++, entry.beg += entry.size) {
		strncpy(entry.fname, argv[i], sizeof(entry.fname));

		assert(in = fopen(argv[i], "rb"));
		entry.size = getfsize(in);
		domd5(entry.md5, in, entry.size);
		assert(!fclose(in)); 

		assert(fwrite(&entry, sizeof(entry), 1, out) == 1);
	}
	assert(!fclose(out));
	return 0;
}
Ejemplo n.º 5
0
std::string readfilepart(const std::string& filename, long pos, long size){
    std::fstream file(filename.c_str(),std::ios::in|std::ios::binary);
    long dif = getfsize(filename) - pos;

    if (dif<0)
        return "";
    if (dif<size)
        size=dif;

    file.seekg(pos);
    file.seekp(pos);
    std::string buff;buff.resize(size);
    file.read(&buff[0],size);
    file.close();
    return buff;
}