Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)
Example 3 Program Before Converting to Support Large Files
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
print_byte(name,offset)
char *name;
int offset;
{
int fd;
int 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 %d\n”,ret);
}
save(name)
char *name;
{
struct stat statb;
int 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);
}
Program Converted for Transitional Compilation Environment
In this example, the stat(), open() and lseek() calls have been changed to the corresponding
64-bit calls. The statb structure has been changed to a struct stat64 structure, which is like
a struct stat structure, except that some fields are larger. For example, because st_size is
larger, it must be assigned to a variable of type off64_t, so the declarations of x and offset
must be changed. This program supports large files as long as it is compiled in the transitional
compilation environment.
Example Conversion 195