Explorar o código

Add the xopen swab() function, contributed by Kensuke Otake <kensuke@phreaker.net>

Eric Andersen %!s(int64=24) %!d(string=hai) anos
pai
achega
beca89d99a
Modificáronse 2 ficheiros con 19 adicións e 1 borrados
  1. 1 1
      libc/unistd/Makefile
  2. 18 0
      libc/unistd/swab.c

+ 1 - 1
libc/unistd/Makefile

@@ -27,7 +27,7 @@ DIRS:=
 
 CSRC=execl.c execlp.c execv.c execvep.c execvp.c execle.c getcwd.c \
 	sleep.c usleep.c getpass.c sysconf_src.c getlogin.c \
-	fpathconf.c confstr.c pathconf.c
+	fpathconf.c confstr.c pathconf.c swab.c
 ifeq ($(strip $(HAS_MMU)),true)
     CSRC+=daemon.c
 endif

+ 18 - 0
libc/unistd/swab.c

@@ -0,0 +1,18 @@
+#include <unistd.h>
+#include <sys/types.h>
+
+/* swab() swaps the position of two adjacent bytes, every two bytes.
+ * Contributed by Kensuke Otake <kensuke@phreaker.net> */
+
+void swab(const void *source, void *dest, ssize_t count) {
+  const char *from = (const char *)source;
+  char *to = (char *)dest;
+
+  count &= ~((ssize_t)1);
+
+  while (count > 1) {
+    const char b0 = from[--count], b1 = from[--count];
+    to[count] = b0;
+    to[count + 1] = b1;
+  }
+}