[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] ios: Move file name normalization logic into ios-dev.h
From: |
Egeyar Bagcioglu |
Subject: |
[PATCH 2/3] ios: Move file name normalization logic into ios-dev.h |
Date: |
Sat, 11 Jul 2020 18:07:25 +0200 |
... so that we can later use the same from streamable files.
2020-07-11 Egeyar Bagcioglu <egeyar@gmail.com>
* libpoke/ios-dev-file.c (ios_dev_file_handler_normalize): Move
the file name normalization logic from here ...
* libpoke/ios-dev.h (IOS_FILE_HANDLER_NORMALIZE): ... to here.
---
libpoke/ios-dev-file.c | 22 +++++-----------------
libpoke/ios-dev.h | 18 ++++++++++++++++++
2 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/libpoke/ios-dev-file.c b/libpoke/ios-dev-file.c
index 4e4f3e63..68b2dc39 100644
--- a/libpoke/ios-dev-file.c
+++ b/libpoke/ios-dev-file.c
@@ -43,23 +43,11 @@ struct ios_dev_file
static char *
ios_dev_file_handler_normalize (const char *handler)
{
- /* This backend is special, in the sense it accepts any handler.
- However, we want to ensure that the ios name is unambiguous from
- other ios devices, by prepending ./ to relative names that might
- otherwise be confusing. */
- static const char safe[] =
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789/+_-";
- char *ret;
-
- if (handler[0] == '/' || strspn (handler, safe) == strlen (handler))
- return strdup (handler);
-
- if (asprintf (&ret, "./%s", handler) == -1)
- return NULL;
-
- return ret;
+ char *newhandler;
+ IOS_FILE_HANDLER_NORMALIZE (handler, newhandler);
+
+ /* TODO handle the case where newhandler is NULL. */
+ return newhandler;
}
static void *
diff --git a/libpoke/ios-dev.h b/libpoke/ios-dev.h
index 8461bb35..d6b269aa 100644
--- a/libpoke/ios-dev.h
+++ b/libpoke/ios-dev.h
@@ -85,3 +85,21 @@ struct ios_dev_if
OFFSET. Otherwise, do not do anything. */
int (*flush) (void *dev, ios_dev_off offset);
};
+
+#define IOS_FILE_HANDLER_NORMALIZE(handler, newhandler)
\
+{ \
+ /* File devices are special, in the sense that they accept any \
+ handler. However, we want to ensure that the ios name is \
+ unambiguous from other ios devices, by prepending ./ to relative \
+ names that might otherwise be confusing. */ \
+ static const char safe[] = \
+ "abcdefghijklmnopqrstuvwxyz" \
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
+ "0123456789/+_-"; \
+ \
+ if (handler[0] == '/' || strspn (handler, safe) == strlen (handler)) \
+ (newhandler) = strdup ((handler)); \
+ \
+ if (asprintf (&(newhandler), "./%s", (handler)) == -1) \
+ (newhandler) = NULL; \
+}
--
2.25.4
- [PATCH 1/3] ios: Introduce ios_flush and ios_dev_<...>_flush., Egeyar Bagcioglu, 2020/07/11
- [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h,
Egeyar Bagcioglu <=
- Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h, Jose E. Marchesi, 2020/07/12
- Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h, Egeyar Bagcioglu, 2020/07/12
- Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h, Egeyar Bagcioglu, 2020/07/13
- Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h, Jose E. Marchesi, 2020/07/13
- Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h, Jose E. Marchesi, 2020/07/13
- Re: [PATCH 2/3] ios: Move file name normalization logic into ios-dev.h, Egeyar Bagcioglu, 2020/07/14
[PATCH 3/3] ios: Pass "flags" to handler_normalize as an argument., Egeyar Bagcioglu, 2020/07/11
Re: [PATCH 1/3] ios: Introduce ios_flush and ios_dev_<...>_flush., Jose E. Marchesi, 2020/07/12