mfile mill_mferr(void) { static struct mill_file f = {-1, 0, 0, 0}; if(mill_slow(f.fd < 0)) { mill_filetune(STDERR_FILENO); f.fd = STDERR_FILENO; } return &f; }
mfile fileattach(int fd) { struct mill_file *f = malloc(sizeof(struct mill_file)); if(!f) { errno = ENOMEM; return NULL; } mill_filetune(fd); f->fd = fd; f->ifirst = 0; f->ilen = 0; f->olen = 0; errno = 0; return f; }
mfile mfopen(const char *pathname, int flags, mode_t mode) { /* Open the file. */ int fd = open(pathname, flags, mode); if (fd == -1) return NULL; mill_filetune(fd); /* Create the object. */ struct mill_file *f = malloc(sizeof(struct mill_file)); if(!f) { fdclean(fd); close(fd); errno = ENOMEM; return NULL; } f->fd = fd; f->ifirst = 0; f->ilen = 0; f->olen = 0; errno = 0; return f; }