Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)

option instead of in the source code. The source has no assumptions about whether off_t is larger
or smaller than an int.
Example 5 Program Converted For a Large File Compilation Environment
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#define _FILE_OFFSET_BITS 64
/** You can specify this macro as a comiler option **/
/** instead of including it in the source code. **/
print_byte(name,offset)
char *name;
off_t offset;
{
int fd;
off_t ret;
if((fd = open(name,O_RDONLY)) == -1) {
printf(Open Failed\n);
return(-2);
}
if((ret=lseek(fd, offset, SEEK_SET)) == -1) {
printf(lseek failed\n);
return(-3);
}
/** Print ret **/
printf(lseek returned %lld\n,ret);
}
save(name)
char *name;
{
struct stat statb;
off_t x;
if(stat(name,&statb) == -1) {
printf(Stat Failed\n);
return(-1);
}
x = statb.st_size/2;
print_byte(name,x);
}
main()
{
char *name=Fred;
save(name);
}
Example Conversion 197