--- uuid_cli.c 2004/02/13 14:29:32 1.15
+++ uuid_cli.c 2004/02/13 16:17:07 1.16
@@ -71,6 +71,8 @@
/* main procedure */
int main(int argc, char *argv[])
{
+ char uuid_buf_bin[UUID_LEN_BIN];
+ char uuid_buf_str[UUID_LEN_STR+1];
uuid_t *uuid;
uuid_t *uuid_ns;
uuid_rc_t rc;
@@ -147,14 +149,33 @@
if (decode) {
/* decoding */
- if (argc != 1)
- usage("invalid number of arguments");
if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
error(1, "uuid_create: %s", uuid_error(rc));
- if (strlen(argv[0]) != UUID_LEN_STR)
- error(1, "invalid length of UUID string representation");
- if ((rc = uuid_import(uuid, UUID_FMT_STR, argv[0], strlen(argv[0]))) != UUID_RC_OK)
- error(1, "uuid_import: %s", uuid_error(rc));
+ if (argc != 1)
+ usage("invalid number of arguments");
+ if (strcmp(argv[0], "-") == 0) {
+ if (raw) {
+ if (fread(uuid_buf_bin, UUID_LEN_BIN, 1, stdin) != 1)
+ error(1, "fread: failed to read %d (UUID_LEN_BIN) bytes from stdin", UUID_LEN_BIN);
+ if ((rc = uuid_import(uuid, UUID_FMT_BIN, uuid_buf_bin, UUID_LEN_BIN)) != UUID_RC_OK)
+ error(1, "uuid_import: %s", uuid_error(rc));
+ }
+ else {
+ if (fread(uuid_buf_str, UUID_LEN_STR, 1, stdin) != 1)
+ error(1, "fread: failed to read %d (UUID_LEN_STR) bytes from stdin", UUID_LEN_STR);
+ uuid_buf_str[UUID_LEN_STR] = '\0';
+ if ((rc = uuid_import(uuid, UUID_FMT_STR, uuid_buf_str, UUID_LEN_STR)) != UUID_RC_OK)
+ error(1, "uuid_import: %s", uuid_error(rc));
+ }
+ }
+ else {
+ if (raw)
+ error(1, "raw input mode only possible if reading from stdin");
+ if (strlen(argv[0]) != UUID_LEN_STR)
+ error(1, "invalid length of UUID string representation");
+ if ((rc = uuid_import(uuid, UUID_FMT_STR, argv[0], strlen(argv[0]))) != UUID_RC_OK)
+ error(1, "uuid_import: %s", uuid_error(rc));
+ }
vp = NULL;
if ((rc = uuid_export(uuid, UUID_FMT_TXT, &vp, NULL)) != UUID_RC_OK)
error(1, "uuid_export: %s", uuid_error(rc));
|