diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-01-09 10:21:01 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-01-09 10:21:01 +0200 |
commit | a97100ba1dae7849571f30075d7564fb0124dc91 (patch) | |
tree | 594494f88b7d0978e7e8a29b57877107ac9cfa93 /rpmio | |
parent | 4906b9c55e97a9db8f5db4691a09253ddfadd976 (diff) | |
download | rpm-a97100ba1dae7849571f30075d7564fb0124dc91.tar.gz rpm-a97100ba1dae7849571f30075d7564fb0124dc91.tar.bz2 rpm-a97100ba1dae7849571f30075d7564fb0124dc91.zip |
Handle spaces in file path arguments correctly (#217258)
Ported from rpm5.org work of Jeff Johnson with some differences:
- place into rpmfileutil instead of rpmgi as it's more generic than just rpmgi
- rename rpmgiEscapeSpaces -> rpmEscapeSpaces
- return char *, not const char * as the return string must be freed by caller
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/rpmfileutil.c | 23 | ||||
-rw-r--r-- | rpmio/rpmfileutil.h | 7 |
2 files changed, 30 insertions, 0 deletions
diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index 40e4e5afb..b07c93a9c 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -840,3 +840,26 @@ exit: return rc; } +char * rpmEscapeSpaces(const char * s) +{ + const char * se; + char * t; + char * te; + size_t nb = 0; + + for (se = s; *se; se++) { + if (isspace(*se)) + nb++; + nb++; + } + nb++; + + t = te = xmalloc(nb); + for (se = s; *se; se++) { + if (isspace(*se)) + *te++ = '\\'; + *te++ = *se; + } + *te = '\0'; + return t; +} diff --git a/rpmio/rpmfileutil.h b/rpmio/rpmfileutil.h index 336ccd266..bd45d183f 100644 --- a/rpmio/rpmfileutil.h +++ b/rpmio/rpmfileutil.h @@ -103,4 +103,11 @@ char * rpmGetPath (const char * path, ...); */ int rpmGlob(const char * patterns, int * argcPtr, char *** argvPtr); +/** + * Escape isspace(3) characters in string. + * @param s string + * @return escaped string + */ +char * rpmEscapeSpaces(const char * s); + #endif /* _RPMFILEUTIL_H */ |