Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_errno.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_errno.c,v 12.1 2005/06/16 20:23:23 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #include "db_int.h"
00013 
00014 /*
00015  * __os_get_errno_ret_zero --
00016  *      Return the value of errno, even if it's zero.
00017  *
00018  * PUBLIC: int __os_get_errno_ret_zero __P((void));
00019  */
00020 int
00021 __os_get_errno_ret_zero()
00022 {
00023         /* This routine must be able to return the same value repeatedly. */
00024         return (errno);
00025 }
00026 
00027 /*
00028  * __os_get_errno --
00029  *      Return the value of errno, or EAGAIN if errno is zero.
00030  *
00031  * PUBLIC: int __os_get_errno __P((void));
00032  */
00033 int
00034 __os_get_errno()
00035 {
00036         /*
00037          * This routine must be able to return the same value repeatedly.
00038          *
00039          * We've seen cases where system calls failed but errno was never set.
00040          * This version of __os_get_errno() sets errno to EAGAIN if it's not
00041          * already set, to work around that problem.  For obvious reasons, we
00042          * can only call this function if we know an error has occurred, that
00043          * is, we can't test errno for a non-zero value after this call.
00044          */
00045         if (errno == 0)
00046                 __os_set_errno(EAGAIN);
00047 
00048         return (errno);
00049 }
00050 
00051 /*
00052  * __os_set_errno --
00053  *      Set the value of errno.
00054  *
00055  * PUBLIC: void __os_set_errno __P((int));
00056  */
00057 void
00058 __os_set_errno(evalue)
00059         int evalue;
00060 {
00061         /*
00062          * This routine is called by the compatibility interfaces (DB 1.85,
00063          * dbm and hsearch).  Force values > 0, that is, not one of DB 2.X
00064          * and later's public error returns.  If something bad has happened,
00065          * default to EFAULT -- a nasty return.  Otherwise, default to EINVAL.
00066          * As the compatibility APIs aren't included on Windows, the Windows
00067          * version of this routine doesn't need this behavior.
00068          */
00069         errno =
00070             evalue >= 0 ? evalue : (evalue == DB_RUNRECOVERY ? EFAULT : EINVAL);
00071 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2