summaryrefslogtreecommitdiff
path: root/libudffs
diff options
context:
space:
mode:
Diffstat (limited to 'libudffs')
-rw-r--r--libudffs/Makefile.am2
-rw-r--r--libudffs/Makefile.in8
-rw-r--r--libudffs/extent.c2
-rw-r--r--libudffs/misc.c76
-rw-r--r--libudffs/unicode.c2
5 files changed, 85 insertions, 5 deletions
diff --git a/libudffs/Makefile.am b/libudffs/Makefile.am
index 2e829be..59f56cb 100644
--- a/libudffs/Makefile.am
+++ b/libudffs/Makefile.am
@@ -1,5 +1,5 @@
noinst_LTLIBRARIES = libudffs.la
-libudffs_la_SOURCES = crc.c extent.c misc.c unicode.c ../include/libudffs.h ../include/ecma_167.h ../include/osta_udf.h ../include/udf_endian.h ../include/bswap.h
+libudffs_la_SOURCES = crc.c extent.c misc.c unicode.c ../include/libudffs.h ../include/ecma_167.h ../include/osta_udf.h ../include/bswap.h
libudffs_la_LIBADD = @LTLIBOBJS@
AM_CPPFLAGS = -I$(top_srcdir)/include
diff --git a/libudffs/Makefile.in b/libudffs/Makefile.in
index e2a0c34..348b9d3 100644
--- a/libudffs/Makefile.in
+++ b/libudffs/Makefile.in
@@ -225,11 +225,17 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
+UDEVDIR = @UDEVDIR@
+UDEV_CFLAGS = @UDEV_CFLAGS@
+UDEV_LIBS = @UDEV_LIBS@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
@@ -285,7 +291,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libudffs.la
-libudffs_la_SOURCES = crc.c extent.c misc.c unicode.c ../include/libudffs.h ../include/ecma_167.h ../include/osta_udf.h ../include/udf_endian.h ../include/bswap.h
+libudffs_la_SOURCES = crc.c extent.c misc.c unicode.c ../include/libudffs.h ../include/ecma_167.h ../include/osta_udf.h ../include/bswap.h
libudffs_la_LIBADD = @LTLIBOBJS@
AM_CPPFLAGS = -I$(top_srcdir)/include
all: all-am
diff --git a/libudffs/extent.c b/libudffs/extent.c
index 8e5f1fb..5856ed8 100644
--- a/libudffs/extent.c
+++ b/libudffs/extent.c
@@ -1,7 +1,7 @@
/*
* extent.c
*
- * Copyright (c) 2001-2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu>
+ * Copyright (c) 2001-2002 Ben Fennema
* Copyright (c) 2014-2017 Pali Rohár <pali.rohar@gmail.com>
* All rights reserved.
*
diff --git a/libudffs/misc.c b/libudffs/misc.c
index 6369078..a0e496a 100644
--- a/libudffs/misc.c
+++ b/libudffs/misc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 Pali Rohár <pali.rohar@gmail.com>
+ * Copyright (C) 2017-2018 Pali Rohár <pali.rohar@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,9 +19,15 @@
#include "config.h"
#include <ctype.h>
+#include <errno.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
#include "libudffs.h"
@@ -82,3 +88,71 @@ size_t gen_uuid_from_vol_set_ident(char uuid[17], const dstring *vol_set_ident,
return 16;
}
+
+uint32_t strtou32(const char *str, int base, int *failed)
+{
+ char *endptr = NULL;
+ long long int ret;
+
+ /* strtou* does not signal underflow, so use signed variant */
+ errno = 0;
+ ret = strtoll(str, &endptr, base);
+ /* strto* skips leading whitespaces, so detect them via isspace */
+ *failed = (!*str || isspace(*str) || *endptr || errno || ret < 0 || ret > UINT32_MAX) ? 1 : 0;
+ return ret;
+}
+
+uint16_t strtou16(const char *str, int base, int *failed)
+{
+ uint32_t ret;
+
+ ret = strtou32(str, base, failed);
+ *failed = (*failed || ret > UINT16_MAX) ? 1 : 0;
+ return ret;
+}
+
+static inline unsigned int intlog2(unsigned int word)
+{
+ unsigned int result = 0;
+
+ while (word >>= 1)
+ result++;
+ return result;
+}
+
+uint32_t randu32(void)
+{
+ int fd;
+ uint32_t value;
+ unsigned int bits;
+ unsigned int rand_bits;
+
+ static int srand_done = 0;
+
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd >= 0)
+ {
+ if (read(fd, &value, sizeof(value)) == sizeof(value))
+ {
+ close(fd);
+ return value;
+ }
+ close(fd);
+ }
+
+ if (!srand_done)
+ {
+ srand(time(NULL) * getpid());
+ srand_done = 1;
+ }
+
+ value = 0;
+ rand_bits = intlog2((unsigned int)RAND_MAX+1);
+ for (bits = 0; bits < 32; bits += rand_bits)
+ {
+ value <<= rand_bits;
+ value |= rand();
+ }
+
+ return value;
+}
diff --git a/libudffs/unicode.c b/libudffs/unicode.c
index e31d4de..d8bbf73 100644
--- a/libudffs/unicode.c
+++ b/libudffs/unicode.c
@@ -1,7 +1,7 @@
/*
* unicode.c
*
- * Copyright (c) 2001-2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu>
+ * Copyright (c) 2001-2002 Ben Fennema
* Copyright (c) 2014-2017 Pali Rohár <pali.rohar@gmail.com>
* All rights reserved.
*