/************************************************************************* * (C) 2010 AITNET ltd - Sofia/Bulgaria - * by Michael Pounov * * $Author: misho $ * $Id: file.c,v 1.1 2010/03/24 16:00:15 misho Exp $ * *************************************************************************/ #include "global.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; }