source: rtems/c/src/lib/include/rtems/libio_.h @ e602b3f

4.104.114.84.95
Last change on this file since e602b3f was 3ef8798, checked in by Joel Sherrill <joel.sherrill@…>, on 03/06/99 at 18:09:15

Added F_GETFL support so the fdopen() implementation in newlib 1.8.1
would work. At the same time, the initial implementation of F_SETFL
was added. A support routine was added to convert internal libio
flags back to the POSIX style. Eventually the internal representation
should be eliminated in the interest of simplicity and code reduction.
This problem was reported by Jake Janovetz <janovetz@…>.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 *  Libio Internal Information
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#ifndef __LIBIO__h
16#define __LIBIO__h
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <rtems.h>
23#include <rtems/assoc.h>                /* assoc.h not included by rtems.h */
24#include <rtems/libio.h>
25
26#include <stdio.h>                      /* O_RDONLY, et.al. */
27#include <fcntl.h>                      /* O_RDONLY, et.al. */
28#include <assert.h>
29#include <stdarg.h>
30#include <errno.h>
31
32#if ! defined(O_NDELAY)
33# if defined(solaris2)
34#  define O_NDELAY O_NONBLOCK
35# elif defined(RTEMS_NEWLIB)
36#  define O_NDELAY _FNBIO
37# endif
38#endif
39
40#if !defined(ENOTSUP)
41#define ENOTSUP EOPNOTSUPP
42#endif
43
44#include <errno.h>
45#include <string.h>                     /* strcmp */
46#include <unistd.h>
47#include <stdlib.h>                     /* calloc() */
48
49#include "libio.h"                      /* libio.h not pulled in by rtems */
50
51
52/*
53 *  Semaphore to protect the io table
54 */
55
56#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
57#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
58
59extern rtems_id        rtems_libio_semaphore;
60
61/*
62 *  File descriptor Table Information
63 */
64
65extern unsigned32      rtems_libio_number_iops;
66extern rtems_libio_t  *rtems_libio_iops;
67extern rtems_libio_t  *rtems_libio_last_iop;
68extern rtems_libio_t *rtems_libio_iop_freelist;
69
70/*
71 *  Default mode for all files.
72 */
73
74extern mode_t    rtems_filesystem_umask;
75
76/*
77 *  set_errno_and_return_minus_one
78 *
79 *  Macro to ease common way to return an error.
80 */
81
82#ifndef set_errno_and_return_minus_one
83#define set_errno_and_return_minus_one( _error ) \
84  do { errno = (_error); return -1; } while(0)
85#endif
86
87/*
88 *  rtems_libio_iop
89 *
90 *  Macro to return the file descriptor pointer.
91 */
92
93#define rtems_libio_iop(_fd) \
94  ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \
95         &rtems_libio_iops[_fd] : 0)
96
97/* 
98 *  rtems_libio_check_is_open
99 * 
100 *  Macro to check if a file descriptor is actually open.
101 */
102
103#define rtems_libio_check_is_open(_iop) \
104  do {                                               \
105      if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
106          errno = EBADF;                             \
107          return -1;                                 \
108      }                                              \
109  } while (0)
110
111/*
112 *  rtems_libio_check_fd
113 *
114 *  Macro to check if a file descriptor number is valid.
115 */
116
117#define rtems_libio_check_fd(_fd) \
118  do {                                                     \
119      if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \
120          errno = EBADF;                                   \
121          return -1;                                       \
122      }                                                    \
123  } while (0)
124
125/*
126 *  rtems_libio_check_buffer
127 *
128 *  Macro to check if a buffer pointer is valid.
129 */
130
131#define rtems_libio_check_buffer(_buffer) \
132  do {                                    \
133      if ((_buffer) == 0) {               \
134          errno = EINVAL;                 \
135          return -1;                      \
136      }                                   \
137  } while (0)
138
139/*
140 *  rtems_libio_check_count
141 *
142 *  Macro to check if a count or length is valid.
143 */
144
145#define rtems_libio_check_count(_count) \
146  do {                                  \
147      if ((_count) == 0) {              \
148          return 0;                     \
149      }                                 \
150  } while (0)
151
152/*
153 *  rtems_libio_check_permissions
154 *
155 *  Macro to check if a file descriptor is open for this operation.
156 */
157
158#define rtems_libio_check_permissions(_iop, _flag)    \
159  do {                                                \
160      if (((_iop)->flags & (_flag)) == 0) {           \
161            set_errno_and_return_minus_one( EINVAL ); \
162            return -1;                                \
163      }                                               \
164  } while (0)
165
166/*
167 *  rtems_filesystem_is_separator
168 *
169 *  Macro to determine if a character is a path name separator.
170 *
171 *  NOTE:  This macro handles MS-DOS and UNIX style names.
172 */
173
174#define rtems_filesystem_is_separator( _ch ) \
175   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
176
177/*
178 *  rtems_filesystem_get_start_loc
179 *
180 *  Macro to determine if path is absolute or relative.
181 */
182
183#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
184  do {                                                         \
185    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
186      *(_loc) = rtems_filesystem_root;                         \
187      *(_index) = 1;                                           \
188    } else {                                                   \
189      *(_loc) = rtems_filesystem_current;                      \
190      *(_index) = 0;                                           \
191    }                                                          \
192  } while (0)
193
194#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
195  do {                                                         \
196    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
197      *(_loc) = rtems_filesystem_root;                         \
198      *(_index) = 1;                                           \
199    } else {                                                   \
200      *(_index) = 0;                                           \
201    }                                                          \
202  } while (0)
203
204
205/*
206 *  External structures
207 */
208
209extern rtems_filesystem_location_info_t rtems_filesystem_current;
210extern rtems_filesystem_location_info_t rtems_filesystem_root;
211extern nlink_t                          rtems_filesystem_link_counts;
212
213
214/*
215 *  File Descriptor Routine Prototypes
216 */
217
218rtems_libio_t *rtems_libio_allocate(void);
219
220unsigned32 rtems_libio_fcntl_flags(
221  unsigned32 fcntl_flags
222);
223
224unsigned32 rtems_libio_to_fcntl_flags(
225  unsigned32 flags
226);
227
228void rtems_libio_free(
229  rtems_libio_t *iop
230);
231
232int rtems_libio_is_open_files_in_fs(
233  rtems_filesystem_mount_table_entry_t *mt_entry
234);
235
236int rtems_libio_is_file_open(
237  void  *node_access
238);
239
240/*
241 *  File System Routine Prototypes
242 */
243
244int rtems_filesystem_evaluate_path(
245  const char                        *pathname,
246  int                                flags,
247  rtems_filesystem_location_info_t  *pathloc,
248  int                                follow_link
249);
250
251void rtems_filesystem_initialize();
252
253int init_fs_mount_table();
254
255#ifdef __cplusplus
256}
257#endif
258
259#endif
260/* end of include file */
261
262
263
Note: See TracBrowser for help on using the repository browser.