source: rtems/c/src/exec/libcsupport/include/rtems/libio_.h @ 23c4bbf5

4.104.114.84.95
Last change on this file since 23c4bbf5 was 23c4bbf5, checked in by Joel Sherrill <joel.sherrill@…>, on 03/16/99 at 01:41:16

Use proper include for libio.h.

  • 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/libio.h>                /* include before standard IO */
24#include <rtems/assoc.h>                /* assoc.h not included by rtems.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/*
50 *  Semaphore to protect the io table
51 */
52
53#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
54#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
55
56extern rtems_id        rtems_libio_semaphore;
57
58/*
59 *  File descriptor Table Information
60 */
61
62extern unsigned32      rtems_libio_number_iops;
63extern rtems_libio_t  *rtems_libio_iops;
64extern rtems_libio_t  *rtems_libio_last_iop;
65extern rtems_libio_t *rtems_libio_iop_freelist;
66
67/*
68 *  Default mode for all files.
69 */
70
71extern mode_t    rtems_filesystem_umask;
72
73/*
74 *  set_errno_and_return_minus_one
75 *
76 *  Macro to ease common way to return an error.
77 */
78
79#ifndef set_errno_and_return_minus_one
80#define set_errno_and_return_minus_one( _error ) \
81  do { errno = (_error); return -1; } while(0)
82#endif
83
84/*
85 *  rtems_libio_iop
86 *
87 *  Macro to return the file descriptor pointer.
88 */
89
90#define rtems_libio_iop(_fd) \
91  ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \
92         &rtems_libio_iops[_fd] : 0)
93
94/* 
95 *  rtems_libio_check_is_open
96 * 
97 *  Macro to check if a file descriptor is actually open.
98 */
99
100#define rtems_libio_check_is_open(_iop) \
101  do {                                               \
102      if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
103          errno = EBADF;                             \
104          return -1;                                 \
105      }                                              \
106  } while (0)
107
108/*
109 *  rtems_libio_check_fd
110 *
111 *  Macro to check if a file descriptor number is valid.
112 */
113
114#define rtems_libio_check_fd(_fd) \
115  do {                                                     \
116      if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \
117          errno = EBADF;                                   \
118          return -1;                                       \
119      }                                                    \
120  } while (0)
121
122/*
123 *  rtems_libio_check_buffer
124 *
125 *  Macro to check if a buffer pointer is valid.
126 */
127
128#define rtems_libio_check_buffer(_buffer) \
129  do {                                    \
130      if ((_buffer) == 0) {               \
131          errno = EINVAL;                 \
132          return -1;                      \
133      }                                   \
134  } while (0)
135
136/*
137 *  rtems_libio_check_count
138 *
139 *  Macro to check if a count or length is valid.
140 */
141
142#define rtems_libio_check_count(_count) \
143  do {                                  \
144      if ((_count) == 0) {              \
145          return 0;                     \
146      }                                 \
147  } while (0)
148
149/*
150 *  rtems_libio_check_permissions
151 *
152 *  Macro to check if a file descriptor is open for this operation.
153 */
154
155#define rtems_libio_check_permissions(_iop, _flag)    \
156  do {                                                \
157      if (((_iop)->flags & (_flag)) == 0) {           \
158            set_errno_and_return_minus_one( EINVAL ); \
159            return -1;                                \
160      }                                               \
161  } while (0)
162
163/*
164 *  rtems_filesystem_is_separator
165 *
166 *  Macro to determine if a character is a path name separator.
167 *
168 *  NOTE:  This macro handles MS-DOS and UNIX style names.
169 */
170
171#define rtems_filesystem_is_separator( _ch ) \
172   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
173
174/*
175 *  rtems_filesystem_get_start_loc
176 *
177 *  Macro to determine if path is absolute or relative.
178 */
179
180#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
181  do {                                                         \
182    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
183      *(_loc) = rtems_filesystem_root;                         \
184      *(_index) = 1;                                           \
185    } else {                                                   \
186      *(_loc) = rtems_filesystem_current;                      \
187      *(_index) = 0;                                           \
188    }                                                          \
189  } while (0)
190
191#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
192  do {                                                         \
193    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
194      *(_loc) = rtems_filesystem_root;                         \
195      *(_index) = 1;                                           \
196    } else {                                                   \
197      *(_index) = 0;                                           \
198    }                                                          \
199  } while (0)
200
201
202/*
203 *  External structures
204 */
205
206extern rtems_filesystem_location_info_t rtems_filesystem_current;
207extern rtems_filesystem_location_info_t rtems_filesystem_root;
208extern nlink_t                          rtems_filesystem_link_counts;
209
210
211/*
212 *  File Descriptor Routine Prototypes
213 */
214
215rtems_libio_t *rtems_libio_allocate(void);
216
217unsigned32 rtems_libio_fcntl_flags(
218  unsigned32 fcntl_flags
219);
220
221unsigned32 rtems_libio_to_fcntl_flags(
222  unsigned32 flags
223);
224
225void rtems_libio_free(
226  rtems_libio_t *iop
227);
228
229int rtems_libio_is_open_files_in_fs(
230  rtems_filesystem_mount_table_entry_t *mt_entry
231);
232
233int rtems_libio_is_file_open(
234  void  *node_access
235);
236
237/*
238 *  File System Routine Prototypes
239 */
240
241int rtems_filesystem_evaluate_path(
242  const char                        *pathname,
243  int                                flags,
244  rtems_filesystem_location_info_t  *pathloc,
245  int                                follow_link
246);
247
248void rtems_filesystem_initialize();
249
250int init_fs_mount_table();
251
252#ifdef __cplusplus
253}
254#endif
255
256#endif
257/* end of include file */
258
259
260
Note: See TracBrowser for help on using the repository browser.