#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
+#include <errno.h>
#define MAX_READ 1024
-#define MAX_FILENAME 256
+#define MAX_FILENAME 30
int main (int argc,char **argv)
{
- int file_fd; /* desc fir file */
- char buf[MAX_READ]; /* buffer for the actual info */
+ int file_fd,n_exit,count;
+ char buf;
char filename[MAX_FILENAME];
- strcpy(argv[1],filename);
+ strcpy(filename,argv[1]);
+ printf("test: %s\n",filename);
if((file_fd=open(filename,O_RDONLY))<=0) {
puts("open failed");
return -23;
}
- if((read(file_fd,&buf,MAX_READ))<=MAX_READ) {
- puts("read failed");
+ if((lseek(file_fd,atoi(argv[2])-MAX_READ,SEEK_SET))<0) {
+ perror("lseek");
return -23;
}
- printf(" -> %s",buf);
+ count=1;
+ n_exit=1;
+ while(n_exit) {
+ n_exit=read(file_fd,&buf,1);
+ count++;
+ putchar(buf);
+ if(count==MAX_READ) break;
+ }
+
+ close(file_fd);
puts("");
puts("done");