[Libsysio-commit] HEAD: libsysio/include file.h
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2007-11-20 17:34:41
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25701/include Modified Files: file.h Log Message: Add two new macros. F_FILEOK tests if the passed file ref is valid; Not NULL and fil->f_pno not NULL. F_WRITEOK tests if the passed file ref is valid and writeable. Index: file.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/file.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- file.h 1 May 2007 16:33:52 -0000 1.19 +++ file.h 20 Nov 2007 17:34:38 -0000 1.20 @@ -113,6 +113,12 @@ struct file { } while (0) /* + * Valid file object? + */ +#define F_FILEOK(_fil) \ + ((_fil) && (_fil)->f_pno) + +/* * Determine if a file may be read/written. * * Given a ptr to an open file table entry and a flag indicating desired @@ -127,6 +133,15 @@ struct file { (((_c) == 'r' && !((_fil)->f_flags & O_WRONLY)) || \ ((_c) == 'w' && ((_fil)->f_flags & (O_WRONLY | O_RDWR)))) +/* + * Is file object writable? Return 0, if so. Otherwise, the appropriate + * (negated) error number. + */ +#define F_WRITEOK(_fil) \ + (!(F_FILEOK(_fil) && F_CHKRW((_fil), 'w')) \ + ? -EBADF \ + : (IS_RDONLY((_fil)->f_pno) ? -EROFS : 0)) + struct ioctx; extern struct file *_sysio_fnew(struct pnode *pno, int flags); |