OSLAB2
OSLAB2
INPUT:
#include<stdio.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h>
extern int errno;
int main()
{
int buf[1000];
int fd = open("read.txt",O_RDONLY|O_CREAT);
printf("file descriptor(open):%d\n",fd);
if(fd==-1){
perror("error opening file");
}
int fd1=read(3,buf,sizeof(buf));
printf("file descriptor(read):%d",fd1);
if(fd1<0)
{
perror("error reading file");
}
close(fd);}
OUTPUT:
#include<stdio.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h>
int main(){
int fd,fd1;
fd=open("lseek.txt",O_RDONLY|O_CREAT);
if(fd == -1){
perror("error openin file");
return 1;
}
fd1=lseek(fd,100,SEEK_SET);
printf(" file descrptor=%d",fd1);
if(fd1==-1){
perror("error seeking in file");
close(fd);
return 1;
}
close(fd);
return 0;
}
OUTPUT: