예제 #1
0
파일: transfile.c 프로젝트: B-Rich/smart
/* Write entry to transaction file. */
int notifier_write_transaction_file(NotifierEntry entry)
{
	FILE *file, *l_file;
	int res = -1;

	struct stat stat_buf;

	/* Check for failed ldif, if exists don't write the transaction file,
	 * otherwise the notifier notifiies the other listeners and nothing changed
	 * in our local LDAP.
	 */
	if (stat(failed_ldif_file, &stat_buf) != 0) {
		if ((file = fopen_lock(transaction_file, "a+", &l_file)) == NULL) {
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Could not open %s\n", transaction_file);
			return res;
		}

		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "write to transaction file dn=[%s], command=[%c]", entry.dn, entry.command);
		fprintf(file, "%ld %s %c\n", entry.id, entry.dn, entry.command);
		res = fclose_lock(&file, &l_file);
	} else {
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Could not write to transaction file %s. Check for %s\n", transaction_file, failed_ldif_file);
	}

	return res;
}
예제 #2
0
파일: fz.c 프로젝트: kyroskoh/advancecomp
/**
 * Open a normal file doing all the write access in memory.
 * The semantic is like the C fopen() function.
 */
adv_fz* fzopennullwrite(const char* file, const char* mode)
{
	adv_fz* f = fzalloc();
	if (!f)
		goto err;

	f->type = fz_memory_write;
	f->virtual_pos = 0;
	f->f = fopen_lock(file, "rb");
	if (f->f) {
		struct stat st;

		if (fstat(fileno(f->f), &st) != 0) {
			goto err_close;
		}

		f->data_write = malloc(st.st_size);
		if (!f->data_write) {
			goto err_close;
		}

		f->virtual_size = st.st_size;

		if (fread_lock(f->data_write, st.st_size, 1, f->f) != 1) {
			goto err_data;
		}

		fclose_lock(f->f);
		f->f = 0;
	} else {
		if (strchr(mode, 'w')!=0 || strchr(mode, 'a')!=0) {
			/* creation allowed */
			f->data_write = 0;
			f->virtual_size = 0;
		} else {
			/* creation not possible */
			goto err_free;
		}
	}

	return f;

err_data:
	free(f->data_write);
err_close:
	fclose_lock(f->f);
err_free:
	free(f);
err:
	return 0;
}
예제 #3
0
파일: fz.c 프로젝트: kyroskoh/advancecomp
/**
 * Open a normal file.
 * The semantic is like the C fopen() function.
 */
adv_fz* fzopen(const char* file, const char* mode)
{
	adv_fz* f = fzalloc();
	if (!f)
		return 0;

	f->type = fz_file;
	f->f = fopen_lock(file, mode);
	if (!f->f) {
		free(f);
		return 0;
	}

	return f;
}
예제 #4
0
파일: fz.c 프로젝트: kyroskoh/advancecomp
/**
 * Open an compressed file part of a ZIP archive.
 * \param file ZIP archive.
 * \param offset Offset in the archive.
 * \param size_compressed Size of the compressed data.
 * \param size_uncompressed Size of the uncompressed data.
 */
adv_fz* fzopenzipcompressed(const char* file, unsigned offset, unsigned size_compressed, unsigned size_uncompressed)
{
	unsigned char buf[ZIP_LO_FIXED];
	unsigned filename_length;
	unsigned extra_field_length;

	adv_fz* f = fzalloc();
	if (!f)
		return 0;

	f->type = fz_file_compressed;
	f->virtual_pos = 0;
	f->virtual_size = size_uncompressed;
	f->f = fopen_lock(file, "rb");
	if (!f->f) {
		free(f);
		return 0;
	}

	if (fseek(f->f, offset, SEEK_SET) != 0) {
		fclose_lock(f->f);
		free(f);
		return 0;
	}
	if (fread_lock(buf, ZIP_LO_FIXED, 1, f->f)!=1) {
		fclose_lock(f->f);
		free(f);
		return 0;
	}
	filename_length = le_uint16_read(buf+ZIP_LO_filename_length);
	extra_field_length = le_uint16_read(buf+ZIP_LO_extra_field_length);

	/* calculate offset to data and seek there */
	offset += ZIP_LO_FIXED + filename_length + extra_field_length;

	f->real_offset = offset;
	f->real_size = size_compressed;

	if (fseek(f->f, f->real_offset, SEEK_SET) != 0) {
		fclose_lock(f->f);
		free(f);
		return 0;
	}

	compressed_init(f);

	return f;
}