comparison packages/error/current/src/errno.cxx @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children 51b34619b677
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 //===========================================================================
2 //
3 // errno.cxx
4 //
5 // ISO C and POSIX error code
6 //
7 //===========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //===========================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): jlarmour
35 // Contributors: jlarmour
36 // Date: 2000-04-14
37 // Purpose: Provide the errno variable
38 // Description: This file either provides the errno variable directly,
39 // or if thread-safe, using a kernel per-thread data
40 // access function
41 // Usage:
42 //
43 //####DESCRIPTIONEND####
44 //
45 //===========================================================================
46
47 // CONFIGURATION
48
49 #include <pkgconf/system.h>
50 #include <pkgconf/error.h> // Configuration header
51
52 #ifdef CYGPKG_ERROR_ERRNO
53
54 // INCLUDES
55
56 #include <cyg/infra/cyg_type.h> // Common project-wide type definitions
57 #include <cyg/infra/cyg_trac.h> // Common tracing functions
58 #include <cyg/error/errno.h> // Header for this file
59
60 #ifdef CYGSEM_ERROR_PER_THREAD_ERRNO
61 # include <pkgconf/kernel.h> // kernel configuration
62 # include <cyg/kernel/thread.hxx> // per-thread data
63 # include <cyg/kernel/thread.inl> // per-thread data
64 # include <cyg/kernel/mutex.hxx> // mutexes
65 #endif
66
67 // GLOBAL VARIABLES
68
69 #ifndef CYGSEM_ERROR_PER_THREAD_ERRNO
70
71 // errno is initialised to 0 at program startup - ANSI 7.1.4
72 Cyg_ErrNo errno = 0;
73
74 #else // ifndef CYGSEM_ERROR_PER_THREAD_ERRNO
75
76 # if defined(CYGDBG_USE_TRACING) && defined(CYGNUM_ERROR_ERRNO_TRACE_LEVEL)
77 static int errno_trace = CYGNUM_ERROR_ERRNO_TRACE_LEVEL;
78 # define TL1 (0 < errno_trace)
79 # else
80 # define TL1 (0)
81 # endif
82
83 // FUNCTIONS
84
85 Cyg_ErrNo * const
86 cyg_error_get_errno_p( void )
87 {
88 Cyg_ErrNo *errno_p;
89
90 CYG_REPORT_FUNCNAMETYPE( "cyg_error_get_errno_p", "&errno is %d");
91
92 // set up the thread data, allocating if necessary (even though the
93 // user _shouldn't_ read errno before its set, we can't stop them - and
94 // ANSI prescribes it has a sensible value (0) before its set too anyway.
95
96 Cyg_Thread *self = Cyg_Thread::self();
97
98 errno_p = (Cyg_ErrNo *)self->get_data_ptr(CYGNUM_KERNEL_THREADS_DATA_ERRNO);
99
100 CYG_TRACE1( TL1, "errno is %d", *errno_p );
101
102 CYG_REPORT_RETVAL( errno_p );
103
104 // return the internal data's errno
105 return errno_p;
106 } // cyg_error_get_errno_p()
107
108 #endif // ifdef CYGSEM_ERROR_PER_THREAD_ERRNO
109
110 #endif // ifdef CYGPKG_ERROR_ERRNO
111
112 // EOF errno.cxx