00001 /* 00002 setblock (turn blocking on or off) 00003 AUP2, Sec. 4.02.2 00004 00005 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00006 May be copied only for purposes and under conditions described 00007 on the Web page www.basepath.com/aup/copyright.htm. 00008 00009 The Example Files are provided "as is," without any warranty; 00010 without even the implied warranty of merchantability or fitness 00011 for a particular purpose. The author and his publisher are not 00012 responsible for any damages, direct or incidental, resulting 00013 from the use or non-use of these Example Files. 00014 00015 The Example Files may contain defects, and some contain deliberate 00016 coding mistakes that were included for educational reasons. 00017 You are responsible for determining if and how the Example Files 00018 are to be used. 00019 00020 */ 00021 #include "defs.h" 00022 #include "setblock.h" 00023 00024 /* turn blocking on or off */ 00025 /*[setblock]*/ 00026 bool setblock(int fd, bool block) 00027 { 00028 int flags; 00029 00030 ec_neg1( flags = fcntl(fd, F_GETFL) ) 00031 if (block) 00032 flags &= ~O_NONBLOCK; 00033 else 00034 flags |= O_NONBLOCK; 00035 ec_neg1( fcntl(fd, F_SETFL, flags) ) 00036 return true; 00037 00038 EC_CLEANUP_BGN 00039 return false; 00040 EC_CLEANUP_END 00041 } 00042 /*[]*/