00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <unistd.h> 00004 #include <signal.h> 00005 #include <fcntl.h> 00006 #include <sys/types.h> 00007 #include <sys/stat.h> 00008 #include <fcntl.h> 00009 00010 char buffer[8192]; 00011 00012 int main(int argc, char **argv) 00013 { 00014 int i, j; 00015 int count; 00016 int fd; 00017 char c = 'P'; 00018 int zapsat; 00019 00020 int count; 00021 00022 if (argc == 0) { 00023 fprintf(stderr, "Usage lseek <filename>\n"); 00024 return 1; 00025 } 00026 00027 if (argc == 2) { 00028 count = atoi(argv[2]); 00029 } 00030 00031 00032 for (i=0;i< 8192; i++){ 00033 buffer[i] = c; 00034 } 00035 fd = open(argv[1],O_RDWR| O_CREAT | O_APPEND ); 00036 if (fd<=0) { 00037 printf("Opening file %s failed.Error nr. = '%d'\n",argv[1] , fd); 00038 return fd; 00039 } 00040 00041 printf("Soubor otevren :)\n"); 00042 00043 ftruncate(fd, count); 00044 00045 lseek(fd,4090,SEEK_CUR); 00046 00047 zapsat = 20; 00048 00049 while (zapsat) { 00050 count = write(fd,buffer,zapsat); 00051 printf("count = '%d'\n", count); 00052 zapsat -= count; 00053 } 00054 00055 00056 00057 00058 close(fd); 00059 return 0; 00060 }