* For more information, please refer to <http://unlicense.org/>
  */
 
-#define _BSD_SOURCE /* for endian.h */
+/* $(CROSS_COMPILE)cc -g -o aio_simple aio_simple.c -laio */
+
+#define _DEFAULT_SOURCE /* for endian.h */
 
 #include <endian.h>
 #include <errno.h>
 
 #define BUF_LEN                8192
 
+/*
+ * cpu_to_le16/32 are used when initializing structures, a context where a
+ * function call is not allowed. To solve this, we code cpu_to_le16/32 in a way
+ * that allows them to be used when initializing structures.
+ */
+
+#if BYTE_ORDER == __LITTLE_ENDIAN
+#define cpu_to_le16(x)  (x)
+#define cpu_to_le32(x)  (x)
+#else
+#define cpu_to_le16(x)  ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
+#define cpu_to_le32(x)  \
+       ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >>  8) | \
+       (((x) & 0x0000ff00u) <<  8) | (((x) & 0x000000ffu) << 24))
+#endif
+
 /******************** Descriptors and Strings *******************************/
 
 static const struct {
        } __attribute__ ((__packed__)) fs_descs, hs_descs;
 } __attribute__ ((__packed__)) descriptors = {
        .header = {
-               .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
-               .flags = htole32(FUNCTIONFS_HAS_FS_DESC |
+               .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
+               .flags = cpu_to_le32(FUNCTIONFS_HAS_FS_DESC |
                                     FUNCTIONFS_HAS_HS_DESC),
-               .length = htole32(sizeof(descriptors)),
+               .length = cpu_to_le32(sizeof(descriptors)),
        },
-       .fs_count = htole32(3),
+       .fs_count = cpu_to_le32(3),
        .fs_descs = {
                .intf = {
                        .bLength = sizeof(descriptors.fs_descs.intf),
                        .bmAttributes = USB_ENDPOINT_XFER_BULK,
                },
        },
-       .hs_count = htole32(3),
+       .hs_count = cpu_to_le32(3),
        .hs_descs = {
                .intf = {
                        .bLength = sizeof(descriptors.hs_descs.intf),
                        .bDescriptorType = USB_DT_ENDPOINT,
                        .bEndpointAddress = 1 | USB_DIR_IN,
                        .bmAttributes = USB_ENDPOINT_XFER_BULK,
-                       .wMaxPacketSize = htole16(512),
+                       .wMaxPacketSize = cpu_to_le16(512),
                },
                .bulk_source = {
                        .bLength = sizeof(descriptors.hs_descs.bulk_source),
                        .bDescriptorType = USB_DT_ENDPOINT,
                        .bEndpointAddress = 2 | USB_DIR_OUT,
                        .bmAttributes = USB_ENDPOINT_XFER_BULK,
-                       .wMaxPacketSize = htole16(512),
+                       .wMaxPacketSize = cpu_to_le16(512),
                },
        },
 };
        } __attribute__ ((__packed__)) lang0;
 } __attribute__ ((__packed__)) strings = {
        .header = {
-               .magic = htole32(FUNCTIONFS_STRINGS_MAGIC),
-               .length = htole32(sizeof(strings)),
-               .str_count = htole32(1),
-               .lang_count = htole32(1),
+               .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC),
+               .length = cpu_to_le32(sizeof(strings)),
+               .str_count = cpu_to_le32(1),
+               .lang_count = cpu_to_le32(1),
        },
        .lang0 = {
-               htole16(0x0409), /* en-us */
+               cpu_to_le16(0x0409), /* en-us */
                STR_INTERFACE,
        },
 };