OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [lib/] [libc/] [libio_.h] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
2
 *  Libio Internal Information
3
 *
4
 *  COPYRIGHT (c) 1989-1999.
5
 *  On-Line Applications Research Corporation (OAR).
6
 *
7
 *  The license and distribution terms for this file may be
8
 *  found in the file LICENSE in this distribution or at
9
 *  http://www.OARcorp.com/rtems/license.html.
10
 *
11 208 chris
 *  $Id: libio_.h,v 1.2 2001-09-27 12:01:15 chris Exp $
12 158 chris
 */
13
 
14
#ifndef __LIBIO__h
15
#define __LIBIO__h
16
 
17
#ifdef __cplusplus
18
extern "C" {
19
#endif
20
 
21
#include <rtems.h>
22
#include <rtems/libio.h>                /* include before standard IO */
23
#include <rtems/assoc.h>                /* assoc.h not included by rtems.h */
24
 
25
#include <stdio.h>                      /* O_RDONLY, et.al. */
26
#include <fcntl.h>                      /* O_RDONLY, et.al. */
27
#include <assert.h>
28
#include <stdarg.h>
29
#include <errno.h>
30
 
31
#if ! defined(O_NDELAY)
32
# if defined(solaris2)
33
#  define O_NDELAY O_NONBLOCK
34
# elif defined(RTEMS_NEWLIB)
35
#  define O_NDELAY _FNBIO
36
# endif
37
#endif
38
 
39
#if !defined(ENOTSUP)
40
#define ENOTSUP EOPNOTSUPP
41
#endif
42
 
43
#include <errno.h>
44
#include <string.h>                     /* strcmp */
45
#include <unistd.h>
46
#include <stdlib.h>                     /* calloc() */
47
 
48
/*
49
 *  Semaphore to protect the io table
50
 */
51
 
52
#define RTEMS_LIBIO_SEM         rtems_build_name('L', 'B', 'I', 'O')
53
#define RTEMS_LIBIO_IOP_SEM(n)  rtems_build_name('L', 'B', 'I', n)
54
 
55
extern rtems_id                          rtems_libio_semaphore;
56
extern rtems_filesystem_file_handlers_r  rtems_filesystem_null_handlers;
57
 
58
/*
59
 *  File descriptor Table Information
60
 */
61
 
62
extern unsigned32      rtems_libio_number_iops;
63
extern rtems_libio_t  *rtems_libio_iops;
64
extern rtems_libio_t  *rtems_libio_last_iop;
65
extern rtems_libio_t *rtems_libio_iop_freelist;
66
 
67
/*
68
 *  Default mode for all files.
69
 */
70
 
71
extern 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_freenode
165
 *
166
 *  Macro to free a node.
167
 */
168
 
169
#define rtems_filesystem_freenode( _node ) \
170
  do { \
171
    if ( (_node)->ops->freenod ) \
172
      (*(_node)->ops->freenod)( (_node) ); \
173
  } while (0)
174
 
175
/*
176
 *  rtems_filesystem_is_separator
177
 *
178
 *  Macro to determine if a character is a path name separator.
179
 *
180
 *  NOTE:  This macro handles MS-DOS and UNIX style names.
181
 */
182
 
183
#define rtems_filesystem_is_separator( _ch ) \
184
   ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0'))
185
 
186
/*
187
 *  rtems_filesystem_get_start_loc
188
 *
189
 *  Macro to determine if path is absolute or relative.
190
 */
191
 
192
#define rtems_filesystem_get_start_loc( _path, _index, _loc )  \
193
  do {                                                         \
194
    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
195
      *(_loc) = rtems_filesystem_root;                         \
196
      *(_index) = 1;                                           \
197
    } else {                                                   \
198
      *(_loc) = rtems_filesystem_current;                      \
199
      *(_index) = 0;                                           \
200
    }                                                          \
201
  } while (0)
202
 
203
#define rtems_filesystem_get_sym_start_loc( _path, _index, _loc )  \
204
  do {                                                         \
205
    if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) {     \
206
      *(_loc) = rtems_filesystem_root;                         \
207
      *(_index) = 1;                                           \
208
    } else {                                                   \
209
      *(_index) = 0;                                           \
210
    }                                                          \
211
  } while (0)
212
 
213
 
214
/*
215
 *  External structures
216
 */
217
 
218
extern rtems_filesystem_location_info_t rtems_filesystem_current;
219
extern rtems_filesystem_location_info_t rtems_filesystem_root;
220
extern nlink_t                          rtems_filesystem_link_counts;
221
 
222
 
223
/*
224
 *  File Descriptor Routine Prototypes
225
 */
226
 
227
rtems_libio_t *rtems_libio_allocate(void);
228
 
229
unsigned32 rtems_libio_fcntl_flags(
230
  unsigned32 fcntl_flags
231
);
232
 
233
unsigned32 rtems_libio_to_fcntl_flags(
234
  unsigned32 flags
235
);
236
 
237
void rtems_libio_free(
238
  rtems_libio_t *iop
239
);
240
 
241
int rtems_libio_is_open_files_in_fs(
242
  rtems_filesystem_mount_table_entry_t *mt_entry
243
);
244
 
245
int rtems_libio_is_file_open(
246
  void  *node_access
247
);
248
 
249
/*
250
 *  File System Routine Prototypes
251
 */
252
 
253
int rtems_filesystem_evaluate_path(
254
  const char                        *pathname,
255
  int                                flags,
256
  rtems_filesystem_location_info_t  *pathloc,
257
  int                                follow_link
258
);
259
 
260
void rtems_filesystem_initialize();
261
 
262
int init_fs_mount_table();
263
 
264
#ifdef __cplusplus
265
}
266
#endif
267
 
268
#endif
269
/* end of include file */
270
 
271
 
272
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.