]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
isosize: move ISO size functions into a shared header
authorDaniel Drake <drake@endlessm.com>
Mon, 16 Dec 2019 05:48:56 +0000 (13:48 +0800)
committerDaniel Drake <drake@endlessm.com>
Mon, 16 Dec 2019 06:29:24 +0000 (14:29 +0800)
Move the helper functions that parse ISO data & sector size info into
a separate, shared header.

These will addtionally be used by libblkid's iso9660 parser.

Signed-off-by: Daniel Drake <drake@endlessm.com>
disk-utils/isosize.c
include/Makemodule.am
include/iso9660.h [new file with mode: 0644]

index 3c8d40f3caf30550cc6e7ca4668b9aac34f2c2d9..92996635684310a145330326ef66e1c2b4d1980e 100644 (file)
@@ -29,6 +29,7 @@
 #include "c.h"
 #include "strutils.h"
 #include "closestream.h"
+#include "iso9660.h"
 
 #define ISOSIZE_EXIT_ALLFAILED 32
 #define ISOSIZE_EXIT_SOMEOK    64
@@ -42,56 +43,6 @@ static int is_iso(int fd)
        return memcmp(&label, &"\1CD001\1", 8);
 }
 
-static int isonum_721(unsigned char *p)
-{
-       return ((p[0] & 0xff)
-               | ((p[1] & 0xff) << 8));
-}
-
-static int isonum_722(unsigned char *p)
-{
-       return ((p[1] & 0xff)
-               | ((p[0] & 0xff) << 8));
-}
-
-static int isonum_723(unsigned char *p, int xflag)
-{
-       int le = isonum_721(p);
-       int be = isonum_722(p + 2);
-
-       if (xflag && le != be)
-               /* translation is useless */
-               warnx("723error: le=%d be=%d", le, be);
-       return (le);
-}
-
-static int isonum_731(unsigned char *p)
-{
-       return ((p[0] & 0xff)
-               | ((p[1] & 0xff) << 8)
-               | ((p[2] & 0xff) << 16)
-               | ((p[3] & 0xff) << 24));
-}
-
-static int isonum_732(unsigned char *p)
-{
-       return ((p[3] & 0xff)
-               | ((p[2] & 0xff) << 8)
-               | ((p[1] & 0xff) << 16)
-               | ((p[0] & 0xff) << 24));
-}
-
-static int isonum_733(unsigned char *p, int xflag)
-{
-       int le = isonum_731(p);
-       int be = isonum_732(p + 4);
-
-       if (xflag && le != be)
-               /* translation is useless */
-               warnx("733error: le=%d be=%d", le, be);
-       return (le);
-}
-
 static int isosize(int argc, char *filenamep, int xflag, long divisor)
 {
        int fd, nsecs, ssize, rc = -1;
index 92d1c305885693bed3aa34c15b13fbdb8b3386ba..c55c262c9bf9dfa7c1d28d13dee6c0a97c34278a 100644 (file)
@@ -22,6 +22,7 @@ dist_noinst_HEADERS += \
        include/fileutils.h \
        include/idcache.h \
        include/ismounted.h \
+       include/iso9660.h \
        include/pwdutils.h \
        include/linux_version.h \
        include/list.h \
diff --git a/include/iso9660.h b/include/iso9660.h
new file mode 100644 (file)
index 0000000..73decd9
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef UTIL_LINUX_ISO_H
+#define UTIL_LINUX_ISO_H
+
+#include <stdbool.h>
+
+#include "c.h"
+
+static inline int isonum_721(unsigned char *p)
+{
+       return ((p[0] & 0xff)
+               | ((p[1] & 0xff) << 8));
+}
+
+static inline int isonum_722(unsigned char *p)
+{
+       return ((p[1] & 0xff)
+               | ((p[0] & 0xff) << 8));
+}
+
+static inline int isonum_723(unsigned char *p, bool check_match)
+{
+       int le = isonum_721(p);
+       int be = isonum_722(p + 2);
+
+       if (check_match && le != be)
+               /* translation is useless */
+               warnx("723error: le=%d be=%d", le, be);
+       return (le);
+}
+
+static inline int isonum_731(unsigned char *p)
+{
+       return ((p[0] & 0xff)
+               | ((p[1] & 0xff) << 8)
+               | ((p[2] & 0xff) << 16)
+               | ((p[3] & 0xff) << 24));
+}
+
+static inline int isonum_732(unsigned char *p)
+{
+       return ((p[3] & 0xff)
+               | ((p[2] & 0xff) << 8)
+               | ((p[1] & 0xff) << 16)
+               | ((p[0] & 0xff) << 24));
+}
+
+static inline int isonum_733(unsigned char *p, bool check_match)
+{
+       int le = isonum_731(p);
+       int be = isonum_732(p + 4);
+
+       if (check_match && le != be)
+               /* translation is useless */
+               warnx("733error: le=%d be=%d", le, be);
+       return(le);
+}
+
+#endif