| 1 |
/* |
| 2 |
libfakechroot -- fake chroot environment |
| 3 |
Copyright (c) 2013 Piotr Roszatycki <[email protected]> |
| 4 |
|
| 5 |
This library is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU Lesser General Public |
| 7 |
License as published by the Free Software Foundation; either |
| 8 |
version 2.1 of the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This library is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
Lesser General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public |
| 16 |
License along with this library; if not, write to the Free Software |
| 17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
#include <config.h> |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
#include <unistd.h> |
| 25 |
#include <stdio.h> |
| 26 |
|
| 27 |
#include "libfakechroot.h" |
| 28 |
#include "strlcpy.h" |
| 29 |
#include "dedotdot.h" |
| 30 |
#include "getcwd_real.h" |
| 31 |
|
| 32 |
|
| 33 |
LOCAL char * rel2abs(const char * name, char * resolved) |
| 34 |
{ |
| 35 |
char cwd[FAKECHROOT_PATH_MAX - 1]; |
| 36 |
|
| 37 |
debug("rel2abs(\"%s\", &resolved)", name); |
| 38 |
|
| 39 |
if (name == NULL) { |
| 40 |
resolved = NULL; |
| 41 |
goto end; |
| 42 |
} |
| 43 |
|
| 44 |
if (*name == '\0') { |
| 45 |
*resolved = '\0'; |
| 46 |
goto end; |
| 47 |
} |
| 48 |
|
| 49 |
getcwd_real(cwd, FAKECHROOT_PATH_MAX - 1); |
| 50 |
narrow_chroot_path(cwd); |
| 51 |
|
| 52 |
if (*name == '/') { |
| 53 |
strlcpy(resolved, name, FAKECHROOT_PATH_MAX); |
| 54 |
} |
| 55 |
else { |
| 56 |
snprintf(resolved, FAKECHROOT_PATH_MAX, "%s/%s", cwd, name); |
| 57 |
} |
| 58 |
|
| 59 |
dedotdot(resolved); |
| 60 |
|
| 61 |
end: |
| 62 |
debug("rel2abs(\"%s\", \"%s\")", name, resolved); |
| 63 |
return resolved; |
| 64 |
} |