1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief POSIX 1003.1b - 5.2.1 - Change Current Working Directory |
---|
5 | * @ingroup libio Internal Interface |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2010. |
---|
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 | int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc ) |
---|
29 | { |
---|
30 | int rv = 0; |
---|
31 | rtems_filesystem_global_location_t *global_loc = |
---|
32 | rtems_filesystem_location_transform_to_global( loc ); |
---|
33 | mode_t type = rtems_filesystem_location_type( &global_loc->location ); |
---|
34 | |
---|
35 | if ( S_ISDIR( type ) ) { |
---|
36 | rtems_filesystem_global_location_assign( |
---|
37 | &rtems_filesystem_current, |
---|
38 | global_loc |
---|
39 | ); |
---|
40 | } else { |
---|
41 | rtems_filesystem_location_error( &global_loc->location, ENOTDIR ); |
---|
42 | rtems_filesystem_global_location_release( global_loc ); |
---|
43 | rv = -1; |
---|
44 | } |
---|
45 | |
---|
46 | return rv; |
---|
47 | } |
---|
48 | |
---|
49 | int chdir( const char *path ) |
---|
50 | { |
---|
51 | int rv = 0; |
---|
52 | rtems_filesystem_eval_path_context_t ctx; |
---|
53 | int eval_flags = RTEMS_FS_PERMS_EXEC |
---|
54 | | RTEMS_FS_FOLLOW_LINK; |
---|
55 | rtems_filesystem_location_info_t pathloc; |
---|
56 | |
---|
57 | rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); |
---|
58 | rtems_filesystem_eval_path_extract_currentloc( &ctx, &pathloc ); |
---|
59 | rv = rtems_filesystem_chdir( &pathloc ); |
---|
60 | rtems_filesystem_eval_path_cleanup( &ctx ); |
---|
61 | |
---|
62 | return rv; |
---|
63 | } |
---|