void *gt_Sfxmappedrange_map_entire(GtSfxmappedrange *sfxmappedrange, GtError *err) { size_t mappedsize; gt_assert(sfxmappedrange != NULL); sfxmappedrange->entire = gt_fa_mmap_read(gt_str_get(sfxmappedrange->filename), &mappedsize,err); if (sfxmappedrange->entire == NULL) { return NULL; } if (mappedsize != gt_Sfxmappedrange_size_entire(sfxmappedrange)) { gt_error_set(err, "map file %s: mapped size = "GT_WU" != " GT_WU" = expected size", gt_str_get(sfxmappedrange->filename), (GtUword) mappedsize, (GtUword) gt_Sfxmappedrange_size_entire(sfxmappedrange)); gt_fa_xmunmap(sfxmappedrange->entire); sfxmappedrange->entire = NULL; return NULL; } gt_log_log("map %s completely ("GT_WU" units of size %u)", gt_str_get(sfxmappedrange->tablename), (GtUword) sfxmappedrange->numofunits, (unsigned int) sfxmappedrange->sizeofunit); return sfxmappedrange->entire; }
void gt_runcheckfunctionontwofiles(Checkcmppairfuntype checkfunction, const char *file1, const char *file2) { const GtUchar *useq = NULL, *vseq = NULL; size_t ulen, vlen; bool forward = true; GtError *err; err = gt_error_new(); useq = (const GtUchar *) gt_fa_mmap_read(file1,&ulen,err); if (useq == NULL) { fprintf(stderr, "error: %s\n", gt_error_get(err)); exit(GT_EXIT_PROGRAMMING_ERROR); } vseq = (const GtUchar *) gt_fa_mmap_read(file2,&vlen,err); if (vseq == NULL) { fprintf(stderr, "error: %s\n", gt_error_get(err)); exit(GT_EXIT_PROGRAMMING_ERROR); } gt_error_delete(err); while (true) { checkfunction(forward,useq,(GtUword) ulen, vseq,(GtUword) vlen); if (!forward) { break; } forward = false; } gt_fa_xmunmap((void *) useq); gt_fa_xmunmap((void *) vseq); }
void *genericmaponlytable(const GtStr *indexname,const char *suffix, size_t *numofbytes,GtError *err) { GtStr *tmpfilename; void *ptr; bool haserr = false; gt_error_check(err); tmpfilename = gt_str_clone(indexname); gt_str_append_cstr(tmpfilename,suffix); ptr = gt_fa_mmap_read(gt_str_get(tmpfilename),numofbytes); if (ptr == NULL) { gt_error_set(err,"cannot map file \"%s\": %s",gt_str_get(tmpfilename), strerror(errno)); haserr = true; } gt_str_delete(tmpfilename); return haserr ? NULL : ptr; }
int gt_mapspec_read(GtMapspecSetupFunc setup, void *data, const char *filename, GtUword expectedsize, void **mapped, GtError *err) { void *mapptr; uint64_t expectedaccordingtomapspec; GtUword byteoffset = 0; size_t numofbytes; GtMapspec *ms = gt_malloc(sizeof (GtMapspec)); GtMapspecification *mapspecptr; int had_err = 0; GtUword totalpadunits = 0; gt_error_check(err); GT_INITARRAY(&ms->mapspectable, GtMapspecification); setup(ms, data, false); mapptr = gt_fa_mmap_read(filename, &numofbytes, err); if (mapptr == NULL) { had_err = -1; } *mapped = mapptr; if (!had_err) { if (assigncorrecttype(ms->mapspectable.spaceGtMapspecification, mapptr,0,err) != 0) { had_err = -1; } } if (!had_err) { expectedaccordingtomapspec = detexpectedaccordingtomapspec(&ms->mapspectable); if (expectedaccordingtomapspec != (uint64_t) numofbytes) { gt_error_set(err, GT_WU " bytes read from %s, but " Formatuint64_t " expected", (GtUword) numofbytes, filename, PRINTuint64_tcast(expectedaccordingtomapspec)); had_err = -1; } } if (!had_err) { mapspecptr = ms->mapspectable.spaceGtMapspecification; gt_assert(mapspecptr != NULL); byteoffset = CALLCASTFUNC(uint64_t,unsigned_long, (uint64_t) (mapspecptr->sizeofunit * mapspecptr->numofunits)); if (byteoffset % (GtUword) GT_WORDSIZE_INBYTES > 0) { size_t padunits = GT_WORDSIZE_INBYTES - (byteoffset % GT_WORDSIZE_INBYTES); byteoffset += (GtUword) padunits; totalpadunits += (GtUword) padunits; } for (mapspecptr++; mapspecptr < ms->mapspectable.spaceGtMapspecification + ms->mapspectable.nextfreeGtMapspecification; mapspecptr++) { if (assigncorrecttype(mapspecptr,mapptr,byteoffset,err) != 0) { had_err = -1; break; } byteoffset = CALLCASTFUNC(uint64_t,unsigned_long, (uint64_t) (byteoffset + mapspecptr->sizeofunit * mapspecptr->numofunits)); if (byteoffset % (GtUword) GT_WORDSIZE_INBYTES > 0) { size_t padunits = GT_WORDSIZE_INBYTES - (byteoffset % GT_WORDSIZE_INBYTES); byteoffset += (GtUword) padunits; totalpadunits += (GtUword) padunits; } } } if (!had_err) { if (expectedsize + totalpadunits != byteoffset) { gt_error_set(err,"mapping: expected file size is "GT_WU" bytes, " "but file has "GT_WU" bytes", expectedsize,byteoffset); had_err = -1; } } GT_FREEARRAY(&ms->mapspectable,GtMapspecification); gt_free(ms); return had_err; }