|
|
1.1 ! root 1: /* cclose.c 1.10 83/05/13 */ ! 2: #include <stdio.h> ! 3: #include "cpmio.h" ! 4: #include "cpmfio.h" ! 5: ! 6: /* ! 7: * Close cp/m file ! 8: * If the file was opened for write, flush ! 9: * buffer to disk and update directory ! 10: */ ! 11: ! 12: c_close(fptr) ! 13: register C_FILE *fptr; ! 14: { ! 15: int scts = 0; ! 16: ! 17: #ifdef DEBUG ! 18: printf("c_close: cnt: %d\n", fptr->c_cnt); ! 19: #endif ! 20: if (fptr->c_flag & WRITE) { ! 21: scts = (blksiz - fptr->c_cnt)/seclth + 1; ! 22: if (fptr->c_cnt%seclth == 0) ! 23: scts--; ! 24: fptr->c_dirp->blkcnt = scts + fptr->c_seccnt; ! 25: if (fptr->c_cnt < blksiz) { ! 26: /* ! 27: * zero fill to end, and flush ! 28: * the block to disk ! 29: */ ! 30: if ((fptr->c_flag&BINARY) == 0) { ! 31: /* ! 32: * add cp/m eof mark (ctrl-z) if the file ! 33: * is not a binary file ! 34: */ ! 35: *(fptr->c_buf++) = '\032'; ! 36: fptr->c_cnt--; ! 37: } ! 38: while (fptr->c_cnt-- > 0) ! 39: *(fptr->c_buf++) = '\0'; ! 40: } ! 41: if (putblock(0xff&(int)fptr->c_dirp->pointers[fptr->c_blk], ! 42: fptr->c_base, scts) == EOF) ! 43: return (EOF); ! 44: } ! 45: savedir(); ! 46: ! 47: /* deallocate buffer memory and file descriptor */ ! 48: fptr->c_flag = 0; ! 49: free(fptr->c_base); ! 50: return (NULL); ! 51: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.