Esempio n. 1
0
/*==========================
 * closebtree -- Close BTREE
 *========================*/
BOOLEAN
closebtree (BTREE btree)
{
	FILE *fk=NULL;
	KEYFILE1 kfile1;
	BOOLEAN result=FALSE;
	if (btree && ((fk = bkfp(btree)) != NULL) && !bimmut(btree)) {
		kfile1 = btree->b_kfile;
		if (kfile1.k_ostat <= 0) {
			/* writer-locked, should be -1 because we don't
			cater for multiple writers */
			kfile1.k_ostat = 0;
		} else { /* read-only, get current shared status */
			rewind(fk);
			if (fread(&kfile1, sizeof(kfile1), 1, fk) != 1) {
				/* *lldberr = BTERR_KFILE */
				/* closebtree does not report specific errors */
				goto exit_closebtree;
			}
			if (kfile1.k_ostat <= 0) {
				/* probably someone has forcibly opened it for write,
				making this -1, and may also have since closed it, leaving
				it at 0 */
				result=TRUE;
				goto exit_closebtree;
			}
			kfile1.k_ostat--;
		}
		rewind(fk);
		if (fwrite(&kfile1, sizeof(kfile1), 1, fk) != 1) {
			/* *lldberr = BTERR_KFILE */
			/* closebtree does not report specific errors */
			goto exit_closebtree;
		}
		if (fclose(fk) != 0) {
			fk = NULL;
			/* *lldberr = BTERR_KFILE; */
			goto exit_closebtree;
		}
		fk = NULL;

		result=TRUE;
	} else {
		result=TRUE;
	}
exit_closebtree:
	if (fk) fclose(fk);
	if (btree) {
		freecache(btree);
		if(bmaster(btree)) {
			stdfree(bmaster(btree));
		}
		stdfree(btree);
	}
	return result;
}
Esempio n. 2
0
int libsieve_message2_free(sieve2_message_t **m)
{
    int res;

    if (m) 
        res = freecache(*m);

    *m = NULL;

    return res;
}