File:  [ELWIX - Embedded LightWeight unIX -] / libaitsync / src / file.c
Revision 1.1.1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Mon May 9 13:46:12 2011 UTC (13 years, 1 month ago) by misho
Branches: sync1_0
Diff to: branchpoint 1.1.1.1: preferred, colored
under NetBSD mkstemps() function not exists!!!
added this feature for NetBSD systems

/*************************************************************************
* (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
*  by Michael Pounov <misho@openbsd-bg.org>
*
* $Author: misho $
* $Id: file.c,v 1.1.1.1.2.1 2011/05/09 13:46:12 misho Exp $
*
*************************************************************************/
#include "global.h"
#include "tool.h"
#include "file.h"


int syncOpen(const char *csFile, int mode)
{
	int f;

	if (!csFile || (*csFile == '-' && !csFile[1]))
		return mode;

	f = open(csFile, !mode ? O_RDONLY : O_WRONLY | O_CREAT | O_TRUNC, 0644);
	if (f == -1)
		SETERR;

	return f;
}

inline int syncTemp(char * __restrict psName, int len)
{
	char str[] = "/tmp/ansyncXXXXXX.dlt";
	int f;

	f = mkstemps(str, 4);
	strlcpy(psName, str, len);

	return f;
}

void syncClose(int f)
{
	if (f > 2)
		close(f);
}

int syncEOF(int f)
{
	off_t old;
	int ret = 0;

	old = lseek(f, 0, SEEK_CUR);
	ret = lseek(f, 0, SEEK_END) - old;
	if (lseek(f, old, SEEK_SET) == -1) {
		SETERR;
		return -1;
	}

	return !ret;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>