chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
udev: set errno = ENOSYS for removed interfaces
[elogind.git]
/
src
/
sd-id128.c
diff --git
a/src/sd-id128.c
b/src/sd-id128.c
index f5e0432a3f9c6835f8d27aa9e9a070af94bda22c..b4184e1c7e56bd47273bb050b1666e76229c31bb 100644
(file)
--- a/
src/sd-id128.c
+++ b/
src/sd-id128.c
@@
-24,13
+24,15
@@
#include <unistd.h>
#include "sd-id128.h"
#include <unistd.h>
#include "sd-id128.h"
+
#include "util.h"
#include "macro.h"
#include "util.h"
#include "macro.h"
-char *sd_id128_to_string(sd_id128_t id, char s[33]) {
+
_public_
char *sd_id128_to_string(sd_id128_t id, char s[33]) {
unsigned n;
unsigned n;
- assert(s);
+ if (!s)
+ return NULL;
for (n = 0; n < 16; n++) {
s[n*2] = hexchar(id.bytes[n] >> 4);
for (n = 0; n < 16; n++) {
s[n*2] = hexchar(id.bytes[n] >> 4);
@@
-42,12
+44,14
@@
char *sd_id128_to_string(sd_id128_t id, char s[33]) {
return s;
}
return s;
}
-int sd_id128_from_string(const char s[33], sd_id128_t *ret) {
+
_public_
int sd_id128_from_string(const char s[33], sd_id128_t *ret) {
unsigned n;
sd_id128_t t;
unsigned n;
sd_id128_t t;
- assert(s);
- assert(ret);
+ if (!s)
+ return -EINVAL;
+ if (!ret)
+ return -EINVAL;
for (n = 0; n < 16; n++) {
int a, b;
for (n = 0; n < 16; n++) {
int a, b;
@@
-70,7
+74,7
@@
int sd_id128_from_string(const char s[33], sd_id128_t *ret) {
return 0;
}
return 0;
}
-s
d_id128_t sd_id128_
make_v4_uuid(sd_id128_t id) {
+s
tatic sd_id128_t
make_v4_uuid(sd_id128_t id) {
/* Stolen from generate_random_uuid() of drivers/char/random.c
* in the kernel sources */
/* Stolen from generate_random_uuid() of drivers/char/random.c
* in the kernel sources */
@@
-83,7
+87,7
@@
sd_id128_t sd_id128_make_v4_uuid(sd_id128_t id) {
return id;
}
return id;
}
-int sd_id128_get_machine(sd_id128_t *ret) {
+
_public_
int sd_id128_get_machine(sd_id128_t *ret) {
static __thread sd_id128_t saved_machine_id;
static __thread bool saved_machine_id_valid = false;
int fd;
static __thread sd_id128_t saved_machine_id;
static __thread bool saved_machine_id_valid = false;
int fd;
@@
-92,6
+96,9
@@
int sd_id128_get_machine(sd_id128_t *ret) {
unsigned j;
sd_id128_t t;
unsigned j;
sd_id128_t t;
+ if (!ret)
+ return -EINVAL;
+
if (saved_machine_id_valid) {
*ret = saved_machine_id;
return 0;
if (saved_machine_id_valid) {
*ret = saved_machine_id;
return 0;
@@
-129,7
+136,7
@@
int sd_id128_get_machine(sd_id128_t *ret) {
return 0;
}
return 0;
}
-int sd_id128_get_boot(sd_id128_t *ret) {
+
_public_
int sd_id128_get_boot(sd_id128_t *ret) {
static __thread sd_id128_t saved_boot_id;
static __thread bool saved_boot_id_valid = false;
int fd;
static __thread sd_id128_t saved_boot_id;
static __thread bool saved_boot_id_valid = false;
int fd;
@@
-139,6
+146,9
@@
int sd_id128_get_boot(sd_id128_t *ret) {
sd_id128_t t;
char *p;
sd_id128_t t;
char *p;
+ if (!ret)
+ return -EINVAL;
+
if (saved_boot_id_valid) {
*ret = saved_boot_id;
return 0;
if (saved_boot_id_valid) {
*ret = saved_boot_id;
return 0;
@@
-181,12
+191,13
@@
int sd_id128_get_boot(sd_id128_t *ret) {
return 0;
}
return 0;
}
-int sd_id128_randomize(sd_id128_t *ret) {
+
_public_
int sd_id128_randomize(sd_id128_t *ret) {
int fd;
ssize_t k;
sd_id128_t t;
int fd;
ssize_t k;
sd_id128_t t;
- assert(ret);
+ if (!ret)
+ return -EINVAL;
fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
@@
-205,6
+216,6
@@
int sd_id128_randomize(sd_id128_t *ret) {
* only guarantee this for newly generated UUIDs, not for
* pre-existing ones.*/
* only guarantee this for newly generated UUIDs, not for
* pre-existing ones.*/
- *ret =
sd_id128_
make_v4_uuid(t);
+ *ret = make_v4_uuid(t);
return 0;
}
return 0;
}