Add stpcpy() and implement version/derivative queries
authorH. Peter Anvin <hpa@zytor.com>
Sat, 29 Mar 2008 05:10:01 +0000 (22:10 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Sat, 29 Mar 2008 05:19:12 +0000 (22:19 -0700)
Add stpcpy(), and actually implement syslinux_version() and
syslinux_derivative_info().

com32/include/string.h
com32/lib/Makefile
com32/lib/stpcpy.c [new file with mode: 0644]
com32/lib/syslinux/dsinfo.c [new file with mode: 0644]
com32/lib/syslinux/version.c [new file with mode: 0644]

index 6592372..af9792b 100644 (file)
@@ -33,6 +33,7 @@ __extern char *strncat(char *, const char *, size_t);
 __extern size_t strlcat(char *, const char *, size_t);
 __extern int strncmp(const char *, const char *, size_t);
 __extern char *strncpy(char *, const char *, size_t);
+__extern char *stpcpy(char *, const char *);
 __extern char *stpncpy(char *, const char *, size_t);
 __extern size_t strlcpy(char *, const char *, size_t);
 __extern char *strpbrk(const char *, const char *);
index 6c08c22..adc3660 100644 (file)
@@ -13,7 +13,8 @@ LIBOBJS = \
        sprintf.o srand48.o sscanf.o stack.o strcasecmp.o strcat.o      \
        strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o         \
        strnlen.o                                                       \
-       strncasecmp.o strncat.o strncmp.o strncpy.o stpncpy.o strndup.o \
+       strncasecmp.o strncat.o strncmp.o strncpy.o strndup.o           \
+       stpcpy.o stpncpy.o                                              \
        strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o  \
        strtoimax.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o    \
        strtoumax.o vfprintf.o vprintf.o vsnprintf.o vsprintf.o         \
@@ -72,7 +73,7 @@ LIBOBJS = \
        \
        syslinux/idle.o syslinux/reboot.o                               \
        syslinux/features.o syslinux/config.o syslinux/serial.o         \
-       syslinux/ipappend.o                                             \
+       syslinux/ipappend.o syslinux/dsinfo.o syslinux/version.o        \
        \
        syslinux/addlist.o syslinux/freelist.o syslinux/memmap.o        \
        syslinux/movebits.o syslinux/shuffle.o syslinux/shuffle_pm.o    \
diff --git a/com32/lib/stpcpy.c b/com32/lib/stpcpy.c
new file mode 100644 (file)
index 0000000..85fc49d
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * stpcpy.c
+ *
+ * stpcpy()
+ */
+
+#include <string.h>
+
+char *stpcpy(char *dst, const char *src)
+{
+  char *q = dst;
+  const char *p = src;
+  char ch;
+
+  for (;;) {
+    *q = ch = *p++;
+    if ( !ch )
+      break;
+    q++;
+  }
+
+  return q;
+}
diff --git a/com32/lib/syslinux/dsinfo.c b/com32/lib/syslinux/dsinfo.c
new file mode 100644 (file)
index 0000000..6d77a0d
--- /dev/null
@@ -0,0 +1,47 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2008 H. Peter Anvin - All Rights Reserved
+ *
+ *   Permission is hereby granted, free of charge, to any person
+ *   obtaining a copy of this software and associated documentation
+ *   files (the "Software"), to deal in the Software without
+ *   restriction, including without limitation the rights to use,
+ *   copy, modify, merge, publish, distribute, sublicense, and/or
+ *   sell copies of the Software, and to permit persons to whom
+ *   the Software is furnished to do so, subject to the following
+ *   conditions:
+ *
+ *   The above copyright notice and this permission notice shall
+ *   be included in all copies or substantial portions of the Software.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *   OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <syslinux/config.h>
+#include <klibc/compiler.h>
+#include <com32.h>
+
+union syslinux_derivative_info __syslinux_derivative_info;
+
+void __constructor __syslinux_get_derivative_info(void)
+{
+  static com32sys_t reg;
+
+  reg.eax.w[0] = 0x000A;
+  __intcall(0x22, &reg, &reg);
+
+  __syslinux_derivative_info.r.ax = reg.eax.w[0];
+  __syslinux_derivative_info.r.cx = reg.ecx.w[0];
+  __syslinux_derivative_info.r.dx = reg.edx.w[0];
+  __syslinux_derivative_info.r.esbx = MK_PTR(reg.es, reg.ebx.w[0]);
+  __syslinux_derivative_info.r.fssi = MK_PTR(reg.fs, reg.esi.w[0]);
+  __syslinux_derivative_info.r.gsdi = MK_PTR(reg.gs, reg.edi.w[0]);
+}
diff --git a/com32/lib/syslinux/version.c b/com32/lib/syslinux/version.c
new file mode 100644 (file)
index 0000000..2131fa0
--- /dev/null
@@ -0,0 +1,46 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2008 H. Peter Anvin - All Rights Reserved
+ *
+ *   Permission is hereby granted, free of charge, to any person
+ *   obtaining a copy of this software and associated documentation
+ *   files (the "Software"), to deal in the Software without
+ *   restriction, including without limitation the rights to use,
+ *   copy, modify, merge, publish, distribute, sublicense, and/or
+ *   sell copies of the Software, and to permit persons to whom
+ *   the Software is furnished to do so, subject to the following
+ *   conditions:
+ *
+ *   The above copyright notice and this permission notice shall
+ *   be included in all copies or substantial portions of the Software.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *   OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <syslinux/config.h>
+#include <klibc/compiler.h>
+#include <com32.h>
+
+struct syslinux_version __syslinux_version;
+
+void __constructor __syslinux_get_version(void)
+{
+  static com32sys_t reg;
+
+  reg.eax.w[0] = 0x0001;
+  __intcall(0x22, &reg, &reg);
+
+  __syslinux_version.version = reg.ecx.w[0];
+  __syslinux_version.max_api = reg.eax.w[0];
+  __syslinux_version.filesystem = reg.edx.b[0];
+  __syslinux_version.version_string = MK_PTR(reg.es, reg.esi.w[0]);
+  __syslinux_version.copyright_string = MK_PTR(reg.es, reg.edi.w[0]);
+}