/* This file is part of Lcrzo.
*/

#if defined LCRZODEF_SYSTEM_Unix
int lcrzo_priv_fd_block_set(int fd, 
			    lcrzo_bool beblocking)
{ int old_fc, new_fc, ret;

  /*verification des parametres*/
  lcrzo_bool_verifbof(beblocking);

  old_fc=fcntl(fd, F_GETFL, 0);
  if (old_fc<0)
  { if (errno==EBADF)
    { errno=0;
      return(LCRZO_ERR_OKDATAEND);
    }
    return(LCRZO_ERR_FUFCNTL);
  }
  if (beblocking)
    new_fc = old_fc & (~O_NONBLOCK);
  else
    new_fc = old_fc | O_NONBLOCK;
  ret=fcntl(fd, F_SETFL, new_fc);
  if (ret<0) return(LCRZO_ERR_FUFCNTL);
  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
#elif defined LCRZODEF_SYSTEM_Windows
  /* this function is not needed */
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif
