[PATCH] move quote_filename into help.c, and remove static scope, as it will also
From: Sean Finney <seanius@seanius.net>
---
src/archives.c | 58 --------------------------------------------------------
src/help.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/main.h | 1 +
3 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/src/archives.c b/src/archives.c
index 9fddb9c..5987c23 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -58,64 +58,6 @@ static security_context_t scontext = NULL;
struct pkginfo *conflictor[MAXCONFLICTORS];
int cflict_index = 0;
-/* snprintf(3) doesn't work if format contains %.<nnn>s and an argument has
- * invalid char for locale, then it returns -1.
- * ohshite() is ok, but fd_fd_copy(), which is used in tarobject() in this
- * file, is not ok, because
- * - fd_fd_copy() == buffer_copy_setup() [include/dpkg.h]
- * - buffer_copy_setup() uses varbufvprintf(&v, desc, al); [lib/mlib.c]
- * - varbufvprintf() fails and memory exausted, because it call
- * fmt = "backend dpkg-deb during `%.255s'
- * arg may contain some invalid char, for example,
- * /usr/share/doc/console-tools/examples/unicode/\342\231\252\342\231\254
- * in console-tools.
- * In this case, if user uses some locale which doesn't support \342\231...,
- * vsnprintf() always returns -1 and varbufextend() get called again
- * and again until memory is exausted and it aborts.
- *
- * So, we need to escape invalid char, probably as in
- * tar-1.13.19/lib/quotearg.c: quotearg_buffer_restyled()
- * but here I escape all 8bit chars, in order to be simple.
- * - ukai@debian.or.jp
- */
-static char *
-quote_filename(char *buf, int size, char *s)
-{
- char *r = buf;
-
- while (size > 0) {
- switch (*s) {
- case '\0':
- *buf = '\0';
- return r;
- case '\\':
- *buf++ = '\\';
- *buf++ = '\\';
- size -= 2;
- break;
- default:
- if (((*s) & 0x80) == 0) {
- *buf++ = *s++;
- --size;
- } else {
- if (size > 4) {
- sprintf(buf, "\\%03o", *(unsigned char *)s);
- size -= 4;
- buf += 4;
- s++;
- } else {
- /* buffer full */
- *buf = '\0'; /* XXX */
- return r;
- }
- }
- }
- }
- *buf = '\0'; /* XXX */
-
- return r;
-}
-
/* special routine to handle partial reads from the tarfile */
static int safe_read(int fd, void *buf, int len)
{
diff --git a/src/help.c b/src/help.c
index 78e3b29..ad85800 100644
--- a/src/help.c
+++ b/src/help.c
@@ -526,6 +526,63 @@ void ensure_pathname_nonexisting(const char *pathname) {
waitsubproc(c1,"rm cleanup",0);
}
+/* snprintf(3) doesn't work if format contains %.<nnn>s and an argument has
+ * invalid char for locale, then it returns -1.
+ * ohshite() is ok, but fd_fd_copy(), which is used in tarobject() in this
+ * file, is not ok, because
+ * - fd_fd_copy() == buffer_copy_setup() [include/dpkg.h]
+ * - buffer_copy_setup() uses varbufvprintf(&v, desc, al); [lib/mlib.c]
+ * - varbufvprintf() fails and memory exausted, because it call
+ * fmt = "backend dpkg-deb during `%.255s'
+ * arg may contain some invalid char, for example,
+ * /usr/share/doc/console-tools/examples/unicode/\342\231\252\342\231\254
+ * in console-tools.
+ * In this case, if user uses some locale which doesn't support \342\231...,
+ * vsnprintf() always returns -1 and varbufextend() get called again
+ * and again until memory is exausted and it aborts.
+ *
+ * So, we need to escape invalid char, probably as in
+ * tar-1.13.19/lib/quotearg.c: quotearg_buffer_restyled()
+ * but here I escape all 8bit chars, in order to be simple.
+ * - ukai@debian.or.jp
+ */
+char* quote_filename(char *buf, int size, char *s)
+{
+ char *r = buf;
+
+ while (size > 0) {
+ switch (*s) {
+ case '\0':
+ *buf = '\0';
+ return r;
+ case '\\':
+ *buf++ = '\\';
+ *buf++ = '\\';
+ size -= 2;
+ break;
+ default:
+ if (((*s) & 0x80) == 0) {
+ *buf++ = *s++;
+ --size;
+ } else {
+ if (size > 4) {
+ sprintf(buf, "\\%03o", *(unsigned char *)s);
+ size -= 4;
+ buf += 4;
+ s++;
+ } else {
+ /* buffer full */
+ *buf = '\0'; /* XXX */
+ return r;
+ }
+ }
+ }
+ }
+ *buf = '\0'; /* XXX */
+
+ return r;
+}
+
void log_action(const char *action, struct pkginfo *pkg) {
log_message("%s %s %s %s", action, pkg->name,
versiondescribe(&pkg->installed.version, vdew_nonambig),
diff --git a/src/main.h b/src/main.h
index 15a8303..4322da4 100644
--- a/src/main.h
+++ b/src/main.h
@@ -190,6 +190,7 @@ void ensure_package_clientdata(struct pkginfo *pkg);
const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);
void oldconffsetflags(const struct conffile *searchconff);
void ensure_pathname_nonexisting(const char *pathname);
+char *quote_filename(char *buf, int size, char *s);
int chmodsafe_unlink(const char *pathname, const char **failed);
int chmodsafe_unlink_statted(const char *pathname, const struct stat *stab,
const char **failed);
--
1.5.4.3
Reply to: