/*************************************************************************
* (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>