c++ - replace fpos_t and fpos_t._pos in different platform -


in linux(ubuntu) fpos_t in struct

typedef fpos_t {     size_t _pos,     size_t _state } 

in windows, fpos_t not defined. in code base, defined in way.

#ifndef _fpos_t_defined typedef __int64 fpos_t; #define _fpos_t_defined #endif  /* _fpos_t_defined */ 

however, in code

foo () {     fpos_t fsize;     fgetpos(fp, &fsize);    // function      bar.len = (unsigned int)fsize;                      // windows  function b           bar.body = (char *)safe_malloc( (size_t)fsize);     // windows     //bar.len = (unsigned int)fsize._pos;                   // linux function b     //bar.body = (char *)safe_malloc( (size_t)fsize._pos);// linux } 

question elegant way substitute fsize._pos fsize when compiled in different platform. method knew

#if defined(linux)     //code linux #else      //code windows #endif  

the fpos_t structure defined opaque; there no portable way extract file offset fpos_t (cast fpos_t int or char).

if want byte offset of file position, open file in binary mode , use ftello (ftello/fseeko vs fgetpos/fsetpos).


Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -