File: | /home/joel/rtems-4.11-work/build/rtems/c/src/../../cpukit/posix/src/semopen.c |
Location: | line 64, column 5 |
Description: | Value stored to 'mode' is never read |
1 | /* |
2 | * COPYRIGHT (c) 1989-2007. |
3 | * On-Line Applications Research Corporation (OAR). |
4 | * |
5 | * The license and distribution terms for this file may be |
6 | * found in the file LICENSE in this distribution or at |
7 | * http://www.rtems.com/license/LICENSE. |
8 | * |
9 | * $Id: semopen.c,v 1.15 2009/05/03 23:10:02 joel Exp $ |
10 | */ |
11 | |
12 | #if HAVE_CONFIG_H1 |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | #include <stdarg.h> |
17 | |
18 | #include <errno(*__errno_location ()).h> |
19 | #include <fcntl.h> |
20 | #include <pthread.h> |
21 | #include <semaphore.h> |
22 | #include <limits.h> |
23 | |
24 | #include <rtems/system.h> |
25 | #include <rtems/score/object.h> |
26 | #include <rtems/posix/semaphore.h> |
27 | #include <rtems/posix/time.h> |
28 | #include <rtems/seterr.h> |
29 | |
30 | /*PAGE |
31 | * |
32 | * sem_open |
33 | * |
34 | * Opens a named semaphore. Used in conjunction with the sem_close |
35 | * and sem_unlink commands. |
36 | * |
37 | * 11.2.3 Initialize/Open a Named Semaphore, P1003.1b-1993, p.221 |
38 | * |
39 | * NOTE: When oflag is O_CREAT, then optional third and fourth |
40 | * parameters must be present. |
41 | */ |
42 | |
43 | sem_t *sem_open( |
44 | const char *name, |
45 | int oflag, |
46 | ... |
47 | /* mode_t mode, */ |
48 | /* unsigned int value */ |
49 | ) |
50 | { |
51 | va_list arg; |
52 | mode_t mode; |
53 | unsigned int value = 0; |
54 | int status; |
55 | sem_t the_semaphore_id; |
56 | sem_t *id; |
57 | POSIX_Semaphore_Control *the_semaphore; |
58 | Objects_Locations location; |
59 | |
60 | _Thread_Disable_dispatch(); |
61 | |
62 | if ( oflag & O_CREAT0100 ) { |
63 | va_start(arg, oflag)__builtin_va_start(arg, oflag); |
64 | mode = (mode_t) va_arg( arg, unsigned int )__builtin_va_arg(arg, unsigned int); |
Value stored to 'mode' is never read | |
65 | value = va_arg( arg, unsigned int )__builtin_va_arg(arg, unsigned int); |
66 | va_end(arg)__builtin_va_end(arg); |
67 | } |
68 | |
69 | status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id ); |
70 | |
71 | /* |
72 | * If the name to id translation worked, then the semaphore exists |
73 | * and we can just return a pointer to the id. Otherwise we may |
74 | * need to check to see if this is a "semaphore does not exist" |
75 | * or some other miscellaneous error on the name. |
76 | */ |
77 | |
78 | if ( status ) { |
79 | |
80 | /* |
81 | * Unless provided a valid name that did not already exist |
82 | * and we are willing to create then it is an error. |
83 | */ |
84 | |
85 | if ( !( status == ENOENT2 && (oflag & O_CREAT0100) ) ) { |
86 | _Thread_Enable_dispatch(); |
87 | rtems_set_errno_and_return_minus_one_cast( status, sem_t * )do { (*__errno_location ()) = (status); return (sem_t *) -1; } while(0); |
88 | } |
89 | } else { |
90 | |
91 | /* |
92 | * Check for existence with creation. |
93 | */ |
94 | |
95 | if ( (oflag & (O_CREAT0100 | O_EXCL0200)) == (O_CREAT0100 | O_EXCL0200) ) { |
96 | _Thread_Enable_dispatch(); |
97 | rtems_set_errno_and_return_minus_one_cast( EEXIST, sem_t * )do { (*__errno_location ()) = (17); return (sem_t *) -1; } while (0); |
98 | } |
99 | |
100 | the_semaphore = _POSIX_Semaphore_Get( &the_semaphore_id, &location ); |
101 | the_semaphore->open_count += 1; |
102 | _Thread_Enable_dispatch(); |
103 | _Thread_Enable_dispatch(); |
104 | goto return_id; |
105 | } |
106 | |
107 | /* |
108 | * At this point, the semaphore does not exist and everything has been |
109 | * checked. We should go ahead and create a semaphore. |
110 | */ |
111 | |
112 | status =_POSIX_Semaphore_Create_support( |
113 | name, |
114 | false0, /* not shared across processes */ |
115 | value, |
116 | &the_semaphore |
117 | ); |
118 | |
119 | /* |
120 | * errno was set by Create_support, so don't set it again. |
121 | */ |
122 | |
123 | _Thread_Enable_dispatch(); |
124 | |
125 | if ( status == -1 ) |
126 | return SEM_FAILED(sem_t *) -1; |
127 | |
128 | return_id: |
129 | #if defined(RTEMS_USE_16_BIT_OBJECT) |
130 | the_semaphore->Semaphore_id = the_semaphore->Object.id; |
131 | id = &the_semaphore->Semaphore_id; |
132 | #else |
133 | id = (sem_t *)&the_semaphore->Object.id; |
134 | #endif |
135 | return id; |
136 | } |