List of commits:
Subject Hash Author Date (UTC)
Initial commit 474cb9c92803539b47670ebac06fdc2b517f3bca Sylvain BERTRAND 2017-07-18 20:38:13
Commit 474cb9c92803539b47670ebac06fdc2b517f3bca - Initial commit
Author: Sylvain BERTRAND
Author date (UTC): 2017-07-18 20:38
Committer name: Sylvain BERTRAND
Committer date (UTC): 2017-07-18 20:38
Parent(s):
Signing key:
Tree: ab04c63b7058a3190c9d36b6454d8e4ea6c380bc
File Lines added Lines deleted
LICENSE 1 0
README 13 0
libuuid.sym 48 0
make 678 0
make.libuuid.sh 77 0
make.uuidgen.sh 76 0
src/clear.c 46 0
src/compare.c 58 0
src/config.h 817 0
src/copy.c 48 0
src/gen_uuid.c 558 0
src/isnull.c 51 0
src/namespace.h 7 0
src/pack.c 72 0
src/parse.c 82 0
src/randutils.c 193 0
src/test_uuid.c 123 0
src/unpack.c 66 0
src/unparse.c 79 0
src/utils/all-io.h 82 0
src/utils/c.h 389 0
src/utils/closestream.h 75 0
src/utils/nls.h 125 0
src/utils/randutils.h 17 0
src/utils/strutils.h 233 0
src/uuid.h 104 0
src/uuidP.h 61 0
src/uuid_time.c 174 0
src/uuidd.h 54 0
src/uuidgen.c 98 0
File LICENSE added (mode: 100644) (index 0000000..20ff7cb)
1 See util-linux license.
File README added (mode: 100644) (index 0000000..a8a9184)
1 This is a code extraction of libuuid and uuidgen from util-linux.
2
3 The main purpose is to get a symbol collision secure static linking of
4 libuuid.a.
5
6 ... and no autotools, libtool, cmake, meson, scons, ninja, perl, python... in
7 the SDK.... YEAY!
8
9 The "configuration" is set is stone, but this is only the first commit.
10
11 --
12 Sylvain BERTRAND
13 sylvain.bertrand@gmail.com
File libuuid.sym added (mode: 100644) (index 0000000..28a2076)
1 /*
2 * The symbol versioning ensures that a new application requiring symbol 'foo'
3 * can't run with old libbrary.so not providing 'foo' - the global SONAME
4 * version info can't enforce this since we never change the SONAME.
5 *
6 * The original libuuid from e2fsprogs (<=1.41.5) does not to use
7 * symbol versioning -- all the original symbols are in UUID_1.0 now.
8 *
9 * Copyright (C) 2011-2014 Karel Zak <kzak@redhat.com>
10 */
11 UUID_1.0 {
12 global:
13 uuid_clear;
14 uuid_compare;
15 uuid_copy;
16 uuid_generate;
17 uuid_generate_random;
18 uuid_generate_time;
19 uuid_is_null;
20 uuid_parse;
21 uuid_unparse;
22 uuid_unparse_lower;
23 uuid_unparse_upper;
24 uuid_time;
25 uuid_type;
26 uuid_variant;
27 };
28
29 /*
30 * version(s) since util-linux 2.20
31 */
32 UUID_2.20 {
33 global:
34 uuid_generate_time_safe;
35 } UUID_1.0;
36
37
38 /*
39 * __uuid_* this is not part of the official API, this is
40 * uuidd (uuid daemon) specific stuff. Hell.
41 */
42 UUIDD_PRIVATE {
43 global:
44 __uuid_generate_time;
45 __uuid_generate_random;
46 local:
47 *;
48 };
File make added (mode: 100755) (index 0000000..41e3bcf)
1 #!/bin/sh
2
3 #this script is brutal and verbose, has no tricks and is quite linear, then
4 #quite easy to deal with
5 #for the moment, it's hardcoded for a gcc toolchain... BAD! Since now
6 #gcc is a c++ piece of shit
7
8 # stolen from ffmpeg configure like a pig
9 set -e
10
11 # prevent locale nonsense from breaking basic text processing
12 LC_ALL=C
13 export LC_ALL
14
15 # libtool versioning
16 libuuid_api=1
17 libuuid_rev=3
18 libuuid_age=0
19 libuuid_so_version=${libuuid_api}.${libuuid_rev}.${libuuid_age}
20 fake_root=fake_root
21 #-------------------------------------------------------------------------------
22
23 # it's benign here, but keep in mind it does define the order of static linking
24 # which is important for proper symbol selection
25 libuuid_src_files='
26 src/clear.c
27 src/compare.c
28 src/copy.c
29 src/gen_uuid.c
30 src/isnull.c
31 src/pack.c
32 src/parse.c
33 src/unpack.c
34 src/unparse.c
35 src/uuid_time.c
36 src/randutils.c
37 '
38
39 # it's benign here, but keep in mind it does define the order of static linking
40 # which is important for proper symbol selection
41 uuidgen_src_files='
42 src/uuidgen.c
43 '
44 #-------------------------------------------------------------------------------
45
46 sep_start()
47 {
48 printf '###############################################################################\n'
49 }
50
51 sep_end()
52 {
53 printf '###############################################################################\n\n'
54 }
55
56 subsep_start()
57 {
58 printf '*******************************************************************************\n'
59 }
60
61 subsep_end()
62 {
63 printf '*******************************************************************************\n'
64 }
65
66 ################################################################################
67
68 sep_start;echo 'looking for source path:'
69 if test -f make; then
70 src_path=.
71 else
72 src_path=$(cd $(dirname "$0"); pwd)
73 echo "$src_path" | grep -q '[[:blank:]]' &&
74 die "out of tree builds are impossible with whitespace in source path."
75 test -e "$src_path/config.h" &&
76 die "out of tree builds are impossible with config.h in source dir."
77 fi
78 echo "source path is $src_path";sep_end
79
80 ################################################################################
81
82 is_in()
83 {
84 value=$1
85 shift
86 for var in $*; do
87 [ $var = $value ] && return 0
88 done
89 return 1
90 }
91
92 die_unknown()
93 {
94 echo "Unknown option \"$1\"."
95 echo "See $0 --help for available options."
96 exit 1
97 }
98
99 set_default()
100 {
101 for opt; do
102 eval : \${$opt:=\$${opt}_default}
103 done
104 }
105
106 CMDLINE_SET='
107 bin_cc
108 bin_ccld
109 libuuid_cc
110 libuuid_ar
111 dbin_cc
112 dbin_ccld
113 slibuuid_cc
114 slibuuid_ccld
115 prefix
116 eprefix
117 bindir
118 libdir
119 includedir
120 sysconfdir
121 localstatedir
122 pkglibexecdir
123 version
124 '
125
126 ################################################################################
127
128 #command line set defaults
129 #-------------------------------------------------------------------------------
130 bin_cc_default='gcc -Wall -Wextra -std=gnu99 -O2 -c'
131 bin_ccld_default='gcc -static'
132
133 libuuid_cc_default='gcc -Wall -Wextra -std=gnu99 -O2 -fPIC -c'
134 libuuid_ar_default="ar rcs"
135
136 dbin_cc_default='gcc -Wall -Wextra -std=gnu99 -O2 -c'
137 dbin_ccld_default='gcc -Wl,--as-needed'
138
139 slibuuid_cc_default="gcc -Wall -Wextra \
140 -std=gnu99 -O2 -fPIC -c
141 "
142 slibuuid_ccld_default="gcc -shared \
143 -Wl,--version-script=$src_path/libuuid.sym \
144 -Wl,-soname,libuuid.so.$libuuid_api \
145 -Wl,--as-needed \
146 "
147 #-------------------------------------------------------------------------------
148
149 prefix_default=/usr/local
150 eprefix_default='$prefix'
151 bindir_default='$prefix/bin'
152 libdir_default='$eprefix/lib'
153 includedir_default='$prefix/include'
154 sysconfdir_default='$prefix/etc'
155 localstatedir_default='$prefix/var'
156 pkglibexecdir_default='$libdir/udev'
157 version_default=24
158 set_default $CMDLINE_SET
159
160 libuuid_only=no
161 disable_static=no
162 disable_dynamic=no
163
164 ################################################################################
165
166
167 ################################################################################
168
169 show_help(){
170 cat <<EOF
171 Usage: make [options]
172
173 default is to build libuuid and uuidgen
174
175 Options: [defaults in brackets after descriptions]
176
177 Help options:
178 --help print this message
179
180 Standard options:
181 --libuuid-only build only libblkid
182 --disable-static disable the build of static lib and static binary
183 --disable-shared disable the build of shared lib and dynamic binary
184
185 --prefix=PREFIX architecture independent prefix [$prefix_default]
186 --eprefix=EPREFIX architecture dependent exec prefix [$eprefix_default]
187 --libdir=DIR object code libraries [$libdir_default]
188 --includedir=DIR C header files [$includedir_default]
189 --sysconfdir=DIR read-only single-machine data [$sysconfdir_default]
190 --localstatedir=DIR modifiable single-machine data [$localstatedir_default]
191 --pkglibexecdir=DIR program executables [$pkglibexecdir_default]
192
193 --version=VERSION override the version number [$version_default]
194
195 --man build man pages
196
197 Advanced options:
198 --bin-cc=CC use C compiler command line CC for static target uuidgen [$bin_cc_default]
199 --bin-ccld=CCLD use linker command line CCLD for static target uuidgen [$bin_ccld_default]
200
201 --dbin-cc=CC use C compiler command line CC for dynamic target uuidgen [$dbin_cc_default]
202 --dbin-ccld=CCLD use linker command line CCLD for dynamic target uuidgen [$dbin_ccld_default]
203
204 --libuuid-cc=CC use C compiler command line CC for static target libuuid [$libuuid_cc_default]
205 --libuuid-ar=AR use archive command line AR for static target libuuid [$libuuid_ar_default]
206
207 --slibuuid-cc=CC use C compiler command line CC for shared target libuuid [$slibuuid_cc_default]
208 --slibuuid-ccld=CCLD use linker command line CCLD for shared target libuuid [$slibuuid_ccld_default]
209 EOF
210 exit 0
211 }
212
213 ################################################################################
214
215 for opt do
216 optval="${opt#*=}"
217 case "$opt" in
218 --help|-h) show_help
219 ;;
220 --libuuid-only)
221 libuuid_only=yes
222 ;;
223 --disable-static)
224 disable_static=yes
225 ;;
226 --disable-dynamic)
227 disable_dynamic=yes
228 ;;
229 --man)
230 MAN=yes
231 ;;
232 *)
233 optname=${opt%%=*}
234 optname=${optname#--}
235 optname=$(echo "$optname" | sed 's/-/_/g')
236 if is_in $optname $CMDLINE_SET; then
237 eval $optname='$optval'
238 else
239 die_unknown $opt
240 fi
241 ;;
242 esac
243 done
244
245 ################################################################################
246
247 path_expand()
248 {
249 e_v=$1
250 #we set a maximum expansion depth of 3
251 for d in 1 2 3
252 do
253 e_v=$(eval echo "$e_v")
254 done
255 #get rid of ugly double // in path
256 echo "$e_v" | sed -e 's%//%/%g'
257 }
258
259 sep_start;echo 'expanding final paths:'
260 e_prefix=$(path_expand "$prefix")
261 e_eprefix=$(path_expand "$eprefix")
262 e_bindir=$(path_expand "$bindir")
263 e_libdir=$(path_expand "$libdir")
264 e_includedir=$(path_expand "$includedir")
265 e_sysconfdir=$(path_expand "$sysconfdir")
266 e_localstatedir=$(path_expand "$localstatedir")
267 e_pkglibexecdir=$(path_expand "$pkglibexecdir")
268 echo "prefix=$e_prefix"
269 echo "eprefix=$e_eprefix"
270 echo "bin=$e_bindir"
271 echo "libdir=$e_libdir"
272 echo "includedir=$e_includedir"
273 echo "sysconfdir=$e_sysconfdir"
274 echo "localstatedir=$e_localstatedir"
275 echo "pkglibexecdir=$e_pkglibexecdir"
276 sep_end
277
278 ################################################################################
279
280 mkdir -p -- ./src
281 printf "#ifndef PATH_H\n#define PATH_H\n#define _PATH_LOCALSTATEDIR \"%b\"\n#endif" "$e_localstatedir" >./src/uuid_paths.h
282
283 ################################################################################
284
285 . $src_path/make.libuuid.sh
286 if test x$libuuid_only != xyes; then
287 . $src_path/make.uuidgen.sh
288 fi
289
290 ################################################################################
291
292
293
294
295 exit
296
297
298
299 libudev_api=0
300 fake_root=fake_root
301
302 #-------------------------------------------------------------------------------
303 libudev_src_files='
304 libudev.c
305 libudev-device.c
306 libudev-device-private.c
307 libudev-enumerate.c
308 libudev-list.c
309 libudev-monitor.c
310 libudev-queue.c
311 libudev-queue-private.c
312 libudev-util.c
313 libudev-util-private.c
314 '
315
316 udevd_common_src_files='
317 udev-event.c
318 udev-watch.c
319 udev-node.c
320 udev-rules.c
321 udev-ctrl.c
322 udev-builtin.c
323 udev-builtin-blkid.c
324 udev-builtin-hwdb.c
325 udev-builtin-input_id.c
326 udev-builtin-kmod.c
327 udev-builtin-path_id.c
328 udev-builtin-usb_id.c
329 '
330
331 udevd_src_files='
332 udevd.c
333 '
334
335 udevadm_src_files='
336 udevadm.c
337 udevadm-info.c
338 udevadm-control.c
339 udevadm-monitor.c
340 udevadm-settle.c
341 udevadm-trigger.c
342 udevadm-test.c
343 udevadm-test-builtin.c
344 '
345
346 #-------------------------------------------------------------------------------
347
348 clean_do()
349 {
350 all_src_files="$libudev_src_files $udevd_common_src_files $udevd_src_files $udevadm_src_files"
351
352 rm -Rf "$fake_root"
353 for src_file in $all_src_files
354 do
355 pp_file=${src_file%.c}
356 pp_file=${pp_file}.pp.c
357 rm -f ${pp_file}
358 o_file=${src_file%.c}
359 o_file=${o_file}.o
360 rm -f ${o_file}
361 #clean directories, but keep root of build tree
362 tgt_dir=$(dirname $src_file)
363 if test -d $tgt_dir -a "$tgt_dir" != "."; then
364 rmdir --ignore-fail-on-non-empty -p $tgt_dir
365 fi
366 done
367 exit 0
368 }
369
370 sep_start()
371 {
372 printf '###############################################################################\n'
373 }
374
375 sep_end()
376 {
377 printf '###############################################################################\n\n'
378 }
379
380 subsep_start()
381 {
382 printf '*******************************************************************************\n'
383 }
384
385 subsep_end()
386 {
387 printf '*******************************************************************************\n'
388 }
389
390 ################################################################################
391
392 is_in(){
393 value=$1
394 shift
395 for var in $*; do
396 [ $var = $value ] && return 0
397 done
398 return 1
399 }
400
401 die_unknown(){
402 echo "Unknown option \"$1\"."
403 echo "See $0 --help for available options."
404 exit 1
405 }
406
407 set_default(){
408 for opt; do
409 eval : \${$opt:=\$${opt}_default}
410 done
411 }
412
413 CMDLINE_SET='
414 bin_cpp
415 bin_cc
416 bin_ccld
417 libudev_cpp
418 libudev_cc
419 libudev_ar
420 dbin_cpp
421 dbin_cc
422 dbin_ccld
423 slibudev_cpp
424 slibudev_cc
425 slibudev_ccld
426 prefix
427 eprefix
428 libdir
429 includedir
430 sysconfdir
431 pkglibexecdir
432 usb_database
433 pci_database
434 version
435 '
436
437 ################################################################################
438
439 #command line set defaults
440 #-------------------------------------------------------------------------------
441 #This defaults are for gcc, tested with version 4.7.3. You will need to
442 #override those for you compiler (tinycc/open64/pcc...). Additionnally, source
443 #support for different toolchains is not done.
444 #The right way to do it is to have a toolchain abstraction layer since there are
445 #no accurate enough standards
446 bin_cpp_default='gcc -E -D_GNU_SOURCE'
447 bin_cc_default='gcc -Wno-unused-parameter -Wno-missing-field-initializers -std=gnu99 -O2 -c'
448 bin_ccld_default='gcc -static'
449
450 libudev_cpp_default='gcc -E -D_GNU_SOURCE'
451 libudev_cc_default='gcc -Wno-unused-parameter -std=gnu99 -O2 -fPIC -c'
452 libudev_ar_default="ar rcs"
453
454 dbin_cpp_default='gcc -E -D_GNU_SOURCE'
455 dbin_cc_default='gcc -Wno-unused-parameter -Wno-missing-field-initializers -std=gnu99 -O2 -c'
456 dbin_ccld_default='gcc'
457
458 slibudev_cpp_default='gcc -E -D_GNU_SOURCE'
459 slibudev_cc_default='gcc -Wno-unused-parameter -std=gnu99 -O2 -fPIC -c'
460 slibudev_ccld_default="gcc -shared -Wl,-h,libudev.so.$libudev_api -lc -lrt"
461 #-------------------------------------------------------------------------------
462
463 prefix_default=/usr/local
464 eprefix_default='$prefix'
465 libdir_default='$eprefix/lib'
466 includedir_default='$prefix/include'
467 sysconfdir_default='$prefix/etc'
468 pkglibexecdir_default='$libdir/udev'
469 #MUST PUT A / AT THE END OR WON'T WORK!
470 usb_database_default='$prefix/share/hwdata/usb.ids'
471 pci_database_default='$prefix/share/hwdata/pci.ids'
472 version_default=189
473 set_default $CMDLINE_SET
474
475 libudev_only=no
476 disable_static=no
477 disable_dynamic=no
478
479 ################################################################################
480
481 show_help(){
482 cat <<EOF
483 Usage: make [options] [operations]
484
485 Operations: [default is to build libudev, udevd and udevadm]:
486 clean clean build products
487
488 Options: [defaults in brackets after descriptions]
489
490 Help options:
491 --help print this message
492
493 Standard options:
494 --libudev-only build only libudev
495 --disable-static disable the build of static lib and static binaries
496 --disable-shared disable the build of shared libs and dynamic binaries
497 --enable-logging enable logging code paths
498 --enable-debug enable debug code paths
499
500 --prefix=PREFIX architecture independent prefix [$prefix_default]
501 --eprefix=EPREFIX architecture dependent exec prefix [$eprefix_default]
502 --libdir=DIR object code libraries [$libdir_default]
503 --includedir=DIR C header files [$includedir_default]
504 --sysconfdir=DIR read-only single-machine data [$sysconfdir_default]
505 --pkglibexecdir=DIR program executables [$pkglibexecdir_default]
506
507 --usb-database=FILE_PATH the usb database path [$usb_database_default]
508 --pci-databased=FILE_PATH the pci database path [$pci_database_default]
509
510 --version=VERSION override the version number [$version_default]
511
512 --man build man pages
513
514 Advanced options:
515 --bin-cpp=CPP use CPP compiler command line CPP for static target binaries [$bin_cpp_default]
516 --bin-cc=CC use C compiler command line CC for static target binaries [$bin_cc_default]
517 --bin-ccld=CCLD use linker command line CCLD for static target binaries [$bin_ccld_default]
518
519 --dbin-cpp=CPP use CPP compiler command line CPP for dynamic target binaries [$dbin_cpp_default]
520 --dbin-cc=CC use C compiler command line CC for dynamic target binaries [$dbin_cc_default]
521 --dbin-ccld=CCLD use linker command line CCLD for dynamic target binaries [$dbin_ccld_default]
522
523 --libudev-cpp=CPP use CPP compiler command line CPP for static target libudev [$libudev_cpp_default]
524 --libudev-cc=CC use C compiler command line CC for static target libudev [$libudev_cc_default]
525 --libudev-ar=AR use archive command line AR for static target libudev [$libudev_ar_default]
526
527 --slibudev-cpp=CPP use CPP compiler command line CPP for shared target libudev [$slibudev_cpp_default]
528 --slibudev-cc=CC use C compiler command line CC for shared target libudev [$slibudev_cc_default]
529 --slibudev-ccld=CCLD use linker command line CCLD for shared target libudev [$slibudev_ccld_default]
530 EOF
531 exit 0
532 }
533
534 ################################################################################
535
536 for opt do
537 optval="${opt#*=}"
538 case "$opt" in
539 clean) clean_do
540 ;;
541 --help|-h) show_help
542 ;;
543 --enable-logging)
544 INTERNAL_CPPFLAGS="$INTERNAL_CPPFLAGS -DENABLE_LOGGING"
545 ;;
546 --enable-debug)
547 INTERNAL_CPPFLAGS="$INTERNAL_CPPFLAGS -DENABLE_DEBUG"
548 ;;
549 --libudev-only)
550 libudev_only=yes
551 ;;
552 --disable-static)
553 disable_static=yes
554 ;;
555 --disable-dynamic)
556 disable_dynamic=yes
557 ;;
558 --man)
559 MAN=yes
560 ;;
561 *)
562 optname=${opt%%=*}
563 optname=${optname#--}
564 optname=$(echo "$optname" | sed 's/-/_/g')
565 if is_in $optname $CMDLINE_SET; then
566 eval $optname='$optval'
567 else
568 die_unknown $opt
569 fi
570 ;;
571 esac
572 done
573
574 ################################################################################
575
576 path_expand()
577 {
578 e_v=$1
579 #we set a maximum expansion depth of 3
580 for d in 1 2 3
581 do
582 e_v=$(eval echo "$e_v")
583 done
584 #get rid of ugly double // in path
585 echo "$e_v" | sed -e 's%//%/%g'
586 }
587
588 sep_start;echo 'expanding final paths:'
589 e_prefix=$(path_expand "$prefix")
590 e_eprefix=$(path_expand "$eprefix")
591 e_libdir=$(path_expand "$libdir")
592 e_includedir=$(path_expand "$includedir")
593 e_sysconfdir=$(path_expand "$sysconfdir")
594 e_pkglibexecdir=$(path_expand "$pkglibexecdir")
595 e_usb_database=$(path_expand "$usb_database")
596 e_pci_database=$(path_expand "$pci_database")
597 echo "prefix=$e_prefix"
598 echo "eprefix=$e_eprefix"
599 echo "libdir=$e_libdir"
600 echo "includedir=$e_includedir"
601 echo "sysconfdir=$e_sysconfdir"
602 echo "pkglibexecdir=$e_pkglibexecdir"
603 echo "usb_database=$e_usb_database"
604 echo "pci_database=$e_pci_database"
605 sep_end
606
607 ################################################################################
608
609 sep_start;echo 'looking for source path:'
610 if test -f make; then
611 src_path=.
612 else
613 src_path=$(cd $(dirname "$0"); pwd)
614 echo "$src_path" | grep -q '[[:blank:]]' &&
615 die "out of tree builds are impossible with whitespace in source path."
616 test -e "$src_path/config.h" &&
617 die "out of tree builds are impossible with config.h in source dir."
618 fi
619 echo "source path is $src_path";sep_end
620
621 ################################################################################
622
623 INTERNAL_CPPFLAGS="$INTERNAL_CPPFLAGS -DSYSCONFDIR=\"$e_sysconfdir\""
624 INTERNAL_CPPFLAGS="$INTERNAL_CPPFLAGS -DPKGLIBEXECDIR=\"$e_pkglibexecdir\""
625 INTERNAL_CPPFLAGS="$INTERNAL_CPPFLAGS -DUSB_DATABASE=\"$e_usb_database\""
626 INTERNAL_CPPFLAGS="$INTERNAL_CPPFLAGS -DPCI_DATABASE=\"$e_pci_database\""
627 INTERNAL_CPPFLAGS="$INTERNAL_CPPFLAGS -DVERSION=\"$e_version\""
628
629 ################################################################################
630
631 . $src_path/make.libudev.sh
632 if test x$libudev_only != xyes; then
633 . $src_path/make.udevd_all.sh
634 fi
635
636 ################################################################################
637
638 mkdir -p -- "$fake_root/$e_libdir/pkgconfig"
639
640 if test x$libudev_only != xyes; then
641 sep_start;echo 'generating pkg-config file for udev'
642 cp -f $src_path/src/udev.pc.in "$fake_root/$e_libdir/pkgconfig/udev.pc"
643 sed -i "s%@VERSION@%$version%" "$fake_root/$e_libdir/pkgconfig/udev.pc"
644 sed -i "s%@pkglibexecdir@%$e_pkglibexecdir%" "$fake_root/$e_libdir/pkgconfig/udev.pc"
645 sep_end
646 fi
647
648 sep_start;echo 'generating pkg-config file for libudev'
649 cp -f $src_path/src/libudev.pc.in "$fake_root/$e_libdir/pkgconfig/libudev.pc"
650 sed -i "s%@VERSION@%$version%" "$fake_root/$e_libdir/pkgconfig/libudev.pc"
651 sed -i "s%@prefix@%$e_prefix%" "$fake_root/$e_libdir/pkgconfig/libudev.pc"
652 sed -i "s%@exec_prefix@%$e_eprefix%" "$fake_root/$e_libdir/pkgconfig/libudev.pc"
653 sed -i "s%@libdir@%$e_libdir%" "$fake_root/$e_libdir/pkgconfig/libudev.pc"
654 sed -i "s%@includedir@%$e_includedir%" "$fake_root/$e_libdir/pkgconfig/libudev.pc"
655 sep_end
656
657 ################################################################################
658
659 if test x$libudev_only != xyes; then
660 sep_start;echo 'fake installing the system udev rules'
661 mkdir -p -- "$fake_root/$e_pkglibexecdir"
662 rm -Rf -- "$fake_root/$e_pkglibexecdir/rules.d"
663 cp -rf -- "$src_path/rules" "$fake_root/$e_pkglibexecdir/rules.d"
664 sep_end
665 fi
666
667 ################################################################################
668
669 if [ -z "$MAN" ]; then
670 exit 0
671 fi
672 #hardly tested...
673 sep_start;echo 'generating man pages'
674 mkdir -p -- "$fake_root/$e_prefix/share/man8" "$fake_root/$e_prefix/share/man7"
675 xsltproc -o "$fake_root/$e_prefix/share/man7/udev.7" -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl "$src_path/src/udev.xml"
676 xsltproc -o "$fake_root/$e_prefix/share/man8/udevadm.8" -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl "$src_path/src/udevadm.xml"
677 xsltproc -o "$fake_root/$e_prefix/share/man8/udevd.8" -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl "$src_path/src/udev.xml"
678 sep_end
File make.libuuid.sh added (mode: 100644) (index 0000000..63d0ae4)
1 if test x$disable_dynamic = xno; then
2 ################################################################################
3 sep_start;echo 'slibuuid:compile src files'
4 for libuuid_src_file in $libuuid_src_files
5 do
6 slibuuid_o_file=${libuuid_src_file%.c}
7 slibuuid_o_file_name=$(basename $slibuuid_o_file)
8 slibuuid_o_file=$(dirname $slibuuid_o_file)/s${slibuuid_o_file_name}.o
9
10 echo "SLIBUUID_CC $libuuid_src_file-->$slibuuid_o_file"
11 mkdir -p -- $(dirname $slibuuid_o_file)
12
13 $slibuuid_cc -o $slibuuid_o_file \
14 -I./src \
15 -I$src_path/src/utils \
16 $src_path/$libuuid_src_file
17
18 slibuuid_o_files="$slibuuid_o_file $slibuuid_o_files"
19 done
20 sep_end
21
22 #-------------------------------------------------------------------------------
23
24 sep_start;echo 'slibuuid:link the object files to produce the shared library'
25 echo "SLIBUUID_CCLD libuuid.so.$libuuid_so_version"
26 mkdir -p -- $fake_root/$e_libdir
27
28 $slibuuid_ccld -o $fake_root/$e_libdir/libuuid.so.$libuuid_so_version \
29 $slibuuid_o_files
30
31 ln -sf libuuid.so.$libuuid_so_version \
32 $fake_root/$e_libdir/libuuid.so.$libuuid_api
33 ln -sf libuuid.so.$libuuid_api \
34 $fake_root/$e_libdir/libuuid.so
35 sep_end
36 ################################################################################
37 fi
38
39
40 if test x$disable_static = xno; then
41 ################################################################################
42 sep_start;echo 'libuuid:compile src files'
43 for libuuid_src_file in $libuuid_src_files
44 do
45 libuuid_o_file=${libuuid_src_file%.c}
46 libuuid_o_file=${libuuid_o_file}.o
47
48 echo "LIBUUID_CC $libuuid_src_file-->$libuuid_o_file"
49 mkdir -p -- $(dirname $libuuid_o_file)
50
51 $libuuid_cc -o $libuuid_o_file \
52 -I./src \
53 -I$src_path/src/utils \
54 $src_path/$libuuid_src_file
55
56 libuuid_o_files="$libuuid_o_file $libuuid_o_files"
57 done
58 sep_end
59
60 #-------------------------------------------------------------------------------
61
62 sep_start;echo 'libuuid:archive the object files to produce the static library'
63 echo "LIBUUID_AR libuuid.a"
64 mkdir -p -- $fake_root/$e_libdir
65
66 rm -f $fake_root/$e_libdir/libuuid.a
67
68 $libuuid_ar $fake_root/$e_libdir/libuuid.a \
69 $libuuid_o_files
70 sep_end
71 ################################################################################
72 fi
73
74 sep_start;echo 'libuuid:fake installing headers'
75 mkdir -p -- $fake_root/$e_includedir
76 cp -f $src_path/src/uuid.h $fake_root/$e_includedir
77 sep_end
File make.uuidgen.sh added (mode: 100644) (index 0000000..bca2ae9)
1 if test x$disable_dynamic = xno; then
2 ################################################################################
3 sep_start;echo 'duuidgen:compile src files'
4 for uuidgen_src_file in $uuidgen_src_files
5 do
6 duuidgen_o_file=${uuidgen_src_file%.c}
7 duuidgen_o_file_name=$(basename $duuidgen_o_file)
8 duuidgen_o_file=$(dirname $duuidgen_o_file)/d${duuidgen_o_file_name}.o
9
10 echo "DBIN_CC $uuidgen_src_file-->$duuidgen_o_file"
11 mkdir -p -- $(dirname $duuidgen_o_file)
12
13 $dbin_cc -o $duuidgen_o_file \
14 -I./src \
15 -I$fake_root/$e_includedir \
16 -I$src_path/src/ \
17 -I$src_path/src/utils \
18 $src_path/$uuidgen_src_file
19
20 duuidgen_o_files="$duuidgen_o_file $duuidgen_o_files"
21 done
22 sep_end
23
24 #-------------------------------------------------------------------------------
25
26 mkdir -p -- $fake_root/${e_bindir}d
27
28 #-------------------------------------------------------------------------------
29
30 sep_start;echo 'duuidgen:link the object files to produce the dynamic binary'
31 echo "DBIN_CCLD uuidgen"
32 $dbin_ccld -o $fake_root/${e_bindir}d/uuidgen \
33 $duuidgen_o_files \
34 $fake_root/$e_libdir/libuuid.so.$libuuid_so_version
35 sep_end
36
37 ################################################################################
38 fi
39
40
41 if test x$disable_static = xno; then
42 ################################################################################
43 sep_start;echo 'uuidgen:compile src files'
44 for uuidgen_src_file in $uuidgen_src_files
45 do
46 uuidgen_o_file=${uuidgen_src_file%.c}
47 uuidgen_o_file=${uuidgen_o_file}.o
48
49 echo "BIN_CC $uuidgen_src_file-->$uuidgen_o_file"
50 mkdir -p -- $(dirname $uuidgen_o_file)
51
52 $bin_cc -o $uuidgen_o_file \
53 -I./src \
54 -I$src_path/src/ \
55 -I$fake_root/$e_includedir \
56 -I$src_path/src/utils \
57 $src_path/$uuidgen_src_file
58
59 uuidgen_o_files="$uuidgen_o_file $uuidgen_o_files"
60 done
61 sep_end
62
63 #-------------------------------------------------------------------------------
64
65 mkdir -p -- $fake_root/$e_bindir
66
67 #-------------------------------------------------------------------------------
68
69 sep_start;echo 'uuidgen:link the object files to produce the static binary'
70 echo "BIN_CCLD uuidgen"
71 $bin_ccld -o $fake_root/$e_bindir/uuidgen \
72 $uuidgen_o_files \
73 $fake_root/$e_libdir/libuuid.a
74 sep_end
75 ################################################################################
76 fi
File src/clear.c added (mode: 100644) (index 0000000..a665260)
1 /*
2 * clear.c -- Clear a UUID
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #include "namespace.h"
38 #include "string.h"
39
40 #include "uuidP.h"
41
42 void uuid_clear(uuid_t uu)
43 {
44 memset(uu, 0, 16);
45 }
46
File src/compare.c added (mode: 100644) (index 0000000..5ca1b46)
1 /*
2 * compare.c --- compare whether or not two UUIDs are the same
3 *
4 * Returns 0 if the two UUIDs are different, and 1 if they are the same.
5 *
6 * Copyright (C) 1996, 1997 Theodore Ts'o.
7 *
8 * %Begin-Header%
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, and the entire permission notice in its entirety,
14 * including the disclaimer of warranties.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote
19 * products derived from this software without specific prior
20 * written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
25 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
33 * DAMAGE.
34 * %End-Header%
35 */
36
37 #include "config.h"
38
39 #include "namespace.h"
40 #include "uuidP.h"
41 #include <string.h>
42
43 #define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1);
44
45 int uuid_compare(const uuid_t uu1, const uuid_t uu2)
46 {
47 struct uuid uuid1, uuid2;
48
49 uuid_unpack(uu1, &uuid1);
50 uuid_unpack(uu2, &uuid2);
51
52 UUCMP(uuid1.time_low, uuid2.time_low);
53 UUCMP(uuid1.time_mid, uuid2.time_mid);
54 UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
55 UUCMP(uuid1.clock_seq, uuid2.clock_seq);
56 return memcmp(uuid1.node, uuid2.node, 6);
57 }
58
File src/config.h added (mode: 100644) (index 0000000..5576a08)
1 /* config.h. Generated from config.h.in by configure. */
2 /* config.h.in. Generated from configure.ac by autoheader. */
3
4 #include "uuid_paths.h"
5
6 /* Define if building universal (internal helper macro) */
7 /* #undef AC_APPLE_UNIVERSAL_BUILD */
8
9 /* Enable agetty --reload feature */
10 #define AGETTY_RELOAD 1
11
12 /* Should chfn and chsh require the user to enter the password? */
13 #define CHFN_CHSH_PASSWORD 1
14
15 /* Path to hwclock adjtime file */
16 #define CONFIG_ADJTIME_PATH "/etc/adjtime"
17
18 /* Define to 1 if translation of program messages to the user's native
19 language is requested. */
20 /* #undef ENABLE_NLS */
21
22 /* search path for fs helpers */
23 #define FS_SEARCH_PATH "/sbin:/sbin/fs.d:/sbin/fs:/bin"
24
25 /* Define to 1 if you have the <asm/io.h> header file. */
26 /* #undef HAVE_ASM_IO_H */
27
28 /* Define if btrfs stuff is available */
29 #define HAVE_BTRFS_SUPPORT 1
30
31 /* Define to 1 if you have the <byteswap.h> header file. */
32 #define HAVE_BYTESWAP_H 1
33
34 /* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the
35 CoreFoundation framework. */
36 /* #undef HAVE_CFLOCALECOPYCURRENT */
37
38 /* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
39 the CoreFoundation framework. */
40 /* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
41
42 /* Define to 1 if you have the `clock_gettime' function. */
43 #define HAVE_CLOCK_GETTIME 1
44
45 /* Define to 1 if the system has the type `cpu_set_t'. */
46 #define HAVE_CPU_SET_T 1
47
48 /* Define to 1 if you have the <crypt.h> header file. */
49 #define HAVE_CRYPT_H 1
50
51 /* Define if the GNU dcgettext() function is already present or preinstalled.
52 */
53 /* #undef HAVE_DCGETTEXT */
54
55 /* Define to 1 if you have the declaration of `CPU_ALLOC', and to 0 if you
56 don't. */
57 #define HAVE_DECL_CPU_ALLOC 1
58
59 /* Define to 1 if you have the declaration of `dirfd', and to 0 if you don't.
60 */
61 /* #undef HAVE_DECL_DIRFD */
62
63 /* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
64 */
65 /* #undef HAVE_DECL_TZNAME */
66
67 /* Define to 1 if you have the declaration of `_NL_TIME_WEEK_1STDAY', and to 0
68 if you don't. */
69 #define HAVE_DECL__NL_TIME_WEEK_1STDAY 1
70
71 /* Define to 1 if you have the `dirfd' function. */
72 #define HAVE_DIRFD 1
73
74 /* Define to 1 if `dd_fd' is a member of `DIR'. */
75 /* #undef HAVE_DIR_DD_FD */
76
77 /* Define to 1 if you have the <dlfcn.h> header file. */
78 #define HAVE_DLFCN_H 1
79
80 /* Define to 1 if you have the <endian.h> header file. */
81 #define HAVE_ENDIAN_H 1
82
83 /* Define to 1 if have **environ prototype */
84 #define HAVE_ENVIRON_DECL 1
85
86 /* Define to 1 if you have the `err' function. */
87 #define HAVE_ERR 1
88
89 /* Define to 1 if you have the <errno.h> header file. */
90 #define HAVE_ERRNO_H 1
91
92 /* Define to 1 if you have the `errx' function. */
93 #define HAVE_ERRX 1
94
95 /* Define to 1 if you have the <err.h> header file. */
96 #define HAVE_ERR_H 1
97
98 /* Define to 1 if you have the `explicit_bzero' function. */
99 #define HAVE_EXPLICIT_BZERO 1
100
101 /* Have valid fallocate() function */
102 #define HAVE_FALLOCATE 1
103
104 /* Define to 1 if you have the <fcntl.h> header file. */
105 #define HAVE_FCNTL_H 1
106
107 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
108 #define HAVE_FSEEKO 1
109
110 /* Define to 1 if you have the `fstatat' function. */
111 #define HAVE_FSTATAT 1
112
113 /* Define to 1 if you have the `fsync' function. */
114 #define HAVE_FSYNC 1
115
116 /* Define to 1 if you have the `futimens' function. */
117 #define HAVE_FUTIMENS 1
118
119 /* Define to 1 if you have the `getdomainname' function. */
120 #define HAVE_GETDOMAINNAME 1
121
122 /* Define to 1 if you have the `getdtablesize' function. */
123 #define HAVE_GETDTABLESIZE 1
124
125 /* Define to 1 if you have the `getexecname' function. */
126 /* #undef HAVE_GETEXECNAME */
127
128 /* Define to 1 if you have the `getmntinfo' function. */
129 /* #undef HAVE_GETMNTINFO */
130
131 /* Define to 1 if you have the <getopt.h> header file. */
132 #define HAVE_GETOPT_H 1
133
134 /* Define to 1 if you have the `getrandom' function. */
135 #define HAVE_GETRANDOM 1
136
137 /* Define to 1 if you have the `getrlimit' function. */
138 #define HAVE_GETRLIMIT 1
139
140 /* Define to 1 if you have the `getsgnam' function. */
141 #define HAVE_GETSGNAM 1
142
143 /* Define if the GNU gettext() function is already present or preinstalled. */
144 /* #undef HAVE_GETTEXT */
145
146 /* Define if you have the iconv() function and it works. */
147 /* #undef HAVE_ICONV */
148
149 /* Define to 1 if you have the `inotify_init' function. */
150 #define HAVE_INOTIFY_INIT 1
151
152 /* Define to 1 if you have the `inotify_init1' function. */
153 #define HAVE_INOTIFY_INIT1 1
154
155 /* Define to 1 if you have the <inttypes.h> header file. */
156 #define HAVE_INTTYPES_H 1
157
158 /* Define to 1 if you have the `ioperm' function. */
159 #define HAVE_IOPERM 1
160
161 /* Define to 1 if you have the `iopl' function. */
162 #define HAVE_IOPL 1
163
164 /* Define to 1 if you have the `isnan' function. */
165 #define HAVE_ISNAN 1
166
167 /* Define to 1 if you have the `jrand48' function. */
168 #define HAVE_JRAND48 1
169
170 /* Define to 1 if you have the <langinfo.h> header file. */
171 #define HAVE_LANGINFO_H 1
172
173 /* Define to 1 if you have the <lastlog.h> header file. */
174 #define HAVE_LASTLOG_H 1
175
176 /* Define to 1 if you have the `lchown' function. */
177 #define HAVE_LCHOWN 1
178
179 /* Define to 1 if you have the `audit' library (-laudit). */
180 /* #undef HAVE_LIBAUDIT */
181
182 /* Define to 1 if you have the -lblkid. */
183 #define HAVE_LIBBLKID 1
184
185 /* Define to 1 if you have the `cap-ng' library (-lcap-ng). */
186 /* #undef HAVE_LIBCAP_NG */
187
188 /* Do we need -lcrypt? */
189 #define HAVE_LIBCRYPT 1
190
191 /* Define if libmount available. */
192 #define HAVE_LIBMOUNT 1
193
194 /* Define if ncurses library available */
195 #define HAVE_LIBNCURSES 1
196
197 /* Define if ncursesw library available */
198 /* #undef HAVE_LIBNCURSESW */
199
200 /* Define to 1 if you have the `readline' library (-lreadline). */
201 /* #undef HAVE_LIBREADLINE */
202
203 /* Define if librtas exists */
204 /* #undef HAVE_LIBRTAS */
205
206 /* Define if SELinux is available */
207 /* #undef HAVE_LIBSELINUX */
208
209 /* Define if libsystemd is available */
210 /* #undef HAVE_LIBSYSTEMD */
211
212 /* Define if libtinfo available. */
213 /* #undef HAVE_LIBTINFO */
214
215 /* Define to 1 if you have the `udev' library (-ludev). */
216 /* #undef HAVE_LIBUDEV */
217
218 /* Define if libuser is available */
219 /* #undef HAVE_LIBUSER */
220
221 /* Define to 1 if you have the `utempter' library (-lutempter). */
222 /* #undef HAVE_LIBUTEMPTER */
223
224 /* Define to 1 if you have the `util' library (-lutil). */
225 #define HAVE_LIBUTIL 1
226
227 /* Define to 1 if you have the <libutil.h> header file. */
228 /* #undef HAVE_LIBUTIL_H */
229
230 /* Define to 1 if you have the -luuid. */
231 #define HAVE_LIBUUID 1
232
233 /* Define to 1 if you have the <linux/blkpg.h> header file. */
234 #define HAVE_LINUX_BLKPG_H 1
235
236 /* Define to 1 if you have the <linux/blkzoned.h> header file. */
237 #define HAVE_LINUX_BLKZONED_H 1
238
239 /* Define to 1 if you have the <linux/btrfs.h> header file. */
240 #define HAVE_LINUX_BTRFS_H 1
241
242 /* Define to 1 if you have the <linux/cdrom.h> header file. */
243 #define HAVE_LINUX_CDROM_H 1
244
245 /* Define to 1 if you have the <linux/compiler.h> header file. */
246 /* #undef HAVE_LINUX_COMPILER_H */
247
248 /* Define to 1 if you have the <linux/falloc.h> header file. */
249 #define HAVE_LINUX_FALLOC_H 1
250
251 /* Define to 1 if you have the <linux/fd.h> header file. */
252 #define HAVE_LINUX_FD_H 1
253
254 /* Define to 1 if you have the <linux/gsmmux.h> header file. */
255 #define HAVE_LINUX_GSMMUX_H 1
256
257 /* Define to 1 if you have the <linux/major.h> header file. */
258 #define HAVE_LINUX_MAJOR_H 1
259
260 /* Define to 1 if you have the <linux/raw.h> header file. */
261 #define HAVE_LINUX_RAW_H 1
262
263 /* Define to 1 if you have the <linux/securebits.h> header file. */
264 #define HAVE_LINUX_SECUREBITS_H 1
265
266 /* Define to 1 if you have the <linux/tiocl.h> header file. */
267 #define HAVE_LINUX_TIOCL_H 1
268
269 /* Define to 1 if you have the <linux/version.h> header file. */
270 #define HAVE_LINUX_VERSION_H 1
271
272 /* Define to 1 if you have the <linux/watchdog.h> header file. */
273 #define HAVE_LINUX_WATCHDOG_H 1
274
275 /* Define to 1 if you have the `llseek' function. */
276 #define HAVE_LLSEEK 1
277
278 /* Define to 1 if have llseek prototype */
279 /* #undef HAVE_LLSEEK_PROTOTYPE */
280
281 /* Define to 1 if you have the <locale.h> header file. */
282 #define HAVE_LOCALE_H 1
283
284 /* Define to 1 if the system has the type `loff_t'. */
285 #define HAVE_LOFF_T 1
286
287 /* Define to 1 if you have the `lseek64' function. */
288 #define HAVE_LSEEK64 1
289
290 /* Define to 1 if have lseek64 prototype */
291 #define HAVE_LSEEK64_PROTOTYPE 1
292
293 /* Define to 1 if you have the <memory.h> header file. */
294 #define HAVE_MEMORY_H 1
295
296 /* Define to 1 if you have the `mempcpy' function. */
297 #define HAVE_MEMPCPY 1
298
299 /* Define to 1 if you have the `mkostemp' function. */
300 #define HAVE_MKOSTEMP 1
301
302 /* Define to 1 if you have the <mntent.h> header file. */
303 #define HAVE_MNTENT_H 1
304
305 /* Define to 1 if you have the `nanosleep' function. */
306 #define HAVE_NANOSLEEP 1
307
308 /* Define to 1 if you have the <ncursesw/ncurses.h> header file. */
309 /* #undef HAVE_NCURSESW_NCURSES_H */
310
311 /* Define to 1 if you have the <ncursesw/term.h> header file. */
312 /* #undef HAVE_NCURSESW_TERM_H */
313
314 /* Define to 1 if you have the <ncurses.h> header file. */
315 #define HAVE_NCURSES_H 1
316
317 /* Define to 1 if you have the <ncurses/ncurses.h> header file. */
318 /* #undef HAVE_NCURSES_NCURSES_H */
319
320 /* Define to 1 if you have the <ncurses/term.h> header file. */
321 /* #undef HAVE_NCURSES_TERM_H */
322
323 /* Define to 1 if you have the <netinet/in.h> header file. */
324 #define HAVE_NETINET_IN_H 1
325
326 /* Define to 1 if you have the <net/if_dl.h> header file. */
327 /* #undef HAVE_NET_IF_DL_H */
328
329 /* Define to 1 if you have the <net/if.h> header file. */
330 #define HAVE_NET_IF_H 1
331
332 /* Define to 1 if you have the `ntp_gettime' function. */
333 #define HAVE_NTP_GETTIME 1
334
335 /* Define to 1 if you have the `openat' function. */
336 #define HAVE_OPENAT 1
337
338 /* Define to 1 if you have the `open_memstream' function. */
339 #define HAVE_OPEN_MEMSTREAM 1
340
341 /* Define to 1 if you have the <paths.h> header file. */
342 #define HAVE_PATHS_H 1
343
344 /* Define to 1 if you have the `personality' function. */
345 #define HAVE_PERSONALITY 1
346
347 /* Define to 1 if you have the `posix_fadvise' function. */
348 #define HAVE_POSIX_FADVISE 1
349
350 /* Have valid posix_fallocate() function */
351 #define HAVE_POSIX_FALLOCATE 1
352
353 /* Define to 1 if you have the `prctl' function. */
354 #define HAVE_PRCTL 1
355
356 /* Define to 1 if you have the `prlimit' function. */
357 #define HAVE_PRLIMIT 1
358
359 /* Define if program_invocation_short_name is defined */
360 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME 1
361
362 /* Define to 1 if you have the <pty.h> header file. */
363 #define HAVE_PTY_H 1
364
365 /* Define to 1 if you have the `qsort_r' function. */
366 #define HAVE_QSORT_R 1
367
368 /* Define to 1 if you have the `reboot' function. */
369 #define HAVE_REBOOT 1
370
371 /* Define if curses library has the resizeterm(). */
372 /* #undef HAVE_RESIZETERM */
373
374 /* Define to 1 if you have the `rpmatch' function. */
375 #define HAVE_RPMATCH 1
376
377 /* Define if struct sockaddr contains sa_len */
378 /* #undef HAVE_SA_LEN */
379
380 /* Define to 1 if you have the `scandirat' function. */
381 #define HAVE_SCANDIRAT 1
382
383 /* scanf %as modifier */
384 /* #undef HAVE_SCANF_AS_MODIFIER */
385
386 /* scanf %ms modifier */
387 #define HAVE_SCANF_MS_MODIFIER 1
388
389 /* Define to 1 if you have the `sched_setattr' function. */
390 /* #undef HAVE_SCHED_SETATTR */
391
392 /* Define to 1 if you have the `sched_setscheduler' function. */
393 #define HAVE_SCHED_SETSCHEDULER 1
394
395 /* Define to 1 if you have the `secure_getenv' function. */
396 #define HAVE_SECURE_GETENV 1
397
398 /* Define to 1 if you have the `security_get_initial_context' function. */
399 /* #undef HAVE_SECURITY_GET_INITIAL_CONTEXT */
400
401 /* Define to 1 if you have the <security/openpam.h> header file. */
402 /* #undef HAVE_SECURITY_OPENPAM_H */
403
404 /* Define to 1 if you have the <security/pam_appl.h> header file. */
405 /* #undef HAVE_SECURITY_PAM_APPL_H */
406
407 /* Define to 1 if you have the <security/pam_misc.h> header file. */
408 /* #undef HAVE_SECURITY_PAM_MISC_H */
409
410 /* Define to 1 if you have the `setns' function. */
411 #define HAVE_SETNS 1
412
413 /* Define to 1 if you have the `setprogname' function. */
414 /* #undef HAVE_SETPROGNAME */
415
416 /* Define to 1 if you have the `setresgid' function. */
417 #define HAVE_SETRESGID 1
418
419 /* Define to 1 if you have the `setresuid' function. */
420 #define HAVE_SETRESUID 1
421
422 /* Define to 1 if you have the <shadow.h> header file. */
423 #define HAVE_SHADOW_H 1
424
425 /* Define to 1 if the system has the type `sighandler_t'. */
426 #define HAVE_SIGHANDLER_T 1
427
428 /* Define to 1 if you have the `sigqueue' function. */
429 #define HAVE_SIGQUEUE 1
430
431 /* Define to 1 if you have the <slang.h> header file. */
432 /* #undef HAVE_SLANG_H */
433
434 /* Define to 1 if you have the <slang/slang.h> header file. */
435 /* #undef HAVE_SLANG_SLANG_H */
436
437 /* Define to 1 if you have the <slang/slcurses.h> header file. */
438 /* #undef HAVE_SLANG_SLCURSES_H */
439
440 /* Define to 1 if you have the <slcurses.h> header file. */
441 /* #undef HAVE_SLCURSES_H */
442
443 /* Add SMACK support */
444 /* #undef HAVE_SMACK */
445
446 /* Define to 1 if you have the `srandom' function. */
447 #define HAVE_SRANDOM 1
448
449 /* Define to 1 if you have the <stdint.h> header file. */
450 #define HAVE_STDINT_H 1
451
452 /* Define to 1 if you have the <stdio_ext.h> header file. */
453 #define HAVE_STDIO_EXT_H 1
454
455 /* Define to 1 if you have the <stdlib.h> header file. */
456 #define HAVE_STDLIB_H 1
457
458 /* Define to 1 if you have the <strings.h> header file. */
459 #define HAVE_STRINGS_H 1
460
461 /* Define to 1 if you have the <string.h> header file. */
462 #define HAVE_STRING_H 1
463
464 /* Define to 1 if you have the `strnchr' function. */
465 /* #undef HAVE_STRNCHR */
466
467 /* Define to 1 if you have the `strndup' function. */
468 #define HAVE_STRNDUP 1
469
470 /* Define to 1 if you have the `strnlen' function. */
471 #define HAVE_STRNLEN 1
472
473 /* Define to 1 if have strsignal function prototype */
474 #define HAVE_STRSIGNAL_DECL 1
475
476 /* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */
477 #define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1
478
479 /* Define to 1 if `c_line' is a member of `struct termios'. */
480 #define HAVE_STRUCT_TERMIOS_C_LINE 1
481
482 /* Define to 1 if `tm_zone' is a member of `struct tm'. */
483 #define HAVE_STRUCT_TM_TM_ZONE 1
484
485 /* Define to 1 if you have the `sysconf' function. */
486 #define HAVE_SYSCONF 1
487
488 /* Define to 1 if you have the `sysinfo' function. */
489 #define HAVE_SYSINFO 1
490
491 /* Define to 1 if you have the <sys/disklabel.h> header file. */
492 /* #undef HAVE_SYS_DISKLABEL_H */
493
494 /* Define to 1 if you have the <sys/disk.h> header file. */
495 /* #undef HAVE_SYS_DISK_H */
496
497 /* Define to 1 if you have the <sys/endian.h> header file. */
498 /* #undef HAVE_SYS_ENDIAN_H */
499
500 /* Define to 1 if you have the <sys/file.h> header file. */
501 #define HAVE_SYS_FILE_H 1
502
503 /* Define to 1 if you have the <sys/ioccom.h> header file. */
504 /* #undef HAVE_SYS_IOCCOM_H */
505
506 /* Define to 1 if you have the <sys/ioctl.h> header file. */
507 #define HAVE_SYS_IOCTL_H 1
508
509 /* Define to 1 if you have the <sys/io.h> header file. */
510 #define HAVE_SYS_IO_H 1
511
512 /* Define to 1 if you have the <sys/mkdev.h> header file. */
513 /* #undef HAVE_SYS_MKDEV_H */
514
515 /* Define to 1 if you have the <sys/mount.h> header file. */
516 #define HAVE_SYS_MOUNT_H 1
517
518 /* Define to 1 if you have the <sys/param.h> header file. */
519 #define HAVE_SYS_PARAM_H 1
520
521 /* Define to 1 if you have the <sys/prctl.h> header file. */
522 #define HAVE_SYS_PRCTL_H 1
523
524 /* Define to 1 if you have the <sys/resource.h> header file. */
525 #define HAVE_SYS_RESOURCE_H 1
526
527 /* Define to 1 if you have the <sys/signalfd.h> header file. */
528 #define HAVE_SYS_SIGNALFD_H 1
529
530 /* Define to 1 if you have the <sys/socket.h> header file. */
531 #define HAVE_SYS_SOCKET_H 1
532
533 /* Define to 1 if you have the <sys/sockio.h> header file. */
534 /* #undef HAVE_SYS_SOCKIO_H */
535
536 /* Define to 1 if you have the <sys/stat.h> header file. */
537 #define HAVE_SYS_STAT_H 1
538
539 /* Define to 1 if you have the <sys/swap.h> header file. */
540 #define HAVE_SYS_SWAP_H 1
541
542 /* Define to 1 if you have the <sys/syscall.h> header file. */
543 #define HAVE_SYS_SYSCALL_H 1
544
545 /* Define to 1 if you have the <sys/sysmacros.h> header file. */
546 #define HAVE_SYS_SYSMACROS_H 1
547
548 /* Define to 1 if you have the <sys/timex.h> header file. */
549 #define HAVE_SYS_TIMEX_H 1
550
551 /* Define to 1 if you have the <sys/time.h> header file. */
552 #define HAVE_SYS_TIME_H 1
553
554 /* Define to 1 if you have the <sys/ttydefaults.h> header file. */
555 #define HAVE_SYS_TTYDEFAULTS_H 1
556
557 /* Define to 1 if you have the <sys/types.h> header file. */
558 #define HAVE_SYS_TYPES_H 1
559
560 /* Define to 1 if you have the <sys/ucred.h> header file. */
561 /* #undef HAVE_SYS_UCRED_H */
562
563 /* Define to 1 if you have the <sys/un.h> header file. */
564 #define HAVE_SYS_UN_H 1
565
566 /* Define to 1 if you have the <term.h> header file. */
567 #define HAVE_TERM_H 1
568
569 /* Define to 1 if you have the `timegm' function. */
570 #define HAVE_TIMEGM 1
571
572 /* Define to 1 if you have the `timer_create' function. */
573 /* #undef HAVE_TIMER_CREATE */
574
575 /* Define to 1 if the target supports thread-local storage. */
576 #define HAVE_TLS 1
577
578 /* Does struct tm have a field tm_gmtoff? */
579 #define HAVE_TM_GMTOFF 1
580
581 /* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
582 `HAVE_STRUCT_TM_TM_ZONE' instead. */
583 #define HAVE_TM_ZONE 1
584
585 /* Define to 1 if you don't have `tm_zone' but do have the external array
586 `tzname'. */
587 /* #undef HAVE_TZNAME */
588
589 /* Define to 1 if the system has the type `union semun'. */
590 /* #undef HAVE_UNION_SEMUN */
591
592 /* Define to 1 if you have the <unistd.h> header file. */
593 #define HAVE_UNISTD_H 1
594
595 /* Define to 1 if you have the `unlinkat' function. */
596 #define HAVE_UNLINKAT 1
597
598 /* Define to 1 if you have the `unshare' function. */
599 #define HAVE_UNSHARE 1
600
601 /* Define to 1 if you have the `updwtmpx' function. */
602 #define HAVE_UPDWTMPX 1
603
604 /* Define if curses library has the use_default_colors(). */
605 /* #undef HAVE_USE_DEFAULT_COLORS */
606
607 /* Define to 1 if you have the `usleep' function. */
608 #define HAVE_USLEEP 1
609
610 /* Define to 1 if you have the `utimensat' function. */
611 #define HAVE_UTIMENSAT 1
612
613 /* Define to 1 if you have the <utmpx.h> header file. */
614 #define HAVE_UTMPX_H 1
615
616 /* Define to 1 if you have the <utmp.h> header file. */
617 #define HAVE_UTMP_H 1
618
619 /* Define to 1 if you want to use uuid daemon. */
620 #define HAVE_UUIDD 1
621
622 /* Define to 1 if you have the `warn' function. */
623 #define HAVE_WARN 1
624
625 /* Define to 1 if you have the `warnx' function. */
626 #define HAVE_WARNX 1
627
628 /* Do we have wide character support? */
629 #define HAVE_WIDECHAR 1
630
631 /* Define to 1 if you have the `__fpending' function. */
632 #define HAVE___FPENDING 1
633
634 /* Define if __progname is defined */
635 #define HAVE___PROGNAME 1
636
637 /* Define to 1 if you have the `__secure_getenv' function. */
638 /* #undef HAVE___SECURE_GETENV */
639
640 /* libblkid date string */
641 #define LIBBLKID_DATE "02-Jun-2017"
642
643 /* libblkid version string */
644 #define LIBBLKID_VERSION "2.30.0"
645
646 /* libfdisk version string */
647 #define LIBFDISK_VERSION "2.30.0"
648
649 /* libmount version string */
650 #define LIBMOUNT_VERSION "2.30.0"
651
652 /* libsmartcols version string */
653 #define LIBSMARTCOLS_VERSION "2.30.0"
654
655 /* Should login chown /dev/vcsN? */
656 /* #undef LOGIN_CHOWN_VCS */
657
658 /* Should login stat() the mailbox? */
659 /* #undef LOGIN_STAT_MAIL */
660
661 /* Define to the sub-directory where libtool stores uninstalled libraries. */
662 #define LT_OBJDIR ".libs/"
663
664 /* Define to 1 if assertions should be disabled. */
665 /* #undef NDEBUG */
666
667 /* Should chsh allow only shells in /etc/shells? */
668 #define ONLY_LISTED_SHELLS 1
669
670 /* Name of package */
671 #define PACKAGE "util-linux"
672
673 /* Define to the address where bug reports for this package should be sent. */
674 #define PACKAGE_BUGREPORT "kzak@redhat.com"
675
676 /* Define to the full name of this package. */
677 #define PACKAGE_NAME "util-linux"
678
679 /* Define to the full name and version of this package. */
680 #define PACKAGE_STRING "util-linux 2.30"
681
682 /* Define to the one symbol short name of this package. */
683 #define PACKAGE_TARNAME "util-linux"
684
685 /* Define to the home page for this package. */
686 #define PACKAGE_URL "http://www.kernel.org/pub/linux/utils/util-linux/"
687
688 /* Define to the version of this package. */
689 #define PACKAGE_VERSION "2.30"
690
691 /* Should pg ring the bell on invalid keys? */
692 #define PG_BELL 1
693
694 /* Define to 1 if you have the ANSI C header files. */
695 #define STDC_HEADERS 1
696
697 /* Is swapon() declared with two parameters? */
698 #define SWAPON_HAS_TWO_ARGS 1
699
700 /* Fallback syscall number for fallocate */
701 /* #undef SYS_fallocate */
702
703 /* Fallback syscall number for ioprio_get */
704 /* #undef SYS_ioprio_get */
705
706 /* Fallback syscall number for ioprio_set */
707 /* #undef SYS_ioprio_set */
708
709 /* Fallback syscall number for pivot_root */
710 /* #undef SYS_pivot_root */
711
712 /* Fallback syscall number for prlimit64 */
713 /* #undef SYS_prlimit64 */
714
715 /* Fallback syscall number for sched_getaffinity */
716 /* #undef SYS_sched_getaffinity */
717
718 /* Fallback syscall number for sched_setattr */
719 /* #undef SYS_sched_setattr */
720
721 /* Fallback syscall number for setns */
722 /* #undef SYS_setns */
723
724 /* Fallback syscall number for unshare */
725 /* #undef SYS_unshare */
726
727 /* Define to 1 if your <sys/time.h> declares `struct tm'. */
728 /* #undef TM_IN_SYS_TIME */
729
730 /* Enables colorized output from utils by default */
731 #define USE_COLORS_BY_DEFAULT 1
732
733 /* Define to 1 if want to support mtab. */
734 /* #undef USE_LIBMOUNT_SUPPORT_MTAB */
735
736 /* Enable plymouth support feature for sulogin and aggety */
737 #define USE_PLYMOUTH_SUPPORT 1
738
739 /* Should sulogin use a emergency mount of /dev and /proc? */
740 /* #undef USE_SULOGIN_EMERGENCY_MOUNT */
741
742 /* Enable extensions on AIX 3, Interix. */
743 #ifndef _ALL_SOURCE
744 # define _ALL_SOURCE 1
745 #endif
746 /* Enable GNU extensions on systems that have them. */
747 #ifndef _GNU_SOURCE
748 # define _GNU_SOURCE 1
749 #endif
750 /* Enable threading extensions on Solaris. */
751 #ifndef _POSIX_PTHREAD_SEMANTICS
752 # define _POSIX_PTHREAD_SEMANTICS 1
753 #endif
754 /* Enable extensions on HP NonStop. */
755 #ifndef _TANDEM_SOURCE
756 # define _TANDEM_SOURCE 1
757 #endif
758 /* Enable general extensions on Solaris. */
759 #ifndef __EXTENSIONS__
760 # define __EXTENSIONS__ 1
761 #endif
762
763
764 /* Should wall and write be installed setgid tty? */
765 /* #undef USE_TTY_GROUP */
766
767 /* Define to 1 to remove /bin and /sbin from PATH env.variable */
768 /* #undef USE_USRDIR_PATHS_ONLY */
769
770 /* Version number of package */
771 #define VERSION "2.30"
772
773 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
774 significant byte first (like Motorola and SPARC, unlike Intel). */
775 #if defined AC_APPLE_UNIVERSAL_BUILD
776 # if defined __BIG_ENDIAN__
777 # define WORDS_BIGENDIAN 1
778 # endif
779 #else
780 # ifndef WORDS_BIGENDIAN
781 /* # undef WORDS_BIGENDIAN */
782 # endif
783 #endif
784
785 /* Enable MAP_ANON in sys/mman.h on Mac OS X */
786 /* #undef _DARWIN_C_SOURCE */
787
788 /* Enable large inode numbers on Mac OS X 10.5. */
789 #ifndef _DARWIN_USE_64_BIT_INODE
790 # define _DARWIN_USE_64_BIT_INODE 1
791 #endif
792
793 /* Number of bits in a file offset, on hosts where this is settable. */
794 /* #undef _FILE_OFFSET_BITS */
795
796 /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
797 /* #undef _LARGEFILE_SOURCE */
798
799 /* Define for large files, on AIX-style hosts. */
800 /* #undef _LARGE_FILES */
801
802 /* Define to 1 if on MINIX. */
803 /* #undef _MINIX */
804
805 /* Define to 2 if the system does not provide POSIX.1 features except with
806 this defined. */
807 /* #undef _POSIX_1_SOURCE */
808
809 /* Define to 1 if you need to in order for `stat' and other things to work. */
810 /* #undef _POSIX_SOURCE */
811
812 /* Define to empty if `const' does not conform to ANSI C. */
813 /* #undef const */
814
815 /* Define to empty if the keyword `volatile' does not work. Warning: valid
816 code using `volatile' can become incorrect without. Disable with care. */
817 /* #undef volatile */
File src/copy.c added (mode: 100644) (index 0000000..a61d50e)
1 /*
2 * copy.c --- copy UUIDs
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #include "namespace.h"
38 #include "uuidP.h"
39
40 void uuid_copy(uuid_t dst, const uuid_t src)
41 {
42 unsigned char *cp1;
43 const unsigned char *cp2;
44 int i;
45
46 for (i=0, cp1 = dst, cp2 = src; i < 16; i++)
47 *cp1++ = *cp2++;
48 }
File src/gen_uuid.c added (mode: 100644) (index 0000000..d29279f)
1 /*
2 * gen_uuid.c --- generate a DCE-compatible uuid
3 *
4 * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #ifdef _WIN32
38 #define _WIN32_WINNT 0x0500
39 #include <windows.h>
40 #define UUID MYUUID
41 #endif
42 #include <stdio.h>
43 #ifdef HAVE_UNISTD_H
44 #include <unistd.h>
45 #endif
46 #ifdef HAVE_STDLIB_H
47 #include <stdlib.h>
48 #endif
49 #include <string.h>
50 #include <fcntl.h>
51 #include <errno.h>
52 #include <limits.h>
53 #include <sys/types.h>
54 #ifdef HAVE_SYS_TIME_H
55 #include <sys/time.h>
56 #endif
57 #include <sys/stat.h>
58 #ifdef HAVE_SYS_FILE_H
59 #include <sys/file.h>
60 #endif
61 #ifdef HAVE_SYS_IOCTL_H
62 #include <sys/ioctl.h>
63 #endif
64 #ifdef HAVE_SYS_SOCKET_H
65 #include <sys/socket.h>
66 #endif
67 #ifdef HAVE_SYS_UN_H
68 #include <sys/un.h>
69 #endif
70 #ifdef HAVE_SYS_SOCKIO_H
71 #include <sys/sockio.h>
72 #endif
73 #ifdef HAVE_NET_IF_H
74 #include <net/if.h>
75 #endif
76 #ifdef HAVE_NETINET_IN_H
77 #include <netinet/in.h>
78 #endif
79 #ifdef HAVE_NET_IF_DL_H
80 #include <net/if_dl.h>
81 #endif
82 #if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
83 #include <sys/syscall.h>
84 #endif
85
86 #include "namespace.h"
87 #include "all-io.h"
88 #include "uuidP.h"
89 #include "uuidd.h"
90 #include "randutils.h"
91 #include "strutils.h"
92 #include "c.h"
93
94 #ifdef HAVE_TLS
95 #define THREAD_LOCAL static __thread
96 #else
97 #define THREAD_LOCAL static
98 #endif
99
100 #ifdef _WIN32
101 static void gettimeofday (struct timeval *tv, void *dummy)
102 {
103 FILETIME ftime;
104 uint64_t n;
105
106 GetSystemTimeAsFileTime (&ftime);
107 n = (((uint64_t) ftime.dwHighDateTime << 32)
108 + (uint64_t) ftime.dwLowDateTime);
109 if (n) {
110 n /= 10;
111 n -= ((369 * 365 + 89) * (uint64_t) 86400) * 1000000;
112 }
113
114 tv->tv_sec = n / 1000000;
115 tv->tv_usec = n % 1000000;
116 }
117
118 static int getuid (void)
119 {
120 return 1;
121 }
122 #endif
123
124 /*
125 * Get the ethernet hardware address, if we can find it...
126 *
127 * XXX for a windows version, probably should use GetAdaptersInfo:
128 * http://www.codeguru.com/cpp/i-n/network/networkinformation/article.php/c5451
129 * commenting out get_node_id just to get gen_uuid to compile under windows
130 * is not the right way to go!
131 */
132 static int get_node_id(unsigned char *node_id)
133 {
134 #ifdef HAVE_NET_IF_H
135 int sd;
136 struct ifreq ifr, *ifrp;
137 struct ifconf ifc;
138 char buf[1024];
139 int n, i;
140 unsigned char *a;
141 #ifdef HAVE_NET_IF_DL_H
142 struct sockaddr_dl *sdlp;
143 #endif
144
145 /*
146 * BSD 4.4 defines the size of an ifreq to be
147 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
148 * However, under earlier systems, sa_len isn't present, so the size is
149 * just sizeof(struct ifreq)
150 */
151 #ifdef HAVE_SA_LEN
152 #define ifreq_size(i) max(sizeof(struct ifreq),\
153 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
154 #else
155 #define ifreq_size(i) sizeof(struct ifreq)
156 #endif /* HAVE_SA_LEN */
157
158 sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
159 if (sd < 0) {
160 return -1;
161 }
162 memset(buf, 0, sizeof(buf));
163 ifc.ifc_len = sizeof(buf);
164 ifc.ifc_buf = buf;
165 if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
166 close(sd);
167 return -1;
168 }
169 n = ifc.ifc_len;
170 for (i = 0; i < n; i+= ifreq_size(*ifrp) ) {
171 ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
172 strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
173 #ifdef SIOCGIFHWADDR
174 if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
175 continue;
176 a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
177 #else
178 #ifdef SIOCGENADDR
179 if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
180 continue;
181 a = (unsigned char *) ifr.ifr_enaddr;
182 #else
183 #ifdef HAVE_NET_IF_DL_H
184 sdlp = (struct sockaddr_dl *) &ifrp->ifr_addr;
185 if ((sdlp->sdl_family != AF_LINK) || (sdlp->sdl_alen != 6))
186 continue;
187 a = (unsigned char *) &sdlp->sdl_data[sdlp->sdl_nlen];
188 #else
189 /*
190 * XXX we don't have a way of getting the hardware
191 * address
192 */
193 close(sd);
194 return 0;
195 #endif /* HAVE_NET_IF_DL_H */
196 #endif /* SIOCGENADDR */
197 #endif /* SIOCGIFHWADDR */
198 if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
199 continue;
200 if (node_id) {
201 memcpy(node_id, a, 6);
202 close(sd);
203 return 1;
204 }
205 }
206 close(sd);
207 #endif
208 return 0;
209 }
210
211 /* Assume that the gettimeofday() has microsecond granularity */
212 #define MAX_ADJUSTMENT 10
213
214 /*
215 * Get clock from global sequence clock counter.
216 *
217 * Return -1 if the clock counter could not be opened/locked (in this case
218 * pseudorandom value is returned in @ret_clock_seq), otherwise return 0.
219 */
220 static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
221 uint16_t *ret_clock_seq, int *num)
222 {
223 THREAD_LOCAL int adjustment = 0;
224 THREAD_LOCAL struct timeval last = {0, 0};
225 THREAD_LOCAL int state_fd = -2;
226 THREAD_LOCAL FILE *state_f;
227 THREAD_LOCAL uint16_t clock_seq;
228 struct timeval tv;
229 uint64_t clock_reg;
230 mode_t save_umask;
231 int len;
232 int ret = 0;
233
234 if (state_fd == -1)
235 ret = -1;
236
237 if (state_fd == -2) {
238 save_umask = umask(0);
239 state_fd = open(LIBUUID_CLOCK_FILE, O_RDWR|O_CREAT|O_CLOEXEC, 0660);
240 (void) umask(save_umask);
241 if (state_fd != -1) {
242 state_f = fdopen(state_fd, "r+" UL_CLOEXECSTR);
243 if (!state_f) {
244 close(state_fd);
245 state_fd = -1;
246 ret = -1;
247 }
248 }
249 else
250 ret = -1;
251 }
252 if (state_fd >= 0) {
253 rewind(state_f);
254 while (flock(state_fd, LOCK_EX) < 0) {
255 if ((errno == EAGAIN) || (errno == EINTR))
256 continue;
257 fclose(state_f);
258 close(state_fd);
259 state_fd = -1;
260 ret = -1;
261 break;
262 }
263 }
264 if (state_fd >= 0) {
265 unsigned int cl;
266 unsigned long tv1, tv2;
267 int a;
268
269 if (fscanf(state_f, "clock: %04x tv: %lu %lu adj: %d\n",
270 &cl, &tv1, &tv2, &a) == 4) {
271 clock_seq = cl & 0x3FFF;
272 last.tv_sec = tv1;
273 last.tv_usec = tv2;
274 adjustment = a;
275 }
276 }
277
278 if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
279 random_get_bytes(&clock_seq, sizeof(clock_seq));
280 clock_seq &= 0x3FFF;
281 gettimeofday(&last, NULL);
282 last.tv_sec--;
283 }
284
285 try_again:
286 gettimeofday(&tv, NULL);
287 if ((tv.tv_sec < last.tv_sec) ||
288 ((tv.tv_sec == last.tv_sec) &&
289 (tv.tv_usec < last.tv_usec))) {
290 clock_seq = (clock_seq+1) & 0x3FFF;
291 adjustment = 0;
292 last = tv;
293 } else if ((tv.tv_sec == last.tv_sec) &&
294 (tv.tv_usec == last.tv_usec)) {
295 if (adjustment >= MAX_ADJUSTMENT)
296 goto try_again;
297 adjustment++;
298 } else {
299 adjustment = 0;
300 last = tv;
301 }
302
303 clock_reg = tv.tv_usec*10 + adjustment;
304 clock_reg += ((uint64_t) tv.tv_sec)*10000000;
305 clock_reg += (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
306
307 if (num && (*num > 1)) {
308 adjustment += *num - 1;
309 last.tv_usec += adjustment / 10;
310 adjustment = adjustment % 10;
311 last.tv_sec += last.tv_usec / 1000000;
312 last.tv_usec = last.tv_usec % 1000000;
313 }
314
315 if (state_fd >= 0) {
316 rewind(state_f);
317 len = fprintf(state_f,
318 "clock: %04x tv: %016ld %08ld adj: %08d\n",
319 clock_seq, (long)last.tv_sec, (long)last.tv_usec, adjustment);
320 fflush(state_f);
321 if (ftruncate(state_fd, len) < 0) {
322 fprintf(state_f, " \n");
323 fflush(state_f);
324 }
325 rewind(state_f);
326 flock(state_fd, LOCK_UN);
327 }
328
329 *clock_high = clock_reg >> 32;
330 *clock_low = clock_reg;
331 *ret_clock_seq = clock_seq;
332 return ret;
333 }
334
335 #if defined(HAVE_UUIDD) && defined(HAVE_SYS_UN_H)
336
337 /*
338 * Try using the uuidd daemon to generate the UUID
339 *
340 * Returns 0 on success, non-zero on failure.
341 */
342 static int get_uuid_via_daemon(int op, uuid_t out, int *num)
343 {
344 char op_buf[64];
345 int op_len;
346 int s;
347 ssize_t ret;
348 int32_t reply_len = 0, expected = 16;
349 struct sockaddr_un srv_addr;
350
351 if (sizeof(UUIDD_SOCKET_PATH) > sizeof(srv_addr.sun_path))
352 return -1;
353
354 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
355 return -1;
356
357 srv_addr.sun_family = AF_UNIX;
358 xstrncpy(srv_addr.sun_path, UUIDD_SOCKET_PATH, sizeof(srv_addr.sun_path));
359
360 if (connect(s, (const struct sockaddr *) &srv_addr,
361 sizeof(struct sockaddr_un)) < 0)
362 goto fail;
363
364 op_buf[0] = op;
365 op_len = 1;
366 if (op == UUIDD_OP_BULK_TIME_UUID) {
367 memcpy(op_buf+1, num, sizeof(*num));
368 op_len += sizeof(*num);
369 expected += sizeof(*num);
370 }
371
372 ret = write(s, op_buf, op_len);
373 if (ret < 1)
374 goto fail;
375
376 ret = read_all(s, (char *) &reply_len, sizeof(reply_len));
377 if (ret < 0)
378 goto fail;
379
380 if (reply_len != expected)
381 goto fail;
382
383 ret = read_all(s, op_buf, reply_len);
384
385 if (op == UUIDD_OP_BULK_TIME_UUID)
386 memcpy(op_buf+16, num, sizeof(int));
387
388 memcpy(out, op_buf, 16);
389
390 close(s);
391 return ((ret == expected) ? 0 : -1);
392
393 fail:
394 close(s);
395 return -1;
396 }
397
398 #else /* !defined(HAVE_UUIDD) && defined(HAVE_SYS_UN_H) */
399 static int get_uuid_via_daemon(int op __attribute__((__unused__)),
400 uuid_t out __attribute__((__unused__)),
401 int *num __attribute__((__unused__)))
402 {
403 return -1;
404 }
405 #endif
406
407 int __uuid_generate_time(uuid_t out, int *num)
408 {
409 static unsigned char node_id[6];
410 static int has_init = 0;
411 struct uuid uu;
412 uint32_t clock_mid;
413 int ret;
414
415 if (!has_init) {
416 if (get_node_id(node_id) <= 0) {
417 random_get_bytes(node_id, 6);
418 /*
419 * Set multicast bit, to prevent conflicts
420 * with IEEE 802 addresses obtained from
421 * network cards
422 */
423 node_id[0] |= 0x01;
424 }
425 has_init = 1;
426 }
427 ret = get_clock(&clock_mid, &uu.time_low, &uu.clock_seq, num);
428 uu.clock_seq |= 0x8000;
429 uu.time_mid = (uint16_t) clock_mid;
430 uu.time_hi_and_version = ((clock_mid >> 16) & 0x0FFF) | 0x1000;
431 memcpy(uu.node, node_id, 6);
432 uuid_pack(&uu, out);
433 return ret;
434 }
435
436 /*
437 * Generate time-based UUID and store it to @out
438 *
439 * Tries to guarantee uniqueness of the generated UUIDs by obtaining them from the uuidd daemon,
440 * or, if uuidd is not usable, by using the global clock state counter (see get_clock()).
441 * If neither of these is possible (e.g. because of insufficient permissions), it generates
442 * the UUID anyway, but returns -1. Otherwise, returns 0.
443 */
444 static int uuid_generate_time_generic(uuid_t out) {
445 #ifdef HAVE_TLS
446 THREAD_LOCAL int num = 0;
447 THREAD_LOCAL struct uuid uu;
448 THREAD_LOCAL time_t last_time = 0;
449 time_t now;
450
451 if (num > 0) {
452 now = time(NULL);
453 if (now > last_time+1)
454 num = 0;
455 }
456 if (num <= 0) {
457 num = 1000;
458 if (get_uuid_via_daemon(UUIDD_OP_BULK_TIME_UUID,
459 out, &num) == 0) {
460 last_time = time(NULL);
461 uuid_unpack(out, &uu);
462 num--;
463 return 0;
464 }
465 num = 0;
466 }
467 if (num > 0) {
468 uu.time_low++;
469 if (uu.time_low == 0) {
470 uu.time_mid++;
471 if (uu.time_mid == 0)
472 uu.time_hi_and_version++;
473 }
474 num--;
475 uuid_pack(&uu, out);
476 return 0;
477 }
478 #else
479 if (get_uuid_via_daemon(UUIDD_OP_TIME_UUID, out, 0) == 0)
480 return 0;
481 #endif
482
483 return __uuid_generate_time(out, NULL);
484 }
485
486 /*
487 * Generate time-based UUID and store it to @out.
488 *
489 * Discards return value from uuid_generate_time_generic()
490 */
491 void uuid_generate_time(uuid_t out)
492 {
493 (void)uuid_generate_time_generic(out);
494 }
495
496
497 int uuid_generate_time_safe(uuid_t out)
498 {
499 return uuid_generate_time_generic(out);
500 }
501
502
503 void __uuid_generate_random(uuid_t out, int *num)
504 {
505 uuid_t buf;
506 struct uuid uu;
507 int i, n;
508
509 if (!num || !*num)
510 n = 1;
511 else
512 n = *num;
513
514 for (i = 0; i < n; i++) {
515 random_get_bytes(buf, sizeof(buf));
516 uuid_unpack(buf, &uu);
517
518 uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
519 uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF)
520 | 0x4000;
521 uuid_pack(&uu, out);
522 out += sizeof(uuid_t);
523 }
524 }
525
526 void uuid_generate_random(uuid_t out)
527 {
528 int num = 1;
529 /* No real reason to use the daemon for random uuid's -- yet */
530
531 __uuid_generate_random(out, &num);
532 }
533
534 /*
535 * Check whether good random source (/dev/random or /dev/urandom)
536 * is available.
537 */
538 static int have_random_source(void)
539 {
540 struct stat s;
541
542 return (!stat("/dev/random", &s) || !stat("/dev/urandom", &s));
543 }
544
545
546 /*
547 * This is the generic front-end to uuid_generate_random and
548 * uuid_generate_time. It uses uuid_generate_random only if
549 * /dev/urandom is available, since otherwise we won't have
550 * high-quality randomness.
551 */
552 void uuid_generate(uuid_t out)
553 {
554 if (have_random_source())
555 uuid_generate_random(out);
556 else
557 uuid_generate_time(out);
558 }
File src/isnull.c added (mode: 100644) (index 0000000..0e33608)
1 /*
2 * isnull.c --- Check whether or not the UUID is null
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #include "namespace.h"
38 #include "uuidP.h"
39
40 /* Returns 1 if the uuid is the NULL uuid */
41 int uuid_is_null(const uuid_t uu)
42 {
43 const unsigned char *cp;
44 int i;
45
46 for (i=0, cp = uu; i < 16; i++)
47 if (*cp++)
48 return 0;
49 return 1;
50 }
51
File src/namespace.h added (mode: 100644) (index 0000000..202c4c8)
1 #ifndef NAMESPACE_H
2 #define NAMESPACE_H
3 #define rand_get_number nyanlibuuid_rand_get_number
4 #define random_get_fd nyanlibuuid_random_get_fd
5 #define random_get_bytes nyanlibuuid_random_get_bytes
6 #define random_tell_source nyanlibuuid_random_tell_source
7 #endif
File src/pack.c added (mode: 100644) (index 0000000..487a089)
1 /*
2 * Internal routine for packing UUIDs
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #include <string.h>
38 #include "namespace.h"
39 #include "uuidP.h"
40
41 void uuid_pack(const struct uuid *uu, uuid_t ptr)
42 {
43 uint32_t tmp;
44 unsigned char *out = ptr;
45
46 tmp = uu->time_low;
47 out[3] = (unsigned char) tmp;
48 tmp >>= 8;
49 out[2] = (unsigned char) tmp;
50 tmp >>= 8;
51 out[1] = (unsigned char) tmp;
52 tmp >>= 8;
53 out[0] = (unsigned char) tmp;
54
55 tmp = uu->time_mid;
56 out[5] = (unsigned char) tmp;
57 tmp >>= 8;
58 out[4] = (unsigned char) tmp;
59
60 tmp = uu->time_hi_and_version;
61 out[7] = (unsigned char) tmp;
62 tmp >>= 8;
63 out[6] = (unsigned char) tmp;
64
65 tmp = uu->clock_seq;
66 out[9] = (unsigned char) tmp;
67 tmp >>= 8;
68 out[8] = (unsigned char) tmp;
69
70 memcpy(out+10, uu->node, 6);
71 }
72
File src/parse.c added (mode: 100644) (index 0000000..13a1368)
1 /*
2 * parse.c --- UUID parsing
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <ctype.h>
40 #include <string.h>
41
42 #include "namespace.h"
43 #include "uuidP.h"
44
45 int uuid_parse(const char *in, uuid_t uu)
46 {
47 struct uuid uuid;
48 int i;
49 const char *cp;
50 char buf[3];
51
52 if (strlen(in) != 36)
53 return -1;
54 for (i=0, cp = in; i <= 36; i++,cp++) {
55 if ((i == 8) || (i == 13) || (i == 18) ||
56 (i == 23)) {
57 if (*cp == '-')
58 continue;
59 else
60 return -1;
61 }
62 if (i== 36)
63 if (*cp == 0)
64 continue;
65 if (!isxdigit(*cp))
66 return -1;
67 }
68 uuid.time_low = strtoul(in, NULL, 16);
69 uuid.time_mid = strtoul(in+9, NULL, 16);
70 uuid.time_hi_and_version = strtoul(in+14, NULL, 16);
71 uuid.clock_seq = strtoul(in+19, NULL, 16);
72 cp = in+24;
73 buf[2] = 0;
74 for (i=0; i < 6; i++) {
75 buf[0] = *cp++;
76 buf[1] = *cp++;
77 uuid.node[i] = strtoul(buf, NULL, 16);
78 }
79
80 uuid_pack(&uuid, uu);
81 return 0;
82 }
File src/randutils.c added (mode: 100644) (index 0000000..517995b)
1 /*
2 * General purpose random utilities
3 *
4 * Based on libuuid code.
5 *
6 * This file may be redistributed under the terms of the
7 * GNU Lesser General Public License.
8 */
9
10 #include "config.h"
11
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <sys/time.h>
18
19 #include <sys/syscall.h>
20
21 #include "namespace.h"
22 #include "c.h"
23 #include "randutils.h"
24 #include "nls.h"
25
26 #ifdef HAVE_TLS
27 #define THREAD_LOCAL static __thread
28 #else
29 #define THREAD_LOCAL static
30 #endif
31
32 #ifdef HAVE_GETRANDOM
33 # include <sys/random.h>
34 #elif defined (__linux__)
35 # if !defined(SYS_getrandom) && defined(__NR_getrandom)
36 /* usable kernel-headers, but old glibc-headers */
37 # define SYS_getrandom __NR_getrandom
38 # endif
39 #endif
40
41 #if !defined(HAVE_GETRANDOM) && defined(SYS_getrandom)
42 /* libc without function, but we have syscal */
43 static int getrandom(void *buf, size_t buflen, unsigned int flags)
44 {
45 return (syscall(SYS_getrandom, buf, buflen, flags));
46 }
47 # define HAVE_GETRANDOM
48 #endif
49
50 #if defined(__linux__) && defined(__NR_gettid) && defined(HAVE_JRAND48)
51 #define DO_JRAND_MIX
52 THREAD_LOCAL unsigned short ul_jrand_seed[3];
53 #endif
54
55 int rand_get_number(int low_n, int high_n)
56 {
57 return rand() % (high_n - low_n + 1) + low_n;
58 }
59
60 static void crank_random(void)
61 {
62 int i;
63 struct timeval tv;
64
65 gettimeofday(&tv, NULL);
66 srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
67
68 #ifdef DO_JRAND_MIX
69 ul_jrand_seed[0] = getpid() ^ (tv.tv_sec & 0xFFFF);
70 ul_jrand_seed[1] = getppid() ^ (tv.tv_usec & 0xFFFF);
71 ul_jrand_seed[2] = (tv.tv_sec ^ tv.tv_usec) >> 16;
72 #endif
73 /* Crank the random number generator a few times */
74 gettimeofday(&tv, NULL);
75 for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
76 rand();
77 }
78
79 int random_get_fd(void)
80 {
81 int i, fd;
82
83 fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
84 if (fd == -1)
85 fd = open("/dev/random", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
86 if (fd >= 0) {
87 i = fcntl(fd, F_GETFD);
88 if (i >= 0)
89 fcntl(fd, F_SETFD, i | FD_CLOEXEC);
90 }
91 crank_random();
92 return fd;
93 }
94
95 /*
96 * Generate a stream of random nbytes into buf.
97 * Use /dev/urandom if possible, and if not,
98 * use glibc pseudo-random functions.
99 */
100 void random_get_bytes(void *buf, size_t nbytes)
101 {
102 size_t i;
103 unsigned char *cp = (unsigned char *)buf;
104
105 #ifdef HAVE_GETRANDOM
106 while (getrandom(buf, nbytes, 0) < 0) {
107 if (errno == EINTR)
108 continue;
109 break;
110 }
111 #else
112 size_t n = nbytes;
113 int fd = random_get_fd();
114 int lose_counter = 0;
115
116 if (fd >= 0) {
117 while (n > 0) {
118 ssize_t x = read(fd, cp, n);
119 if (x <= 0) {
120 if (lose_counter++ > 16)
121 break;
122 continue;
123 }
124 n -= x;
125 cp += x;
126 lose_counter = 0;
127 }
128
129 close(fd);
130 }
131 #endif
132 /*
133 * We do this all the time, but this is the only source of
134 * randomness if /dev/random/urandom is out to lunch.
135 */
136 crank_random();
137 for (cp = buf, i = 0; i < nbytes; i++)
138 *cp++ ^= (rand() >> 7) & 0xFF;
139
140 #ifdef DO_JRAND_MIX
141 {
142 unsigned short tmp_seed[3];
143
144 memcpy(tmp_seed, ul_jrand_seed, sizeof(tmp_seed));
145 ul_jrand_seed[2] = ul_jrand_seed[2] ^ syscall(__NR_gettid);
146 for (cp = buf, i = 0; i < nbytes; i++)
147 *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF;
148 memcpy(ul_jrand_seed, tmp_seed,
149 sizeof(ul_jrand_seed)-sizeof(unsigned short));
150 }
151 #endif
152
153 return;
154 }
155
156
157 /*
158 * Tell source of randomness.
159 */
160 const char *random_tell_source(void)
161 {
162 #ifdef HAVE_GETRANDOM
163 return _("getrandom() function");
164 #else
165 size_t i;
166 static const char *random_sources[] = {
167 "/dev/urandom",
168 "/dev/random"
169 };
170
171 for (i = 0; i < ARRAY_SIZE(random_sources); i++) {
172 if (!access(random_sources[i], R_OK))
173 return random_sources[i];
174 }
175 #endif
176 return _("libc pseudo-random functions");
177 }
178
179 #ifdef TEST_PROGRAM_RANDUTILS
180 int main(int argc __attribute__ ((__unused__)),
181 char *argv[] __attribute__ ((__unused__)))
182 {
183 unsigned int v, i;
184
185 /* generate and print 10 random numbers */
186 for (i = 0; i < 10; i++) {
187 random_get_bytes(&v, sizeof(v));
188 printf("%d\n", v);
189 }
190
191 return EXIT_SUCCESS;
192 }
193 #endif /* TEST_PROGRAM_RANDUTILS */
File src/test_uuid.c added (mode: 100644) (index 0000000..b2a3a2a)
1 /*
2 * tst_uuid.c --- test program from the UUID library
3 *
4 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #ifdef _WIN32
38 #define _WIN32_WINNT 0x0500
39 #include <windows.h>
40 #define UUID MYUUID
41 #endif
42
43 #include <ctype.h>
44 #include <fcntl.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <sys/stat.h>
48
49 #include "namespace.h"
50 #include "c.h"
51 #include "uuid.h"
52
53 static int test_uuid(const char * uuid, int isValid)
54 {
55 static const char * validStr[2] = {"invalid", "valid"};
56 uuid_t uuidBits;
57 int parsedOk;
58
59 parsedOk = uuid_parse(uuid, uuidBits) == 0;
60
61 printf("%s is %s", uuid, validStr[isValid]);
62 if (parsedOk != isValid) {
63 printf(" but uuid_parse says %s\n", validStr[parsedOk]);
64 return 1;
65 }
66 printf(", OK\n");
67 return 0;
68 }
69
70 static int check_uuids_in_file(const char *file)
71 {
72 int fd, ret = 0;
73 size_t sz;
74 char str[sizeof("01234567-89ab-cdef-0134-567890abcedf")];
75 uuid_t uuidBits;
76
77 if ((fd = open(file, O_RDONLY)) < 0) {
78 warn("%s", file);
79 return 1;
80 }
81 while ((sz = read(fd, str, sizeof(str))) != 0) {
82 if (isspace(str[sizeof(str) - 1]))
83 str[sizeof(str) - 1] = '\0';
84 if (uuid_parse(str, uuidBits)) {
85 warnx("%s: %s", file, str);
86 ret++;
87 }
88 }
89 return ret;
90 }
91
92 int
93 main(int argc, char **argv)
94 {
95 int failed = 0;
96
97 if (argc < 2) {
98 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981b", 1);
99 failed += test_uuid("84949CC5-4701-4A84-895B-354C584A981B", 1);
100 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981bc", 0);
101 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981", 0);
102 failed += test_uuid("84949cc5x4701-4a84-895b-354c584a981b", 0);
103 failed += test_uuid("84949cc504701-4a84-895b-354c584a981b", 0);
104 failed += test_uuid("84949cc5-470104a84-895b-354c584a981b", 0);
105 failed += test_uuid("84949cc5-4701-4a840895b-354c584a981b", 0);
106 failed += test_uuid("84949cc5-4701-4a84-895b0354c584a981b", 0);
107 failed += test_uuid("g4949cc5-4701-4a84-895b-354c584a981b", 0);
108 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981g", 0);
109 failed += test_uuid("00000000-0000-0000-0000-000000000000", 1);
110 failed += test_uuid("01234567-89ab-cdef-0134-567890abcedf", 1);
111 failed += test_uuid("ffffffff-ffff-ffff-ffff-ffffffffffff", 1);
112 } else {
113 int i;
114
115 for (i = 1; i < argc; i++)
116 failed += check_uuids_in_file(argv[i]);
117 }
118 if (failed) {
119 printf("%d failures.\n", failed);
120 exit(1);
121 }
122 return 0;
123 }
File src/unpack.c added (mode: 100644) (index 0000000..b599b60)
1 /*
2 * Internal routine for unpacking UUID
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #include <string.h>
38 #include "namespace.h"
39 #include "uuidP.h"
40
41 void uuid_unpack(const uuid_t in, struct uuid *uu)
42 {
43 const uint8_t *ptr = in;
44 uint32_t tmp;
45
46 tmp = *ptr++;
47 tmp = (tmp << 8) | *ptr++;
48 tmp = (tmp << 8) | *ptr++;
49 tmp = (tmp << 8) | *ptr++;
50 uu->time_low = tmp;
51
52 tmp = *ptr++;
53 tmp = (tmp << 8) | *ptr++;
54 uu->time_mid = tmp;
55
56 tmp = *ptr++;
57 tmp = (tmp << 8) | *ptr++;
58 uu->time_hi_and_version = tmp;
59
60 tmp = *ptr++;
61 tmp = (tmp << 8) | *ptr++;
62 uu->clock_seq = tmp;
63
64 memcpy(uu->node, ptr, 6);
65 }
66
File src/unparse.c added (mode: 100644) (index 0000000..89bc3e3)
1 /*
2 * unparse.c -- convert a UUID to string
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include "config.h"
36
37 #include <stdio.h>
38
39 #include "namespace.h"
40 #include "uuidP.h"
41
42 static const char *fmt_lower =
43 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
44
45 static const char *fmt_upper =
46 "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X";
47
48 #ifdef UUID_UNPARSE_DEFAULT_UPPER
49 #define FMT_DEFAULT fmt_upper
50 #else
51 #define FMT_DEFAULT fmt_lower
52 #endif
53
54 static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt)
55 {
56 struct uuid uuid;
57
58 uuid_unpack(uu, &uuid);
59 sprintf(out, fmt,
60 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
61 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
62 uuid.node[0], uuid.node[1], uuid.node[2],
63 uuid.node[3], uuid.node[4], uuid.node[5]);
64 }
65
66 void uuid_unparse_lower(const uuid_t uu, char *out)
67 {
68 uuid_unparse_x(uu, out, fmt_lower);
69 }
70
71 void uuid_unparse_upper(const uuid_t uu, char *out)
72 {
73 uuid_unparse_x(uu, out, fmt_upper);
74 }
75
76 void uuid_unparse(const uuid_t uu, char *out)
77 {
78 uuid_unparse_x(uu, out, FMT_DEFAULT);
79 }
File src/utils/all-io.h added (mode: 100644) (index 0000000..0623692)
1 /*
2 * No copyright is claimed. This code is in the public domain; do with
3 * it what you wish.
4 *
5 * Written by Karel Zak <kzak@redhat.com>
6 * Petr Uzel <petr.uzel@suse.cz>
7 */
8
9 #ifndef UTIL_LINUX_ALL_IO_H
10 #define UTIL_LINUX_ALL_IO_H
11
12 #include <string.h>
13 #include <unistd.h>
14 #include <errno.h>
15
16 #include "c.h"
17
18 static inline int write_all(int fd, const void *buf, size_t count)
19 {
20 while (count) {
21 ssize_t tmp;
22
23 errno = 0;
24 tmp = write(fd, buf, count);
25 if (tmp > 0) {
26 count -= tmp;
27 if (count)
28 buf = (void *) ((char *) buf + tmp);
29 } else if (errno != EINTR && errno != EAGAIN)
30 return -1;
31 if (errno == EAGAIN) /* Try later, *sigh* */
32 xusleep(250000);
33 }
34 return 0;
35 }
36
37 static inline int fwrite_all(const void *ptr, size_t size,
38 size_t nmemb, FILE *stream)
39 {
40 while (nmemb) {
41 size_t tmp;
42
43 errno = 0;
44 tmp = fwrite(ptr, size, nmemb, stream);
45 if (tmp > 0) {
46 nmemb -= tmp;
47 if (nmemb)
48 ptr = (void *) ((char *) ptr + (tmp * size));
49 } else if (errno != EINTR && errno != EAGAIN)
50 return -1;
51 if (errno == EAGAIN) /* Try later, *sigh* */
52 xusleep(250000);
53 }
54 return 0;
55 }
56
57 static inline ssize_t read_all(int fd, char *buf, size_t count)
58 {
59 ssize_t ret;
60 ssize_t c = 0;
61 int tries = 0;
62
63 memset(buf, 0, count);
64 while (count > 0) {
65 ret = read(fd, buf, count);
66 if (ret <= 0) {
67 if (ret < 0 && (errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
68 xusleep(250000);
69 continue;
70 }
71 return c ? c : -1;
72 }
73 if (ret > 0)
74 tries = 0;
75 count -= ret;
76 buf += ret;
77 c += ret;
78 }
79 return c;
80 }
81
82 #endif /* UTIL_LINUX_ALL_IO_H */
File src/utils/c.h added (mode: 100644) (index 0000000..a5162b9)
1 /*
2 * Fundamental C definitions.
3 */
4
5 #ifndef UTIL_LINUX_C_H
6 #define UTIL_LINUX_C_H
7
8 #include <limits.h>
9 #include <stddef.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <stdarg.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <errno.h>
17
18 #include <assert.h>
19
20 #ifdef HAVE_ERR_H
21 # include <err.h>
22 #endif
23
24 #ifdef HAVE_SYS_SYSMACROS_H
25 # include <sys/sysmacros.h> /* for major, minor */
26 #endif
27
28 #ifndef LOGIN_NAME_MAX
29 # define LOGIN_NAME_MAX 256
30 #endif
31
32 /*
33 * Compiler-specific stuff
34 */
35 #ifndef __GNUC_PREREQ
36 # if defined __GNUC__ && defined __GNUC_MINOR__
37 # define __GNUC_PREREQ(maj, min) \
38 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
39 # else
40 # define __GNUC_PREREQ(maj, min) 0
41 # endif
42 #endif
43
44 #ifdef __GNUC__
45
46 /* &a[0] degrades to a pointer: a different type from an array */
47 # define __must_be_array(a) \
48 UL_BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a), __typeof__(&a[0])))
49
50 # define ignore_result(x) __extension__ ({ \
51 __typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
52 })
53
54 #else /* !__GNUC__ */
55 # define __must_be_array(a) 0
56 # define __attribute__(_arg_)
57 # define ignore_result(x) ((void) (x))
58 #endif /* !__GNUC__ */
59
60 /*
61 * Function attributes
62 */
63 #ifndef __ul_alloc_size
64 # if __GNUC_PREREQ (4, 3)
65 # define __ul_alloc_size(s) __attribute__((alloc_size(s), warn_unused_result))
66 # else
67 # define __ul_alloc_size(s)
68 # endif
69 #endif
70
71 #ifndef __ul_calloc_size
72 # if __GNUC_PREREQ (4, 3)
73 # define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s), warn_unused_result))
74 # else
75 # define __ul_calloc_size(n, s)
76 # endif
77 #endif
78
79 /*
80 * Force a compilation error if condition is true, but also produce a
81 * result (of value 0 and type size_t), so the expression can be used
82 * e.g. in a structure initializer (or wherever else comma expressions
83 * aren't permitted).
84 */
85 #define UL_BUILD_BUG_ON_ZERO(e) __extension__ (sizeof(struct { int:-!!(e); }))
86 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
87
88 #ifndef ARRAY_SIZE
89 # define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
90 #endif
91
92 #ifndef PATH_MAX
93 # define PATH_MAX 4096
94 #endif
95
96 #ifndef TRUE
97 # define TRUE 1
98 #endif
99
100 #ifndef FALSE
101 # define FALSE 0
102 #endif
103
104 #ifndef min
105 # define min(x, y) __extension__ ({ \
106 __typeof__(x) _min1 = (x); \
107 __typeof__(y) _min2 = (y); \
108 (void) (&_min1 == &_min2); \
109 _min1 < _min2 ? _min1 : _min2; })
110 #endif
111
112 #ifndef max
113 # define max(x, y) __extension__ ({ \
114 __typeof__(x) _max1 = (x); \
115 __typeof__(y) _max2 = (y); \
116 (void) (&_max1 == &_max2); \
117 _max1 > _max2 ? _max1 : _max2; })
118 #endif
119
120 #ifndef cmp_numbers
121 # define cmp_numbers(x, y) __extension__ ({ \
122 __typeof__(x) _a = (x); \
123 __typeof__(y) _b = (y); \
124 (void) (&_a == &_b); \
125 _a == _b ? 0 : _a > _b ? 1 : -1; })
126 #endif
127
128 #ifndef offsetof
129 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
130 #endif
131
132 #ifndef container_of
133 #define container_of(ptr, type, member) __extension__ ({ \
134 const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
135 (type *)( (char *)__mptr - offsetof(type,member) );})
136 #endif
137
138 #ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
139 # ifdef HAVE___PROGNAME
140 extern char *__progname;
141 # define program_invocation_short_name __progname
142 # else
143 # ifdef HAVE_GETEXECNAME
144 # define program_invocation_short_name \
145 prog_inv_sh_nm_from_file(getexecname(), 0)
146 # else
147 # define program_invocation_short_name \
148 prog_inv_sh_nm_from_file(__FILE__, 1)
149 # endif
150 static char prog_inv_sh_nm_buf[256];
151 static inline char *
152 prog_inv_sh_nm_from_file(char *f, char stripext)
153 {
154 char *t;
155
156 if ((t = strrchr(f, '/')) != NULL)
157 t++;
158 else
159 t = f;
160
161 strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
162 prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
163
164 if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL)
165 *t = '\0';
166
167 return prog_inv_sh_nm_buf;
168 }
169 # endif
170 #endif
171
172
173 #ifndef HAVE_ERR_H
174 static inline void
175 errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
176 {
177 fprintf(stderr, "%s: ", program_invocation_short_name);
178 if (fmt != NULL) {
179 va_list argp;
180 va_start(argp, fmt);
181 vfprintf(stderr, fmt, argp);
182 va_end(argp);
183 if (adderr)
184 fprintf(stderr, ": ");
185 }
186 if (adderr)
187 fprintf(stderr, "%m");
188 fprintf(stderr, "\n");
189 if (doexit)
190 exit(excode);
191 }
192
193 #ifndef HAVE_ERR
194 # define err(E, FMT...) errmsg(1, E, 1, FMT)
195 #endif
196
197 #ifndef HAVE_ERRX
198 # define errx(E, FMT...) errmsg(1, E, 0, FMT)
199 #endif
200
201 #ifndef HAVE_WARN
202 # define warn(FMT...) errmsg(0, 0, 1, FMT)
203 #endif
204
205 #ifndef HAVE_WARNX
206 # define warnx(FMT...) errmsg(0, 0, 0, FMT)
207 #endif
208 #endif /* !HAVE_ERR_H */
209
210
211 /* Don't use inline function to avoid '#include "nls.h"' in c.h
212 */
213 #define errtryhelp(eval) __extension__ ({ \
214 fprintf(stderr, _("Try '%s --help' for more information.\n"), \
215 program_invocation_short_name); \
216 exit(eval); \
217 })
218
219 #define errtryh(eval) __extension__ ({ \
220 fprintf(stderr, _("Try '%s -h' for more information.\n"), \
221 program_invocation_short_name); \
222 exit(eval); \
223 })
224
225
226 static inline __attribute__((const)) int is_power_of_2(unsigned long num)
227 {
228 return (num != 0 && ((num & (num - 1)) == 0));
229 }
230
231 #ifndef HAVE_LOFF_T
232 typedef int64_t loff_t;
233 #endif
234
235 #if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) && defined(HAVE_DIR_DD_FD)
236 #include <sys/types.h>
237 #include <dirent.h>
238 static inline int dirfd(DIR *d)
239 {
240 return d->dd_fd;
241 }
242 #endif
243
244 /*
245 * Fallback defines for old versions of glibc
246 */
247 #include <fcntl.h>
248
249 #ifdef O_CLOEXEC
250 #define UL_CLOEXECSTR "e"
251 #else
252 #define UL_CLOEXECSTR ""
253 #endif
254
255 #ifndef O_CLOEXEC
256 #define O_CLOEXEC 0
257 #endif
258
259 #ifdef __FreeBSD_kernel__
260 #ifndef F_DUPFD_CLOEXEC
261 #define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */
262 #endif
263 #endif
264
265
266 #ifndef AI_ADDRCONFIG
267 #define AI_ADDRCONFIG 0x0020
268 #endif
269
270 #ifndef IUTF8
271 #define IUTF8 0040000
272 #endif
273
274 /*
275 * MAXHOSTNAMELEN replacement
276 */
277 static inline size_t get_hostname_max(void)
278 {
279 long len = sysconf(_SC_HOST_NAME_MAX);
280
281 if (0 < len)
282 return len;
283
284 #ifdef MAXHOSTNAMELEN
285 return MAXHOSTNAMELEN;
286 #elif HOST_NAME_MAX
287 return HOST_NAME_MAX;
288 #endif
289 return 64;
290 }
291
292 /*
293 * The usleep function was marked obsolete in POSIX.1-2001 and was removed
294 * in POSIX.1-2008. It was replaced with nanosleep() that provides more
295 * advantages (like no interaction with signals and other timer functions).
296 */
297 #include <time.h>
298
299 static inline int xusleep(useconds_t usec)
300 {
301 #ifdef HAVE_NANOSLEEP
302 struct timespec waittime = {
303 .tv_sec = usec / 1000000L,
304 .tv_nsec = (usec % 1000000L) * 1000
305 };
306 return nanosleep(&waittime, NULL);
307 #elif defined(HAVE_USLEEP)
308 return usleep(usec);
309 #else
310 # error "System with usleep() or nanosleep() required!"
311 #endif
312 }
313
314 /*
315 * Constant strings for usage() functions. For more info see
316 * Documentation/howto-usage-function.txt and disk-utils/delpart.c
317 */
318 #define USAGE_HEADER _("\nUsage:\n")
319 #define USAGE_OPTIONS _("\nOptions:\n")
320 #define USAGE_SEPARATOR "\n"
321 #define USAGE_HELP _(" -h, --help display this help and exit\n")
322 #define USAGE_VERSION _(" -V, --version output version information and exit\n")
323 #define USAGE_MAN_TAIL(_man) _("\nFor more details see %s.\n"), _man
324
325 #define UTIL_LINUX_VERSION _("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING
326
327 /*
328 * scanf modifiers for "strings allocation"
329 */
330 #ifdef HAVE_SCANF_MS_MODIFIER
331 #define UL_SCNsA "%ms"
332 #elif defined(HAVE_SCANF_AS_MODIFIER)
333 #define UL_SCNsA "%as"
334 #endif
335
336 /*
337 * seek stuff
338 */
339 #ifndef SEEK_DATA
340 # define SEEK_DATA 3
341 #endif
342 #ifndef SEEK_HOLE
343 # define SEEK_HOLE 4
344 #endif
345
346
347 /*
348 * Macros to convert #define'itions to strings, for example
349 * #define XYXXY 42
350 * printf ("%s=%s\n", stringify(XYXXY), stringify_value(XYXXY));
351 */
352 #define stringify_value(s) stringify(s)
353 #define stringify(s) #s
354
355 /*
356 * UL_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time
357 * instrumentation shipped with Clang and GCC) to not instrument the
358 * annotated function. Furthermore, it will prevent the compiler from
359 * inlining the function because inlining currently breaks the blacklisting
360 * mechanism of AddressSanitizer.
361 */
362 #if defined(__has_feature)
363 # if __has_feature(address_sanitizer)
364 # define UL_ASAN_BLACKLIST __attribute__((noinline)) __attribute__((no_sanitize_memory)) __attribute__((no_sanitize_address))
365 # else
366 # define UL_ASAN_BLACKLIST /* nothing */
367 # endif
368 #else
369 # define UL_ASAN_BLACKLIST /* nothing */
370 #endif
371
372
373
374 /*
375 * Note that sysconf(_SC_GETPW_R_SIZE_MAX) returns *initial* suggested size for
376 * pwd buffer and in some cases it is not large enough. See POSIX and
377 * getpwnam_r man page for more details.
378 */
379 #define UL_GETPW_BUFSIZ (16 * 1024)
380
381 /*
382 * Darwin or other BSDs may only have MAP_ANON. To get it on Darwin we must
383 * define _DARWIN_C_SOURCE before including sys/mman.h. We do this in config.h.
384 */
385 #if !defined MAP_ANONYMOUS && defined MAP_ANON
386 # define MAP_ANONYMOUS (MAP_ANON)
387 #endif
388
389 #endif /* UTIL_LINUX_C_H */
File src/utils/closestream.h added (mode: 100644) (index 0000000..2dfe113)
1 #ifndef UTIL_LINUX_CLOSESTREAM_H
2 #define UTIL_LINUX_CLOSESTREAM_H
3
4 #include <stdio.h>
5 #ifdef HAVE_STDIO_EXT_H
6 #include <stdio_ext.h>
7 #endif
8 #include <unistd.h>
9
10 #include "c.h"
11 #include "nls.h"
12
13 #ifndef CLOSE_EXIT_CODE
14 # define CLOSE_EXIT_CODE EXIT_FAILURE
15 #endif
16
17 #ifndef HAVE___FPENDING
18 static inline int
19 __fpending(FILE *stream __attribute__((__unused__)))
20 {
21 return 0;
22 }
23 #endif
24
25 static inline int
26 close_stream(FILE * stream)
27 {
28 const int some_pending = (__fpending(stream) != 0);
29 const int prev_fail = (ferror(stream) != 0);
30 const int fclose_fail = (fclose(stream) != 0);
31
32 if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) {
33 if (!fclose_fail && !(errno == EPIPE))
34 errno = 0;
35 return EOF;
36 }
37 return 0;
38 }
39
40 /* Meant to be used atexit(close_stdout); */
41 static inline void
42 close_stdout(void)
43 {
44 if (close_stream(stdout) != 0 && !(errno == EPIPE)) {
45 if (errno)
46 warn(_("write error"));
47 else
48 warnx(_("write error"));
49 _exit(CLOSE_EXIT_CODE);
50 }
51
52 if (close_stream(stderr) != 0)
53 _exit(CLOSE_EXIT_CODE);
54 }
55
56 #ifndef HAVE_FSYNC
57 static inline int
58 fsync(int fd __attribute__((__unused__)))
59 {
60 return 0;
61 }
62 #endif
63
64 static inline int
65 close_fd(int fd)
66 {
67 const int fsync_fail = (fsync(fd) != 0);
68 const int close_fail = (close(fd) != 0);
69
70 if (fsync_fail || close_fail)
71 return EOF;
72 return 0;
73 }
74
75 #endif /* UTIL_LINUX_CLOSESTREAM_H */
File src/utils/nls.h added (mode: 100644) (index 0000000..50f4f29)
1 #ifndef UTIL_LINUX_NLS_H
2 #define UTIL_LINUX_NLS_H
3
4 int main(int argc, char *argv[]);
5
6 #ifndef LOCALEDIR
7 #define LOCALEDIR "/usr/share/locale"
8 #endif
9
10 #ifdef HAVE_LOCALE_H
11 # include <locale.h>
12 #else
13 # undef setlocale
14 # define setlocale(Category, Locale) /* empty */
15 struct lconv
16 {
17 char *decimal_point;
18 };
19 # undef localeconv
20 # define localeconv() NULL
21 #endif
22
23
24 #ifdef ENABLE_NLS
25 # include <libintl.h>
26 /*
27 * For NLS support in the public shared libraries we have to specify text
28 * domain name to be independend on the main program. For this purpose define
29 * UL_TEXTDOMAIN_EXPLICIT before you include nls.h to your shared library code.
30 */
31 # ifdef UL_TEXTDOMAIN_EXPLICIT
32 # define _(Text) dgettext (UL_TEXTDOMAIN_EXPLICIT, Text)
33 # else
34 # define _(Text) gettext (Text)
35 # endif
36 # ifdef gettext_noop
37 # define N_(String) gettext_noop (String)
38 # else
39 # define N_(String) (String)
40 # endif
41 # define P_(Singular, Plural, n) ngettext (Singular, Plural, n)
42 #else
43 # undef bindtextdomain
44 # define bindtextdomain(Domain, Directory) /* empty */
45 # undef textdomain
46 # define textdomain(Domain) /* empty */
47 # define _(Text) (Text)
48 # define N_(Text) (Text)
49 # define P_(Singular, Plural, n) ((n) == 1 ? (Singular) : (Plural))
50 #endif /* ENABLE_NLS */
51
52 #ifdef HAVE_LANGINFO_H
53 # include <langinfo.h>
54 #else
55
56 typedef int nl_item;
57 extern char *langinfo_fallback(nl_item item);
58
59 # define nl_langinfo langinfo_fallback
60
61 enum {
62 CODESET = 1,
63 RADIXCHAR,
64 THOUSEP,
65 D_T_FMT,
66 D_FMT,
67 T_FMT,
68 T_FMT_AMPM,
69 AM_STR,
70 PM_STR,
71
72 DAY_1,
73 DAY_2,
74 DAY_3,
75 DAY_4,
76 DAY_5,
77 DAY_6,
78 DAY_7,
79
80 ABDAY_1,
81 ABDAY_2,
82 ABDAY_3,
83 ABDAY_4,
84 ABDAY_5,
85 ABDAY_6,
86 ABDAY_7,
87
88 MON_1,
89 MON_2,
90 MON_3,
91 MON_4,
92 MON_5,
93 MON_6,
94 MON_7,
95 MON_8,
96 MON_9,
97 MON_10,
98 MON_11,
99 MON_12,
100
101 ABMON_1,
102 ABMON_2,
103 ABMON_3,
104 ABMON_4,
105 ABMON_5,
106 ABMON_6,
107 ABMON_7,
108 ABMON_8,
109 ABMON_9,
110 ABMON_10,
111 ABMON_11,
112 ABMON_12,
113
114 ERA_D_FMT,
115 ERA_D_T_FMT,
116 ERA_T_FMT,
117 ALT_DIGITS,
118 CRNCYSTR,
119 YESEXPR,
120 NOEXPR
121 };
122
123 #endif /* !HAVE_LANGINFO_H */
124
125 #endif /* UTIL_LINUX_NLS_H */
File src/utils/randutils.h added (mode: 100644) (index 0000000..86e35f3)
1 #ifndef UTIL_LINUX_RANDUTILS
2 #define UTIL_LINUX_RANDUTILS
3
4 #ifdef HAVE_SRANDOM
5 #define srand(x) srandom(x)
6 #define rand() random()
7 #endif
8
9 /* rand() based */
10 extern int rand_get_number(int low_n, int high_n);
11
12 /* /dev/urandom based with fallback to rand() */
13 extern int random_get_fd(void);
14 extern void random_get_bytes(void *buf, size_t nbytes);
15 extern const char *random_tell_source(void);
16
17 #endif
File src/utils/strutils.h added (mode: 100644) (index 0000000..28c1b5e)
1 #ifndef UTIL_LINUX_STRUTILS
2 #define UTIL_LINUX_STRUTILS
3
4 #include <stdlib.h>
5 #include <inttypes.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <errno.h>
11
12 /* default strtoxx_or_err() exit code */
13 #ifndef STRTOXX_EXIT_CODE
14 # define STRTOXX_EXIT_CODE EXIT_FAILURE
15 #endif
16
17
18 extern int parse_size(const char *str, uintmax_t *res, int *power);
19 extern int strtosize(const char *str, uintmax_t *res);
20 extern uintmax_t strtosize_or_err(const char *str, const char *errmesg);
21
22 extern int16_t strtos16_or_err(const char *str, const char *errmesg);
23 extern uint16_t strtou16_or_err(const char *str, const char *errmesg);
24 extern uint16_t strtox16_or_err(const char *str, const char *errmesg);
25
26 extern int32_t strtos32_or_err(const char *str, const char *errmesg);
27 extern uint32_t strtou32_or_err(const char *str, const char *errmesg);
28 extern uint32_t strtox32_or_err(const char *str, const char *errmesg);
29
30 extern int64_t strtos64_or_err(const char *str, const char *errmesg);
31 extern uint64_t strtou64_or_err(const char *str, const char *errmesg);
32 extern uint64_t strtox64_or_err(const char *str, const char *errmesg);
33
34 extern double strtod_or_err(const char *str, const char *errmesg);
35
36 extern long strtol_or_err(const char *str, const char *errmesg);
37 extern unsigned long strtoul_or_err(const char *str, const char *errmesg);
38
39 extern void strtotimeval_or_err(const char *str, struct timeval *tv,
40 const char *errmesg);
41
42 extern int isdigit_strend(const char *str, const char **end);
43 #define isdigit_string(_s) isdigit_strend(_s, NULL)
44
45 extern int isxdigit_strend(const char *str, const char **end);
46 #define isxdigit_string(_s) isxdigit_strend(_s, NULL)
47
48
49 extern int parse_switch(const char *arg, const char *errmesg, ...);
50
51 #ifndef HAVE_MEMPCPY
52 extern void *mempcpy(void *restrict dest, const void *restrict src, size_t n);
53 #endif
54 #ifndef HAVE_STRNLEN
55 extern size_t strnlen(const char *s, size_t maxlen);
56 #endif
57 #ifndef HAVE_STRNDUP
58 extern char *strndup(const char *s, size_t n);
59 #endif
60 #ifndef HAVE_STRNCHR
61 extern char *strnchr(const char *s, size_t maxlen, int c);
62 #endif
63
64 /* caller guarantees n > 0 */
65 static inline void xstrncpy(char *dest, const char *src, size_t n)
66 {
67 strncpy(dest, src, n-1);
68 dest[n-1] = 0;
69 }
70
71 static inline int strdup_to_offset(void *stru, size_t offset, const char *str)
72 {
73 char *n = NULL;
74 char **o;
75
76 if (!stru)
77 return -EINVAL;
78
79 o = (char **) ((char *) stru + offset);
80 if (str) {
81 n = strdup(str);
82 if (!n)
83 return -ENOMEM;
84 }
85
86 free(*o);
87 *o = n;
88 return 0;
89 }
90
91 #define strdup_to_struct_member(_s, _m, _str) \
92 strdup_to_offset((void *) _s, offsetof(__typeof__(*(_s)), _m), _str)
93
94 extern void xstrmode(mode_t mode, char *str);
95
96 /* Options for size_to_human_string() */
97 enum
98 {
99 SIZE_SUFFIX_1LETTER = 0,
100 SIZE_SUFFIX_3LETTER = 1,
101 SIZE_SUFFIX_SPACE = 2
102 };
103
104 extern char *size_to_human_string(int options, uint64_t bytes);
105
106 extern int string_to_idarray(const char *list, int ary[], size_t arysz,
107 int (name2id)(const char *, size_t));
108 extern int string_add_to_idarray(const char *list, int ary[],
109 size_t arysz, size_t *ary_pos,
110 int (name2id)(const char *, size_t));
111
112 extern int string_to_bitarray(const char *list, char *ary,
113 int (*name2bit)(const char *, size_t));
114
115 extern int string_to_bitmask(const char *list,
116 unsigned long *mask,
117 long (*name2flag)(const char *, size_t));
118 extern int parse_range(const char *str, int *lower, int *upper, int def);
119
120 extern int streq_paths(const char *a, const char *b);
121
122 /*
123 * Match string beginning.
124 */
125 static inline const char *startswith(const char *s, const char *prefix)
126 {
127 size_t sz = prefix ? strlen(prefix) : 0;
128
129 if (s && sz && strncmp(s, prefix, sz) == 0)
130 return s + sz;
131 return NULL;
132 }
133
134 /*
135 * Case insensitive match string beginning.
136 */
137 static inline const char *startswith_no_case(const char *s, const char *prefix)
138 {
139 size_t sz = prefix ? strlen(prefix) : 0;
140
141 if (s && sz && strncasecmp(s, prefix, sz) == 0)
142 return s + sz;
143 return NULL;
144 }
145
146 /*
147 * Match string ending.
148 */
149 static inline const char *endswith(const char *s, const char *postfix)
150 {
151 size_t sl = s ? strlen(s) : 0;
152 size_t pl = postfix ? strlen(postfix) : 0;
153
154 if (pl == 0)
155 return (char *)s + sl;
156 if (sl < pl)
157 return NULL;
158 if (memcmp(s + sl - pl, postfix, pl) != 0)
159 return NULL;
160 return (char *)s + sl - pl;
161 }
162
163 /*
164 * Skip leading white space.
165 */
166 static inline const char *skip_space(const char *p)
167 {
168 while (isspace(*p))
169 ++p;
170 return p;
171 }
172
173 static inline const char *skip_blank(const char *p)
174 {
175 while (isblank(*p))
176 ++p;
177 return p;
178 }
179
180
181 /* Removes whitespace from the right-hand side of a string (trailing
182 * whitespace).
183 *
184 * Returns size of the new string (without \0).
185 */
186 static inline size_t rtrim_whitespace(unsigned char *str)
187 {
188 size_t i;
189
190 if (!str)
191 return 0;
192 i = strlen((char *) str);
193 while (i) {
194 i--;
195 if (!isspace(str[i])) {
196 i++;
197 break;
198 }
199 }
200 str[i] = '\0';
201 return i;
202 }
203
204 /* Removes whitespace from the left-hand side of a string.
205 *
206 * Returns size of the new string (without \0).
207 */
208 static inline size_t ltrim_whitespace(unsigned char *str)
209 {
210 size_t len;
211 unsigned char *p;
212
213 if (!str)
214 return 0;
215 for (p = str; *p && isspace(*p); p++);
216
217 len = strlen((char *) p);
218
219 if (len && p > str)
220 memmove(str, p, len + 1);
221
222 return len;
223 }
224
225 extern char *strnappend(const char *s, const char *suffix, size_t b);
226 extern char *strappend(const char *s, const char *suffix);
227 extern char *strfappend(const char *s, const char *format, ...)
228 __attribute__ ((__format__ (__printf__, 2, 0)));
229 extern const char *split(const char **state, size_t *l, const char *separator, int quoted);
230
231 extern int skip_fline(FILE *fp);
232
233 #endif
File src/uuid.h added (mode: 100644) (index 0000000..30bd4c0)
1 /*
2 * Public include file for the UUID library
3 *
4 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #ifndef _UUID_UUID_H
36 #define _UUID_UUID_H
37
38 #include <sys/types.h>
39 #ifndef _WIN32
40 #include <sys/time.h>
41 #endif
42 #include <time.h>
43
44 typedef unsigned char uuid_t[16];
45
46 /* UUID Variant definitions */
47 #define UUID_VARIANT_NCS 0
48 #define UUID_VARIANT_DCE 1
49 #define UUID_VARIANT_MICROSOFT 2
50 #define UUID_VARIANT_OTHER 3
51
52 /* UUID Type definitions */
53 #define UUID_TYPE_DCE_TIME 1
54 #define UUID_TYPE_DCE_RANDOM 4
55
56 /* Allow UUID constants to be defined */
57 #ifdef __GNUC__
58 #define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
59 static const uuid_t name __attribute__ ((unused)) = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
60 #else
61 #define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
62 static const uuid_t name = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
63 #endif
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
69 /* clear.c */
70 extern void uuid_clear(uuid_t uu);
71
72 /* compare.c */
73 extern int uuid_compare(const uuid_t uu1, const uuid_t uu2);
74
75 /* copy.c */
76 extern void uuid_copy(uuid_t dst, const uuid_t src);
77
78 /* gen_uuid.c */
79 extern void uuid_generate(uuid_t out);
80 extern void uuid_generate_random(uuid_t out);
81 extern void uuid_generate_time(uuid_t out);
82 extern int uuid_generate_time_safe(uuid_t out);
83
84 /* isnull.c */
85 extern int uuid_is_null(const uuid_t uu);
86
87 /* parse.c */
88 extern int uuid_parse(const char *in, uuid_t uu);
89
90 /* unparse.c */
91 extern void uuid_unparse(const uuid_t uu, char *out);
92 extern void uuid_unparse_lower(const uuid_t uu, char *out);
93 extern void uuid_unparse_upper(const uuid_t uu, char *out);
94
95 /* uuid_time.c */
96 extern time_t uuid_time(const uuid_t uu, struct timeval *ret_tv);
97 extern int uuid_type(const uuid_t uu);
98 extern int uuid_variant(const uuid_t uu);
99
100 #ifdef __cplusplus
101 }
102 #endif
103
104 #endif /* _UUID_UUID_H */
File src/uuidP.h added (mode: 100644) (index 0000000..86a5e26)
1 /*
2 * uuid.h -- private header file for uuids
3 *
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #include <inttypes.h>
36 #include <sys/types.h>
37
38 #include "uuid.h"
39
40 #define LIBUUID_CLOCK_FILE "/var/lib/libuuid/clock.txt"
41
42 /*
43 * Offset between 15-Oct-1582 and 1-Jan-70
44 */
45 #define TIME_OFFSET_HIGH 0x01B21DD2
46 #define TIME_OFFSET_LOW 0x13814000
47
48 struct uuid {
49 uint32_t time_low;
50 uint16_t time_mid;
51 uint16_t time_hi_and_version;
52 uint16_t clock_seq;
53 uint8_t node[6];
54 };
55
56
57 /*
58 * prototypes
59 */
60 void uuid_pack(const struct uuid *uu, uuid_t ptr);
61 void uuid_unpack(const uuid_t in, struct uuid *uu);
File src/uuid_time.c added (mode: 100644) (index 0000000..a418ab7)
1 /*
2 * uuid_time.c --- Interpret the time field from a uuid. This program
3 * violates the UUID abstraction barrier by reaching into the guts
4 * of a UUID and interpreting it.
5 *
6 * Copyright (C) 1998, 1999 Theodore Ts'o.
7 *
8 * %Begin-Header%
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, and the entire permission notice in its entirety,
14 * including the disclaimer of warranties.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote
19 * products derived from this software without specific prior
20 * written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
25 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
33 * DAMAGE.
34 * %End-Header%
35 */
36
37 #include "config.h"
38
39 #ifdef _WIN32
40 #define _WIN32_WINNT 0x0500
41 #include <windows.h>
42 #define UUID MYUUID
43 #endif
44
45 #include <stdio.h>
46 #ifdef HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif
49 #include <stdlib.h>
50 #include <sys/types.h>
51 #ifdef HAVE_SYS_TIME_H
52 #include <sys/time.h>
53 #endif
54 #include <time.h>
55
56 #include "namespace.h"
57 #include "uuidP.h"
58
59 time_t uuid_time(const uuid_t uu, struct timeval *ret_tv)
60 {
61 struct timeval tv;
62 struct uuid uuid;
63 uint32_t high;
64 uint64_t clock_reg;
65
66 uuid_unpack(uu, &uuid);
67
68 high = uuid.time_mid | ((uuid.time_hi_and_version & 0xFFF) << 16);
69 clock_reg = uuid.time_low | ((uint64_t) high << 32);
70
71 clock_reg -= (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
72 tv.tv_sec = clock_reg / 10000000;
73 tv.tv_usec = (clock_reg % 10000000) / 10;
74
75 if (ret_tv)
76 *ret_tv = tv;
77
78 return tv.tv_sec;
79 }
80
81 int uuid_type(const uuid_t uu)
82 {
83 struct uuid uuid;
84
85 uuid_unpack(uu, &uuid);
86 return ((uuid.time_hi_and_version >> 12) & 0xF);
87 }
88
89 int uuid_variant(const uuid_t uu)
90 {
91 struct uuid uuid;
92 int var;
93
94 uuid_unpack(uu, &uuid);
95 var = uuid.clock_seq;
96
97 if ((var & 0x8000) == 0)
98 return UUID_VARIANT_NCS;
99 if ((var & 0x4000) == 0)
100 return UUID_VARIANT_DCE;
101 if ((var & 0x2000) == 0)
102 return UUID_VARIANT_MICROSOFT;
103 return UUID_VARIANT_OTHER;
104 }
105
106 #ifdef DEBUG
107 static const char *variant_string(int variant)
108 {
109 switch (variant) {
110 case UUID_VARIANT_NCS:
111 return "NCS";
112 case UUID_VARIANT_DCE:
113 return "DCE";
114 case UUID_VARIANT_MICROSOFT:
115 return "Microsoft";
116 default:
117 return "Other";
118 }
119 }
120
121
122 int
123 main(int argc, char **argv)
124 {
125 uuid_t buf;
126 time_t time_reg;
127 struct timeval tv;
128 int type, variant;
129
130 if (argc != 2) {
131 fprintf(stderr, "Usage: %s uuid\n", argv[0]);
132 exit(1);
133 }
134 if (uuid_parse(argv[1], buf)) {
135 fprintf(stderr, "Invalid UUID: %s\n", argv[1]);
136 exit(1);
137 }
138 variant = uuid_variant(buf);
139 type = uuid_type(buf);
140 time_reg = uuid_time(buf, &tv);
141
142 printf("UUID variant is %d (%s)\n", variant, variant_string(variant));
143 if (variant != UUID_VARIANT_DCE) {
144 printf("Warning: This program only knows how to interpret "
145 "DCE UUIDs.\n\tThe rest of the output is likely "
146 "to be incorrect!!\n");
147 }
148 printf("UUID type is %d", type);
149 switch (type) {
150 case 1:
151 printf(" (time based)\n");
152 break;
153 case 2:
154 printf(" (DCE)\n");
155 break;
156 case 3:
157 printf(" (name-based)\n");
158 break;
159 case 4:
160 printf(" (random)\n");
161 break;
162 default:
163 printf("\n");
164 }
165 if (type != 1) {
166 printf("Warning: not a time-based UUID, so UUID time "
167 "decoding will likely not work!\n");
168 }
169 printf("UUID time is: (%ld, %ld): %s\n", (long)tv.tv_sec, (long)tv.tv_usec,
170 ctime(&time_reg));
171
172 return 0;
173 }
174 #endif
File src/uuidd.h added (mode: 100644) (index 0000000..2f70968)
1 /*
2 * Definitions used by the uuidd daemon
3 *
4 * Copyright (C) 2007 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 * %End-Header%
33 */
34
35 #ifndef _UUID_UUIDD_H
36 #define _UUID_UUIDD_H
37
38 #define UUIDD_DIR _PATH_LOCALSTATEDIR "/uuidd"
39 #define UUIDD_SOCKET_PATH UUIDD_DIR "/request"
40 #define UUIDD_PIDFILE_PATH UUIDD_DIR "/uuidd.pid"
41 #define UUIDD_PATH "/usr/sbin/uuidd"
42
43 #define UUIDD_OP_GETPID 0
44 #define UUIDD_OP_GET_MAXOP 1
45 #define UUIDD_OP_TIME_UUID 2
46 #define UUIDD_OP_RANDOM_UUID 3
47 #define UUIDD_OP_BULK_TIME_UUID 4
48 #define UUIDD_OP_BULK_RANDOM_UUID 5
49 #define UUIDD_MAX_OP UUIDD_OP_BULK_RANDOM_UUID
50
51 extern int __uuid_generate_time(uuid_t out, int *num);
52 extern void __uuid_generate_random(uuid_t out, int *num);
53
54 #endif /* _UUID_UUID_H */
File src/uuidgen.c added (mode: 100644) (index 0000000..fd1cdcc)
1 /*
2 * gen_uuid.c --- generate a DCE-compatible uuid
3 *
4 * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
5 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Public
8 * License.
9 * %End-Header%
10 */
11
12 #include "config.h"
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <getopt.h>
17
18 #include "namespace.h"
19 #include "uuid.h"
20 #include "nls.h"
21 #include "c.h"
22 #include "closestream.h"
23
24 static void __attribute__ ((__noreturn__)) usage(FILE * out)
25 {
26 fputs(USAGE_HEADER, out);
27 fprintf(out,
28 _(" %s [options]\n"), program_invocation_short_name);
29
30 fputs(USAGE_SEPARATOR, out);
31 fputs(_("Create a new UUID value.\n"), out);
32
33 fputs(USAGE_OPTIONS, out);
34 fputs(_(" -r, --random generate random-based uuid\n"
35 " -t, --time generate time-based uuid\n"
36 " -V, --version output version information and exit\n"
37 " -h, --help display this help and exit\n\n"), out);
38
39 fprintf(out, USAGE_MAN_TAIL("uuidgen(1)"));
40 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
41 }
42
43 int
44 main (int argc, char *argv[])
45 {
46 int c;
47 int do_type = 0;
48 char str[37];
49 uuid_t uu;
50
51 static const struct option longopts[] = {
52 {"random", no_argument, NULL, 'r'},
53 {"time", no_argument, NULL, 't'},
54 {"version", no_argument, NULL, 'V'},
55 {"help", no_argument, NULL, 'h'},
56 {NULL, 0, NULL, 0}
57 };
58
59 setlocale(LC_ALL, "");
60 bindtextdomain(PACKAGE, LOCALEDIR);
61 textdomain(PACKAGE);
62 atexit(close_stdout);
63
64 while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
65 switch (c) {
66 case 't':
67 do_type = UUID_TYPE_DCE_TIME;
68 break;
69 case 'r':
70 do_type = UUID_TYPE_DCE_RANDOM;
71 break;
72 case 'V':
73 printf(UTIL_LINUX_VERSION);
74 return EXIT_SUCCESS;
75 case 'h':
76 usage(stdout);
77 default:
78 errtryhelp(EXIT_FAILURE);
79 }
80
81 switch (do_type) {
82 case UUID_TYPE_DCE_TIME:
83 uuid_generate_time(uu);
84 break;
85 case UUID_TYPE_DCE_RANDOM:
86 uuid_generate_random(uu);
87 break;
88 default:
89 uuid_generate(uu);
90 break;
91 }
92
93 uuid_unparse(uu, str);
94
95 printf("%s\n", str);
96
97 return EXIT_SUCCESS;
98 }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/nyanuuid

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/nyanuuid

Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/nyanuuid

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main