11e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o/* 219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * unparse.c -- convert a UUID to string 3efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * 419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Copyright (C) 1996, 1997 Theodore Ts'o. 519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * 619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %Begin-Header% 71bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * Redistribution and use in source and binary forms, with or without 81bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * modification, are permitted provided that the following conditions 91bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * are met: 101bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * 1. Redistributions of source code must retain the above copyright 111bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * notice, and the entire permission notice in its entirety, 121bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * including the disclaimer of warranties. 131bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * 2. Redistributions in binary form must reproduce the above copyright 141bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * notice, this list of conditions and the following disclaimer in the 151bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * documentation and/or other materials provided with the distribution. 161bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * 3. The name of the author may not be used to endorse or promote 171bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * products derived from this software without specific prior 181bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * written permission. 19efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * 201bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 211bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 221bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 231bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 241bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 251bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 261bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 271bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 281bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 291bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 301bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 311bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * DAMAGE. 3219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %End-Header% 331e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o */ 341e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#include <stdio.h> 361e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 371e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#include "uuidP.h" 381e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 39efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'ostatic const char *fmt_lower = 40d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"; 41d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o 42efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'ostatic const char *fmt_upper = 43d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"; 44d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o 45d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o#ifdef UUID_UNPARSE_DEFAULT_UPPER 46d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o#define FMT_DEFAULT fmt_upper 47d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o#else 48d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o#define FMT_DEFAULT fmt_lower 49d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o#endif 50d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o 51d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'ostatic void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt) 521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{ 531e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o struct uuid uuid; 541e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o uuid_unpack(uu, &uuid); 56d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o sprintf(out, fmt, 571e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, 581e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, 591e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o uuid.node[0], uuid.node[1], uuid.node[2], 601e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o uuid.node[3], uuid.node[4], uuid.node[5]); 611e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o} 621e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 63d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'ovoid uuid_unparse_lower(const uuid_t uu, char *out) 64d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o{ 65d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o uuid_unparse_x(uu, out, fmt_lower); 66d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o} 67d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o 68d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'ovoid uuid_unparse_upper(const uuid_t uu, char *out) 69d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o{ 70d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o uuid_unparse_x(uu, out, fmt_upper); 71d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o} 72d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o 73d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'ovoid uuid_unparse(const uuid_t uu, char *out) 74d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o{ 75d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o uuid_unparse_x(uu, out, FMT_DEFAULT); 76d3d741fc383d3eb1f8636393bc1c68c9bd467cc0Theodore Ts'o} 77