Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)
Example 2 Sample Portable fseek() and ftell() Conversion Code Fragment
/** begin code fragment **/
movepos(fd)
FILE *fd;
{
 int rslt;
/** If ((TNS/R and G06.29 or later) or **/
/** (TNS/E and H06.06 or later)) and **/
/** this is a transitional compilation environment, **/
#if (_TANDEM_ARCH_ == 1 && __G_Series_RVU >= 629 || \
 _TANDEM_ARCH_ == 2 && __H_Series_RVU >= 606) && \
 (_LARGEFILE64_SOURCE == 1)
#define ftell ftello
#define fseek fseeko
#ifdef _FILE_OFFSET_BITS == 64
#define offset_format “%lld”
#else /** _FILE_OFFSET_BITS == 32 **/
#define offset_format “%d”
#endif
 off_t offset;
 off_t offset-num;
#else
#define offset_format “%d”
 long int offset;
 long int offset-num;
#endif
 offset = ftell(fd);
 if(offset != -1)
 {
 offset-num = offset/2;
 rslt = fseek(fd,num,SEEK_CUR);
 if(!rslt)
 printf(“New Position “offset_format“\n”,offset-num);
 else
 printf(“Error!\n”);
 }
} 
/** end code fragment **/
Example Conversion
Original Example Program
Example 3 (page 195) contains the original example program. This program works correctly as
long as the file is a small file. However, if the file is a large file, the stat() function call fails and
the program returns -1.
194 Porting Applications to Support Large OSS Files










