Files
applets
applets_sh
arch
archival
configs
console-tools
coreutils
debianutils
docs
e2fsprogs
editors
examples
findutils
include
init
klibc-utils
libbb
Config.src
Kbuild.src
README
appletlib.c
ask_confirmation.c
auto_string.c
bb_askpass.c
bb_bswap_64.c
bb_cat.c
bb_do_delay.c
bb_getgroups.c
bb_pwd.c
bb_qsort.c
bb_strtod.c
bb_strtonum.c
bbunit.c
capability.c
change_identity.c
chomp.c
common_bufsiz.c
compare_string_array.c
concat_path_file.c
concat_subpath_file.c
copy_file.c
copyfd.c
correct_password.c
crc32.c
default_error_retval.c
device_open.c
die_if_bad_username.c
dump.c
endofname.c
executable.c
fclose_nonstdin.c
fflush_stdout_and_exit.c
fgets_str.c
find_mount_point.c
find_pid_by_name.c
find_root_device.c
full_write.c
get_console.c
get_cpu_count.c
get_last_path_component.c
get_line_from_file.c
get_shell_name.c
get_volsize.c
getopt32.c
getopt_allopts.c
getpty.c
hash_md5_sha.c
hash_md5prime.c
herror_msg.c
human_readable.c
in_ether.c
inet_cksum.c
inet_common.c
inode_hash.c
isdirectory.c
isqrt.c
kernel_version.c
last_char_is.c
lineedit.c
lineedit_ptr_hack.c
llist.c
logenv.c
login.c
loop.c
make_directory.c
makedev.c
match_fstype.c
messages.c
missing_syscalls.c
mode_string.c
mtab.c
nuke_str.c
obscure.c
parse_config.c
parse_mode.c
percent_decode.c
perror_msg.c
perror_nomsg.c
perror_nomsg_and_die.c
pidfile.c
platform.c
print_flags.c
print_numbered_lines.c
printable.c
printable_string.c
process_escape_sequence.c
procps.c
progress.c
ptr_to_globals.c
pw_encrypt.c
pw_encrypt_des.c
pw_encrypt_md5.c
pw_encrypt_sha.c
read.c
read_key.c
read_printf.c
recursive_action.c
remove_file.c
replace.c
rtc.c
run_shell.c
safe_gethostname.c
safe_poll.c
safe_strncpy.c
safe_write.c
securetty.c
selinux_common.c
setup_environment.c
signals.c
simplify_path.c
single_argv.c
skip_whitespace.c
speed_table.c
str_tolower.c
strrstr.c
sysconf.c
time.c
trim.c
u_signal_names.c
ubi.c
udp_io.c
unicode.c
update_passwd.c
utmp.c
uuencode.c
verror_msg.c
vfork_daemon_rexec.c
warn_ignoring_args.c
wfopen.c
wfopen_input.c
write.c
xatonum.c
xatonum_template.c
xconnect.c
xfunc_die.c
xfuncs.c
xfuncs_printf.c
xgetcwd.c
xgethostbyname.c
xreadlink.c
xrealloc_vector.c
xregcomp.c
libpwdgrp
loginutils
mailutils
miscutils
modutils
networking
printutils
procps
qemu_multiarch_testing
runit
scripts
selinux
shell
sysklogd
testsuite
util-linux
.gitignore
.indent.pro
AUTHORS
Config.in
INSTALL
LICENSE
Makefile
Makefile.custom
Makefile.flags
Makefile.help
NOFORK_NOEXEC.lst
README
TODO
TODO_unicode
make_single_applets.sh
size_single_applets.sh
busybox/libbb/simplify_path.c
Denys Vlasenko fb132e4737 whitespace cleanup
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-10-29 11:46:52 +02:00

60 lines
1.1 KiB
C

/* vi: set sw=4 ts=4: */
/*
* bb_simplify_path implementation for busybox
*
* Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
char* FAST_FUNC bb_simplify_abs_path_inplace(char *start)
{
char *s, *p;
p = s = start;
do {
if (*p == '/') {
if (*s == '/') { /* skip duplicate (or initial) slash */
continue;
}
if (*s == '.') {
if (s[1] == '/' || !s[1]) { /* remove extra '.' */
continue;
}
if ((s[1] == '.') && (s[2] == '/' || !s[2])) {
++s;
if (p > start) {
while (*--p != '/') /* omit previous dir */
continue;
}
continue;
}
}
}
*++p = *s;
} while (*++s);
if ((p == start) || (*p != '/')) { /* not a trailing slash */
++p; /* so keep last character */
}
*p = '\0';
return p;
}
char* FAST_FUNC bb_simplify_path(const char *path)
{
char *s, *p;
if (path[0] == '/')
s = xstrdup(path);
else {
p = xrealloc_getcwd_or_warn(NULL);
s = concat_path_file(p, path);
free(p);
}
bb_simplify_abs_path_inplace(s);
return s;
}