[Pkg-libvirt-commits] [libguestfs] 10/66: utils: Move guestfs___validate_guid out of utils.c.
Hilko Bengen
bengen at moszumanska.debian.org
Fri May 9 12:56:20 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch master
in repository libguestfs.
commit 8d868255b50be802fa84b173d17358a3269f2a9b
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Sat Mar 29 16:57:59 2014 +0000
utils: Move guestfs___validate_guid out of utils.c.
guestfs___validate_guid was a new function added to utils.c in
commit beef77403cd9d634b6ff6daa9f33d292e2d320a7.
However utils.c should not include <guestfs-internal.h> since the
other functions in this file can be used by all front-end code, not
just libguestfs.so.
This function is only needed in libguestfs.so, so move it to another
source file, and remove include of <guestfs-internal.h> from utils.c.
Also: use 'size_t' for counting, not 'int'.
This fixes commit beef77403cd9d634b6ff6daa9f33d292e2d320a7.
(cherry picked from commit 768ab2e01dab5a8e7e751c33b72c1341fcaf9dc3)
---
po/POTFILES | 1 +
src/Makefile.am | 1 +
src/guestfs-internal.h | 2 +-
src/guid.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/utils.c | 45 +-------------------------------
5 files changed, 74 insertions(+), 45 deletions(-)
diff --git a/po/POTFILES b/po/POTFILES
index 37dbbaa..0fac8fe 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -284,6 +284,7 @@ src/events.c
src/file.c
src/filearch.c
src/fuse.c
+src/guid.c
src/handle.c
src/info.c
src/inspect-apps.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 768e716..bb4ebb3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -99,6 +99,7 @@ libguestfs_la_SOURCES = \
file.c \
filearch.c \
fuse.c \
+ guid.c \
handle.c \
info.c \
inspect.c \
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 27fc857..648f005 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -845,7 +845,7 @@ extern void guestfs___cleanup_cmd_close (struct command **);
extern char *guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src);
extern bool guestfs___discard_possible (guestfs_h *g, struct drive *drv, unsigned long qemu_version);
-/* utils.c */
+/* guid.c */
extern int guestfs___validate_guid (const char *);
#endif /* GUESTFS_INTERNAL_H_ */
diff --git a/src/guid.c b/src/guid.c
new file mode 100644
index 0000000..8f6da4f
--- /dev/null
+++ b/src/guid.c
@@ -0,0 +1,70 @@
+/* libguestfs
+ * Copyright (C) 2014 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "c-ctype.h"
+
+#include "guestfs.h"
+#include "guestfs-internal.h"
+
+/* Check whether a string supposed to contain a GUID actually contains it.
+ * It can recognize strings either as '{21EC2020-3AEA-1069-A2DD-08002B30309D}'
+ * or '21EC2020-3AEA-1069-A2DD-08002B30309D'.
+ */
+int
+guestfs___validate_guid (const char *str)
+{
+ size_t i, len = strlen (str);
+
+ switch (len) {
+ case 36:
+ break;
+ case 38:
+ if (str[0] == '{' && str[len -1] == '}') {
+ ++str;
+ len -= 2;
+ break;
+ }
+ return 0;
+ default:
+ return 0;
+ }
+
+ for (i = 0; i < len; ++i) {
+ switch (i) {
+ case 8:
+ case 13:
+ case 18:
+ case 23:
+ if (str[i] != '-')
+ return 0;
+ break;
+ default:
+ if (!c_isalnum (str[i]))
+ return 0;
+ break;
+ }
+ }
+
+ return 1;
+}
diff --git a/src/utils.c b/src/utils.c
index 3ad0063..201ca6b 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -28,10 +28,8 @@
#include <sys/wait.h>
#include <libintl.h>
-#include "c-ctype.h"
-
+/* NB: MUST NOT include "guestfs-internal.h" or gnulib headers. */
#include "guestfs.h"
-#include "guestfs-internal.h"
#include "guestfs-internal-frontend.h"
/* Note that functions in libutils are used by the tools and language
@@ -271,44 +269,3 @@ guestfs___drive_name (size_t index, char *ret)
*ret = '\0';
return ret;
}
-
-/* Check whether a string supposed to contain a GUID actually contains it.
- * It can recognize strings either as '{21EC2020-3AEA-1069-A2DD-08002B30309D}'
- * or '21EC2020-3AEA-1069-A2DD-08002B30309D'.
- */
-int
-guestfs___validate_guid (const char *str)
-{
- int len = strlen (str);
- switch (len) {
- case 36:
- break;
- case 38:
- if (str[0] == '{' && str[len -1] == '}') {
- ++str;
- len -= 2;
- break;
- }
- return 0;
- default:
- return 0;
- }
-
- for (int i = 0; i < len; ++i) {
- switch (i) {
- case 8:
- case 13:
- case 18:
- case 23:
- if (str[i] != '-')
- return 0;
- break;
- default:
- if (!c_isalnum (str[i]))
- return 0;
- break;
- }
- }
-
- return 1;
-}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list