You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/07/22 00:42:11 UTC

[GitHub] [incubator-nuttx] btashton commented on a change in pull request #1440: libc: Add uuid implemenation

btashton commented on a change in pull request #1440:
URL: https://github.com/apache/incubator-nuttx/pull/1440#discussion_r458463783



##########
File path: libs/libc/uuid/lib_uuid_from_string.c
##########
@@ -0,0 +1,113 @@
+/****************************************************************************
+ * libs/libc/uuid/lib_uuid_from_string.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <uuid.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * uuid_from_string
+ *
+ * Description:
+ *   convert a string representation of an UUID into a binary representation.
+ *
+ * See also:
+ *   http://www.opengroup.org/onlinepubs/009629399/uuid_from_string.htm
+ *
+ ****************************************************************************/
+
+void uuid_from_string(const char *s, uuid_t *u, uint32_t *status)
+{
+  int n;
+
+  /* Short-circuit 2 special cases: NULL pointer and empty string. */
+
+  if (s == NULL || *s == '\0')
+    {
+      uuid_create_nil(u, status);
+      return;
+    }
+
+  /* Assume the worst. */
+
+  if (status != NULL)
+    {
+      *status = uuid_s_invalid_string_uuid;
+    }
+
+  /* The UUID string representation has a fixed length. */
+
+  if (strlen(s) != UUID_STR_LEN)

Review comment:
       Should we protect this with `strnlen(s, UUID_STR_LEN+1)`

##########
File path: libs/libc/uuid/lib_uuid_stream.c
##########
@@ -0,0 +1,181 @@
+/****************************************************************************
+ * libs/libc/uuid/lib_uuid_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <endian.h>
+#include <uuid.h>
+
+/****************************************************************************

Review comment:
       Did this code come from NetBSD?  It looks a lot like the code here
   http://mirrors.mit.edu/NetBSD/NetBSD-release-7/src/lib/libc/uuid/uuid_stream.c
   
   If so my understanding is that we would leave the BSD headers on this and call it out in the LICENSE file

##########
File path: libs/libc/uuid/lib_uuid_stream.c
##########
@@ -0,0 +1,181 @@
+/****************************************************************************
+ * libs/libc/uuid/lib_uuid_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <endian.h>
+#include <uuid.h>
+
+/****************************************************************************
+ * Encode/Decode UUID into octet-stream.
+ *   http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
+ *
+ * 0                   1                   2                   3
+ *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |                          time_low                             |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |       time_mid                |         time_hi_and_version   |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |clk_seq_hi_res |  clk_seq_low  |         node (0-1)            |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |                         node (2-5)                            |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ ****************************************************************************/
+
+/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
+
+static inline uint16_t be16dec(const void *pp)

Review comment:
       These endian functions dont seem to be uuid specific.  Normally they are defined via `<machine/endian.h>` or `<endian.h>` OS specific location.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org