- fp = fopen(tempfilename, "w");
- if (fp == NULL) {
- cprintf("%d Cannot open %s: %s\n",
+ memset(&StatBuf, 0, sizeof(struct stat));
+ if (stat(filename, &StatBuf) == -1)
+ StatBuf.st_size = 80; /* Not there? guess 80 chars line. */
+
+ sprintf(tempfilename + len, ".%d", CC->cs_pid);
+
+ TmpFD = open(tempfilename, O_CREAT|O_EXCL);
+
+ if (TmpFD > 0)
+ {
+ char *tmp = malloc(StatBuf.st_size * 2);
+ memset(tmp, 0, StatBuf.st_size * 2);
+ rc = write(TmpFD, tmp, StatBuf.st_size * 2);
+ free(tmp);
+ if (rc <= 0)
+ {
+ close(TmpFD);
+ cprintf("%d Unable to allocate the space required for %s: %s\n",
+ ERROR + INTERNAL_ERROR,
+ tempfilename,
+ strerror(errno));
+ return;
+ }
+ lseek(TmpFD, SEEK_SET, 0);
+ }
+ else {
+ cprintf("%d Unable to allocate the space required for %s: %s\n",