10 int main(int argc, char **argv)
20 printf("\nfilename: ");
21 x = fgets(buf,19,stdin);
32 file = fopen(filename,"rb");
34 fprintf(stderr,"cannot open %s: %s\n",filename,strerror(errno));
38 if (fread(buf, 10, 1, file) != 1) {
39 fprintf(stderr,"short read, aborted\n");
46 fprintf(stderr,"ftell returned -1: %s\n", strerror(errno));
51 printf("reading 10 bytes from file\n");
52 printf("current file pos: %ld\n", pos);
54 printf("get file size (lseek): ");
55 fd = *(char *)file; /* kids, don't do this at home */
56 fsz = lseek(fd, 0, SEEK_END);
58 fprintf(stderr,"lseek returned -1: %s\n", strerror(errno));
62 printf("%ld (fd = %d)\n", (long)fsz, fd);
64 printf("get file size (fseek): ");
65 pos = fseek(file, 0, SEEK_END);
67 fprintf(stderr,"fseek returned -1: %s\n", strerror(errno));
74 fprintf(stderr,"ftell returned -1: %s\n", strerror(errno));
80 printf("positioning at offset 100: ");
81 pos = fseek(file, 100, SEEK_SET);
83 fprintf(stderr,"fseek returned -1: %s\n", strerror(errno));
89 fprintf(stderr,"ftell returned -1: %s\n", strerror(errno));
97 printf("failed! cur pos = %ld\n",pos);
102 printf("seeking back 44 bytes: ");
103 pos = fseek(file, -44, SEEK_CUR);
105 fprintf(stderr,"fseek returned -1: %s\n", strerror(errno));
111 fprintf(stderr,"ftell returned -1: %s\n", strerror(errno));
119 printf("failed! cur pos = %ld\n",pos);
124 printf("seeking forward 111 bytes: ");
125 pos = fseek(file, 111, SEEK_CUR);
127 fprintf(stderr,"fseek returned -1: %s\n", strerror(errno));
133 fprintf(stderr,"ftell returned -1: %s\n", strerror(errno));
141 printf("failed! cur pos = %ld\n",pos);
146 printf("seeking 13 bytes before eof: ");
147 pos = fseek(file, -13, SEEK_END);
149 fprintf(stderr,"fseek returned -1: %s\n", strerror(errno));
155 fprintf(stderr,"ftell returned -1: %s\n", strerror(errno));
159 if (pos == fsz - 13) {
163 printf("failed! cur pos = %ld\n",pos);
168 printf("seeking before sof:\n\t");
169 pos = fseek(file, -fsz, SEEK_CUR);
171 printf("Ok, error %s\n", strerror(errno));
174 printf("NOT OK, no error\n");