<pre style='margin:0'>
Christopher Nielsen (mascguy) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/b9309fc8069d1a4ecb0c35397026036d44c38e61">https://github.com/macports/macports-legacy-support/commit/b9309fc8069d1a4ecb0c35397026036d44c38e61</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit b9309fc8069d1a4ecb0c35397026036d44c38e61
</span>Author: raf <raf@raf.org>
AuthorDate: Wed Jul 17 12:47:04 2024 +1000
<span style='display:block; white-space:pre;color:#404040;'> Add tests for fgetattrlist() and fsetattrlist()
</span>---
manual_tests/darwin_c.c | 1 +
test/test_fgetattrlist.c | 68 ++++++++++++++++++++++++++++++++++
test/test_fsetattrlist.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 164 insertions(+)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/manual_tests/darwin_c.c b/manual_tests/darwin_c.c
</span><span style='display:block; white-space:pre;color:#808080;'>index bcc04ef..70aca67 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/manual_tests/darwin_c.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/manual_tests/darwin_c.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -212,6 +212,7 @@ int timespec_get = 0;
</span> #ifdef _SC_PHYS_PAGES
#error _SC_PHYS_PAGES is unexpectedly defined
#endif
<span style='display:block; white-space:pre;background:#e0ffe0;'>+int fgetattrlist = 0;
</span> int fsetattrlist = 0;
#endif /* __DARWIN_C_LEVEL < __DARWIN_C_FULL */
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/test/test_fgetattrlist.c b/test/test_fgetattrlist.c
</span>new file mode 100644
<span style='display:block; white-space:pre;color:#808080;'>index 0000000..63816c2
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>--- /dev/null
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/test/test_fgetattrlist.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -0,0 +1,68 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/*
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Copyright (C) 2024 raf <raf@raf.org>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Permission to use, copy, modify, and distribute this software for any
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * purpose with or without fee is hereby granted, provided that the above
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * copyright notice and this permission notice appear in all copies.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Based on the first example in the getattrlist(2) manual entry */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <assert.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stdlib.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stdio.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <string.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <fcntl.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <unistd.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/attr.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/errno.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/vnode.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef struct attrlist attrlist_t;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+struct FInfoAttrBuf {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ u_int32_t length;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fsobj_type_t objType;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char finderInfo[32];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+} __attribute__((aligned(4), packed));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef struct FInfoAttrBuf FInfoAttrBuf;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static int FInfoDemo(int fd)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int err;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrlist_t attrList;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ FInfoAttrBuf attrBuf;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ memset(&attrList, 0, sizeof(attrList));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = fgetattrlist(fd, &attrList, &attrBuf, sizeof(attrBuf), 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (err != 0)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = errno;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (err == 0)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert(attrBuf.length == sizeof(attrBuf));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return err;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Note: Not an exhaustive test. Just call fgetattrlist(). */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int main(int ac, char **av)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int rc = (FInfoDemo(open(".", O_RDONLY)) == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (rc != EXIT_SUCCESS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("fgetattrlist() failed, possibly correctly due to an unexpected filesystem type\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return rc;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* vi:set et ts=4 sw=4: */
</span><span style='display:block; white-space:pre;color:#808080;'>diff --git a/test/test_fsetattrlist.c b/test/test_fsetattrlist.c
</span>new file mode 100644
<span style='display:block; white-space:pre;color:#808080;'>index 0000000..741f6c9
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>--- /dev/null
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/test/test_fsetattrlist.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -0,0 +1,95 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/*
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Copyright (C) 2024 raf <raf@raf.org>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Permission to use, copy, modify, and distribute this software for any
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * purpose with or without fee is hereby granted, provided that the above
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * copyright notice and this permission notice appear in all copies.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Based on the first example in the getattrlist(2) manual entry */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <assert.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stdlib.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stdio.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stddef.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <string.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <fcntl.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/attr.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/errno.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <unistd.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/vnode.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef struct attrlist attrlist_t;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+struct FInfoAttrBuf
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ u_int32_t length;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fsobj_type_t objType;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char finderInfo[32];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+};
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef struct FInfoAttrBuf FInfoAttrBuf;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static int FInfoDemo(int fd, const char *type, const char *creator)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int err;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrlist_t attrList;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ FInfoAttrBuf attrBuf;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert(strlen(type) == 4);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert(strlen(creator) == 4);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ memset(&attrList, 0, sizeof(attrList));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = fgetattrlist(fd, &attrList, &attrBuf, sizeof(attrBuf), 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (err != 0)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = errno;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ((err == 0) && (attrBuf.objType != VREG))
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(stderr, "Not a standard file.");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = EINVAL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ else
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ memcpy(&attrBuf.finderInfo[0], type, 4);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ memcpy(&attrBuf.finderInfo[4], creator, 4);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrList.commonattr = ATTR_CMN_FNDRINFO;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = fsetattrlist(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fd,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ &attrList,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ attrBuf.finderInfo,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sizeof(attrBuf.finderInfo),
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return err;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Note: Not an exhaustive test. Just call fsetattrlist(). */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int main(int ac, char **av)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char *fname = "./.jnk.tmp";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int fd = open(fname, O_CREAT | O_RDWR, S_IRWXU);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int rc = (FInfoDemo(fd, "TYPE", "CRTR") == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ unlink(fname);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (rc != EXIT_SUCCESS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("fgetattrlist() failed, possibly correctly due to an unexpected filesystem type\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return rc;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* vi:set et ts=4 sw=4: */
</span></pre><pre style='margin:0'>
</pre>