4.115
Last change
on this file since e02d5dd9 was
c499856,
checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47
|
Change all references of rtems.com to rtems.org.
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Change Directory |
---|
5 | * @ingroup libcsupport |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2011. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * Modifications to support reference counting in the file system are |
---|
13 | * Copyright (c) 2012 embedded brains GmbH. |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <unistd.h> |
---|
25 | |
---|
26 | #include <rtems/libio_.h> |
---|
27 | |
---|
28 | /** |
---|
29 | * compatible with SVr4, 4.4BSD and X/OPEN - Change Directory |
---|
30 | */ |
---|
31 | int fchdir( int fd ) |
---|
32 | { |
---|
33 | int rv = 0; |
---|
34 | rtems_libio_t *iop; |
---|
35 | struct stat st; |
---|
36 | rtems_filesystem_location_info_t loc; |
---|
37 | |
---|
38 | st.st_mode = 0; |
---|
39 | st.st_uid = 0; |
---|
40 | st.st_gid = 0; |
---|
41 | |
---|
42 | rtems_libio_check_fd( fd ); |
---|
43 | iop = rtems_libio_iop( fd ); |
---|
44 | rtems_libio_check_is_open( iop ); |
---|
45 | |
---|
46 | rtems_filesystem_instance_lock( &iop->pathinfo ); |
---|
47 | rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, &st ); |
---|
48 | if ( rv == 0 ) { |
---|
49 | bool access_ok = rtems_filesystem_check_access( |
---|
50 | RTEMS_FS_PERMS_EXEC, |
---|
51 | st.st_mode, |
---|
52 | st.st_uid, |
---|
53 | st.st_gid |
---|
54 | ); |
---|
55 | |
---|
56 | if ( access_ok ) { |
---|
57 | rtems_filesystem_location_clone( &loc, &iop->pathinfo ); |
---|
58 | } else { |
---|
59 | errno = EACCES; |
---|
60 | rv = -1; |
---|
61 | } |
---|
62 | } |
---|
63 | rtems_filesystem_instance_unlock( &iop->pathinfo ); |
---|
64 | |
---|
65 | if ( rv == 0 ) { |
---|
66 | rv = rtems_filesystem_chdir( &loc ); |
---|
67 | } |
---|
68 | |
---|
69 | return rv; |
---|
70 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.