Print this page
4118 libuuid should provide uuid_unparse_{upper,lower} functions
Reviewed by: Serghei Samsi <sscdvp@gmail.com>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libuuid/common/uuid.c
          +++ new/usr/src/lib/libuuid/common/uuid.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   * Copyright 2012 Milan Jurik. All rights reserved.
  25   25   * Copyright 2013 Joyent, Inc. All rights reserved.
       26 + * Copyright 2014 Andrew Stormont.
  26   27   */
  27   28  
  28   29  /*
  29   30   * The copyright in this file is taken from the original Leach & Salz
  30   31   * UUID specification, from which this implementation is derived.
  31   32   */
  32   33  
  33   34  /*
  34   35   * Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
  35   36   * Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
↓ open down ↓ 535 lines elided ↑ open up ↑
 571  572  uuid_clear(uuid_t uu)
 572  573  {
 573  574          (void) memset(uu, 0, UUID_LEN);
 574  575  }
 575  576  
 576  577  /*
 577  578   * This function converts the supplied UUID uu from the internal
 578  579   * binary format into a 36-byte string (plus trailing null char)
 579  580   * and stores this value in the character string pointed to by out.
 580  581   */
 581      -void
 582      -uuid_unparse(uuid_t uu, char *out)
      582 +static void
      583 +uuid_unparse_common(uuid_t uu, char *out, boolean_t upper)
 583  584  {
 584  585          struct uuid     uuid;
 585  586          uint16_t        clock_seq;
 586  587          char            etheraddr[13];
 587  588          int             index = 0, i;
 588  589  
 589  590          /* basic sanity checking */
 590  591          if (uu == NULL) {
 591  592                  return;
 592  593          }
 593  594  
 594      -        /* XXX user should have allocated enough memory */
 595      -        /*
 596      -         * if (strlen(out) < UUID_PRINTABLE_STRING_LENGTH) {
 597      -         * return;
 598      -         * }
 599      -         */
 600  595          string_to_struct(&uuid, uu);
 601  596          clock_seq = uuid.clock_seq_hi_and_reserved;
 602  597          clock_seq = (clock_seq  << 8) | uuid.clock_seq_low;
 603  598          for (i = 0; i < 6; i++) {
 604      -                (void) sprintf(&etheraddr[index++], "%.2x", uuid.node_addr[i]);
      599 +                (void) sprintf(&etheraddr[index++], upper ? "%.2X" : "%.2x",
      600 +                    uuid.node_addr[i]);
 605  601                  index++;
 606  602          }
 607  603          etheraddr[index] = '\0';
 608  604  
 609      -        (void) snprintf(out, 25, "%08x-%04x-%04x-%04x-",
      605 +        (void) snprintf(out, 25,
      606 +            upper ? "%08X-%04X-%04X-%04X-" : "%08x-%04x-%04x-%04x-",
 610  607              uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, clock_seq);
 611  608          (void) strlcat(out, etheraddr, UUID_PRINTABLE_STRING_LENGTH);
 612  609  }
 613  610  
      611 +void
      612 +uuid_unparse_upper(uuid_t uu, char *out)
      613 +{
      614 +        uuid_unparse_common(uu, out, B_TRUE);
      615 +}
      616 +
      617 +void
      618 +uuid_unparse_lower(uuid_t uu, char *out)
      619 +{
      620 +        uuid_unparse_common(uu, out, B_FALSE);
      621 +}
      622 +
      623 +void
      624 +uuid_unparse(uuid_t uu, char *out)
      625 +{
      626 +        /*
      627 +         * Historically uuid_unparse on Solaris returns lower case,
      628 +         * for compatibility we preserve this behaviour.
      629 +         */
      630 +        uuid_unparse_common(uu, out, B_FALSE);
      631 +}
      632 +
 614  633  /*
 615  634   * The uuid_is_null function compares the value of the supplied
 616  635   * UUID variable uu to the NULL value. If the value is equal
 617  636   * to the NULL UUID, 1 is returned, otherwise 0 is returned.
 618  637   */
 619  638  int
 620  639  uuid_is_null(uuid_t uu)
 621  640  {
 622  641          int             i;
 623  642          uuid_t          null_uu;
↓ open down ↓ 102 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX