From kevin at tyndur.org Sat Apr 4 23:07:57 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 4 Apr 2009 23:07:57 +0200 Subject: [tyndur-devel] [PATCH] Makefile-Target fuer CD-ROM-Images Message-ID: <1238879277-9022-1-git-send-email-kevin@tyndur.org> + Makefile-Target fuer CD-ROM-Images --- Makefile | 5 +- build/config/grub_cdrom.cfg | 8 +++ build/config/image_cdrom.sh | 2 + build/root-cdrom/config/servmgr/mount/cmd | 1 + build/root-cdrom/config/servmgr/mount/conf | 1 + build/root-cdrom/config/servmgr/mount/deps | 1 + build/scripts/image_cdrom | 92 ++++++++++++++++++++++++++++ buildmk.sh | 5 +- 8 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 build/config/grub_cdrom.cfg create mode 100644 build/config/image_cdrom.sh create mode 100644 build/root-cdrom/config/servmgr/mount/cmd create mode 100644 build/root-cdrom/config/servmgr/mount/conf create mode 100644 build/root-cdrom/config/servmgr/mount/deps create mode 100755 build/scripts/image_cdrom diff --git a/Makefile b/Makefile index 673b5b5..9b63409 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,10 @@ image-floppy: updateroot image-hd: updateroot build/scripts/image_hd - + +image-cdrom: updateroot + build/scripts/image_cdrom + test-qemu: image-floppy qemu -serial stdio -fda build/images/floppy.img -boot a -net user -net nic,model=rtl8139 | tee qemu-serial.log diff --git a/build/config/grub_cdrom.cfg b/build/config/grub_cdrom.cfg new file mode 100644 index 0000000..fc71ef7 --- /dev/null +++ b/build/config/grub_cdrom.cfg @@ -0,0 +1,8 @@ +title tyndur +kernel /tyndur debug=s +module /init boot=file:/ +module /ata +module /iso9660 +module /console servmgr:/term servmgr:/term +module /servmgr ata:/atapi10|iso9660:/ vterm:/vterm8/out ata iso9660 console +boot diff --git a/build/config/image_cdrom.sh b/build/config/image_cdrom.sh new file mode 100644 index 0000000..3e3e67f --- /dev/null +++ b/build/config/image_cdrom.sh @@ -0,0 +1,2 @@ +IMAGE_PATH="build/images/cdrom.img" +FLOPPY_IMAGE_PATH="build/images/cdrom_floppy.img" diff --git a/build/root-cdrom/config/servmgr/mount/cmd b/build/root-cdrom/config/servmgr/mount/cmd new file mode 100644 index 0000000..34807da --- /dev/null +++ b/build/root-cdrom/config/servmgr/mount/cmd @@ -0,0 +1 @@ +/modules/file mount file:/ ata:/atapi10|iso9660:/ diff --git a/build/root-cdrom/config/servmgr/mount/conf b/build/root-cdrom/config/servmgr/mount/conf new file mode 100644 index 0000000..319afcd --- /dev/null +++ b/build/root-cdrom/config/servmgr/mount/conf @@ -0,0 +1 @@ +waitterminate diff --git a/build/root-cdrom/config/servmgr/mount/deps b/build/root-cdrom/config/servmgr/mount/deps new file mode 100644 index 0000000..f73f309 --- /dev/null +++ b/build/root-cdrom/config/servmgr/mount/deps @@ -0,0 +1 @@ +file diff --git a/build/scripts/image_cdrom b/build/scripts/image_cdrom new file mode 100755 index 0000000..186a91a --- /dev/null +++ b/build/scripts/image_cdrom @@ -0,0 +1,92 @@ +#!/bin/bash + +# Copyright (c) 2008-2009 The tyndur Project. All rights reserved. +# +# This code is derived from software contributed to the tyndur Project +# by Antoine Kaufmann. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the tyndur Project +# and its contributors. +# 4. Neither the name of the tyndur Project nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +ROOT=build/root +ROOT_COMMON=build/root-common +ROOT_CDROM=build/root-cdrom + +export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin + +source build/config/image_cdrom.sh +export LOST_BUILDMK_ROOT="`pwd`" +source config.sh + + +export MTOOLSRC=lostmtools.conf + +# Konfigurationsdatei fuer mtools generieren +cat << EOF > $MTOOLSRC +drive l: + file="$FLOPPY_IMAGE_PATH" cylinders=80 heads=2 sectors=18 filter +EOF + +# Wenn das Image neu erstellt werden muss, kommen noch ein paar schritte mehr +# dazu. +NEW=0 +if ! [ -f $FLOPPY_IMAGE_PATH ]; then + # Leeres Image erstellen und formatieren + dd if=/dev/zero of=$FLOPPY_IMAGE_PATH bs=1024 count=1440 + mformat l: + NEW=1 +fi + + +if [ $NEW -ne 0 ]; then + # Grub kopieren und installieren + mmd -D s l:/boot + mmd -D s l:/boot/grub + mcopy -D o $LOST_GRUB_STAGESDIR/stage? l:/boot/grub/ + + $LOST_TOOLS_GRUB --batch < References: <1238879277-9022-1-git-send-email-kevin@tyndur.org> Message-ID: <20090404213001.GA9924@einstein.produktiv.lan> On Sat, Apr 04 23:07, Kevin Wolf wrote: > + Makefile-Target fuer CD-ROM-Images Sieht gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 4 23:50:09 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 4 Apr 2009 23:50:09 +0200 Subject: [tyndur-devel] [PATCH v3] build hinzugefuegt In-Reply-To: <1238357845-14454-1-git-send-email-kevin@tyndur.org> References: <20090329195411.GA7684@einstein.produktiv.lan> <1238357845-14454-1-git-send-email-kevin@tyndur.org> Message-ID: <20090404215009.GB9924@einstein.produktiv.lan> On Sun, Mar 29 22:17, Kevin Wolf wrote: > + build: Erster Commit des Buildtools fuer tyndur > > Compilegetestet ist diese neue Version sogar ;-) > --- > src/modules/c/build/Makefile.all | 7 + > src/modules/c/build/build.c | 272 +++++++++++++++++++++++++++++++++++ > src/modules/c/build/dir.c | 235 ++++++++++++++++++++++++++++++ > src/modules/c/build/include/build.h | 80 ++++++++++ > src/modules/c/build/main.c | 121 ++++++++++++++++ > 5 files changed, 715 insertions(+), 0 deletions(-) > create mode 100644 src/modules/c/build/Makefile.all > create mode 100644 src/modules/c/build/build.c > create mode 100644 src/modules/c/build/dir.c > create mode 100644 src/modules/c/build/include/build.h > create mode 100644 src/modules/c/build/main.c > > diff --git a/src/modules/c/build/dir.c b/src/modules/c/build/dir.c > new file mode 100644 > index 0000000..1919fb0 > --- /dev/null > +++ b/src/modules/c/build/dir.c > @@ -0,0 +1,235 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include "build.h" > + > +/** > + * Durchsucht ein Verzeichnis und speichert alle fuer das Bauen noetige > + * Informationen in dynamisch allozierten Datenstrukturen, die vom Aufrufer > + * mir free_directory() freigegeben werden muss. > + * > + * Das bedeutet: > + * - Alle Quellcodedateien sammeln (*.c, *.pas, ...) > + * - Includeverzeichnisse speichern > + * - lib-Verzeichnisse erfassen > + * - Bei arch/-Verzeichnissen nur die richtige Architektur beruecksichtigen > + * - .nobuild und .ignorenobuild beachten > + */ > +struct build_dir* scan_directory(struct build_dir* parent, const char* path) > +{ > + DIR* dir = opendir(path); > + struct dirent* ent; > + char* suffix; > + struct build_file* file; > + enum filetype filetype; > + struct stat stat_buf; > + struct build_dir* build_dir; > + struct build_dir* subdir; > + char* file_path; > + int i; > + > + int nobuild = 0; > + int ignorenobuild = 0; > + > + if (dir == NULL) { > + fprintf(stderr, "Verzeichnis %s kann nicht geoeffnet werden.\n", > + path); > + return NULL; > + } > + > + // Speicher fuer Verzeichnis-struct anlegen und initialiseren > + build_dir = calloc(1, sizeof(*build_dir)); > + build_dir->path = strdup(path); > + build_dir->parent = parent; > + build_dir->subdirs = list_create(); > + build_dir->obj_files = list_create(); > + for (i = 0; i < MAX_LANG; i++) { > + build_dir->src_files[i] = list_create(); > + } > + > + // Dateien und Unterverzeichnisse einlesen > + while ((ent = readdir(dir))) { > + > + filetype = OTHER_FILE; > + suffix = strrchr(ent->d_name, '.'); > + > + asprintf(&file_path, "%s/%s", path, ent->d_name); > + stat(file_path, &stat_buf); > + > + // Dateityp erkennen > + if (!strcmp(ent->d_name, ".nobuild")) { > + nobuild = 1; > + goto next; > + } else if (!strcmp(ent->d_name, ".ignorenobuild")) { > + ignorenobuild = 1; > + goto next; > + } else if (*ent->d_name == '.') { > + goto next; > + } else if (S_ISDIR(stat_buf.st_mode)) { > + filetype = SUBDIR; > + } else if (suffix == NULL) { > + filetype = OTHER_FILE; > + } else if (!strcmp(suffix, ".o")) { > + filetype = OBJ; > + } else if (!strcmp(suffix, ".c")) { > + filetype = LANG_C; > + } else if (!strcmp(suffix, ".pas")) { > + filetype = LANG_PAS; > + } else if (!strcmp(suffix, ".asm")) { > + filetype = LANG_ASM_NASM; > + } else if (!strcmp(suffix, ".S")) { > + filetype = LANG_ASM_GAS; > + } > + > + // Wenn bis hierher nichts verwertbares gefunden wurde, wird die Datei > + // einfach ignoriert. > + if (filetype == OTHER_FILE) { > + goto next; > + } > + > + // Datei je nach Typ verarbeiten > + file = calloc(1, sizeof(*file)); > + file->type = filetype; > + file->name = strdup(ent->d_name); > + > + switch (filetype) { > + case SUBDIR: > + // Unterverzeichnisse werden je nach Namen unterschiedlich > + // erfasst: > + // > + // - include/ wird zu den Includepfaden hinzugefuegt, das > + // Verzeicnis wird nicht weiter durchsucht > + // - In include/arch/ und arch/ wird nur das richtige > + // Unterverzeichnis weiterverfolgt > + // - lib/ wird gesondert gespeichert, damit es vor allen > + // anderen Verzeichnissen gebaut werden kann > + // - Alles andere wird einfach als Unterverzeichnis gemerkt > + if (!strcmp(file->name, "include")) { > + DIR* arch_dir; > + char* tmp; > + > + build_dir->has_include = 1; > + > + asprintf(&tmp, "include/arch/%s", arch); > + arch_dir = opendir(tmp); > + free(tmp); > + > + if (arch_dir != NULL) { > + closedir(arch_dir); > + build_dir->has_arch_include = 1; > + } > + > + } else if (!strcmp(file->name, "lib")) { > + build_dir->lib = scan_directory(build_dir, file_path); > + } else if (!strcmp(file->name, "arch")) { > + char* tmp; > + asprintf(&tmp, "%s/%s", file_path, arch); > + subdir = scan_directory(build_dir, tmp); > + free(tmp); > + if (subdir != NULL) { > + list_push(build_dir->subdirs, subdir); > + } > + } else { > + subdir = scan_directory(build_dir, file_path); > + if (subdir != NULL) { > + list_push(build_dir->subdirs, subdir); > + } > + } > + break; > + case OBJ: > + // Objektdateien haben ihre eigene Liste > + list_push(build_dir->obj_files, file); > + break; > + default: > + // Quellcodedateien werden nach Sprache getrennt gespeichert > + list_push(build_dir->src_files[filetype], file); > + break; > + } > + > + next: > + free(file_path); > + } > + > + closedir(dir); > + > + // Wenn das Verzeichnis gar nicht gebaut werden soll, besser nichts > + // zurueckgeben > + if (nobuild && !ignorenobuild) { > + free_directory(build_dir); > + return NULL; > + } > + > + return build_dir; > +} > + > +/** > + * Gibt die Datenstrukturen fuer ein Verzeichnis wieder frei > + */ > +void free_directory(struct build_dir* dir) > +{ > + int i; > + struct build_dir* subdir; > + struct build_file* file; > + > + if (dir == NULL) { > + return; > + } > + > + while ((subdir = list_pop(dir->subdirs))) { > + free_directory(subdir); > + } > + > + while ((file = list_pop(dir->obj_files))) { > + free(file->name); > + free(file); > + } Bräuchtest du da nicht noch irgend ein list_destroy() oder zwei? > + > + for (i = 0; i < MAX_LANG; i++) { > + while ((file = list_pop(dir->src_files[i]))) { > + free(file->name); > + free(file); > + } > + } > + Oder drei... > + free_directory(dir->lib); > + free(dir->path); > + free(dir); > +} > diff --git a/src/modules/c/build/main.c b/src/modules/c/build/main.c > new file mode 100644 > index 0000000..0f725cc > --- /dev/null > +++ b/src/modules/c/build/main.c > @@ -0,0 +1,121 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > +#include > + > +#include "build.h" > + > +/** > + * Legt Kuerzel fuer Dateitypen fest, die fuer die Anzeige benutzt werden > + * koennen, waehrend die Datei verarbeitet wird > + */ > +char* filetype_str[] = { > + [OTHER_FILE] = " ? ", > + [SUBDIR] = "DIR", > + [OBJ] = "OBJ", > + [LANG_C] = " C ", > + [LANG_PAS] = "PAS", > + [LANG_ASM_GAS] = "ASM", > + [LANG_ASM_NASM] = "ASM", > +}; > + > +/** > + * Legt die aktuelle Architektur fest. > + * > + * Wird benutzt, falls arch/-Verzeichnisse im Projekt existieren > + */ > +char* arch = "i386"; > + > +/** > + * Mit verbose != 0 wird die Kommandozeile aller aufgerufenen Tools angezeigt. > + * Sonst wird nur eine kurze Statusmeldung ausgegeben. > + */ > +int verbose = 0; > + > +/// Nur Meldungen ausgeben, aber nichts wirklich aufrufen > +int dryrun= 0; > + > + > +static void usage(char* binary) > +{ > + fprintf(stderr, "Aufruf: %s [-v] [--dry-run] []\n", > + binary); > + exit(1); > +} > + > +int main(int argc, char** argv) > +{ > + struct build_dir* rootdir; > + int i; > + char* rootdir_path = NULL; > + > + // Verarbeitung der Kommandozeilenparameter > + for (i = 1; i < argc; i++) { > + if (!strcmp(argv[i], "-v")) { > + verbose = 1; > + } else if (!strcmp(argv[i], "--dry-run")) { > + dry_run = 1; > + } else if (argv[i][0] == '-') { > + usage(argv[0]); > + } else if (rootdir_path) { > + usage(argv[0]); > + } else { > + rootdir_path = argv[i]; > + } > + } > + > + // Ins Wurzelverzeichnis des Projekts wechseln > + if (rootdir_path) { > + if (chdir(argv[i])) { > + fprintf(stderr, "Verzeichnis nicht gefunden\n"); > + return 1; > + } > + } > + > + // Alle zu kompilierenden Dateien, Includeverzeichnisse usw. erfassen > + rootdir = scan_directory(NULL, "."); > + if (rootdir == NULL) { > + fprintf(stderr, "Verzeichnis nicht gefunden\n"); > + return 1; > + } > + > + // Bauen! > + build(rootdir); > + Vielleich noch ein free_directory(rootdir)? ;-) > + return 0; > +} Mehr kann ich momentan leider nich bemängeln. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Apr 5 20:06:01 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 5 Apr 2009 20:06:01 +0200 Subject: [tyndur-devel] [PATCH] kernel: SYSCALL_FASTRPC_WAIT In-Reply-To: <1238443864-6494-1-git-send-email-kevin@tyndur.org> References: <1238443864-6494-1-git-send-email-kevin@tyndur.org> Message-ID: <20090405180600.GA15081@einstein.produktiv.lan> On Mon, Mar 30 22:11, Kevin Wolf wrote: > + kernel: SYSCALL_FASTRPC_WAIT als Kombination von RPC und wait_for_rpc() > * libc: Neuen Syscall fuer Sync-RPC benutzen > --- > src/include/syscallno.h | 1 + > src/kernel/src/syscall.c | 10 ++++++++++ > src/modules/include/syscall.h | 1 + > src/modules/lib/rpc/sync.c | 2 +- > src/modules/lib/syscalls/rpc.c | 21 +++++++++++++++++---- > 5 files changed, 30 insertions(+), 5 deletions(-) > > diff --git a/src/modules/lib/syscalls/rpc.c b/src/modules/lib/syscalls/rpc.c > index 72d4bbc..68cb394 100644 > --- a/src/modules/lib/syscalls/rpc.c > +++ b/src/modules/lib/syscalls/rpc.c > @@ -16,8 +16,9 @@ void rpc(dword pid) > } while (result != 0); > } > > -void send_message > - (dword pid, dword function, dword correlation_id, dword len, char* data) > +static inline void do_send_message > + (dword pid, dword function, dword correlation_id, dword len, char* data, > + bool wait_for_rpc) > { > dword result = 0; > > @@ -38,10 +39,22 @@ void send_message > "mov %1, %%eax;" > "int $0x30;" > "add $0x14, %%esp;" > - : "=a" (result) > - : "i" (SYSCALL_FASTRPC), "g" (pid), "i" (0x8), "g" (metadata), > + : "=a" (result) > + : "i" (wait_for_rpc ? SYSCALL_FASTRPC_WAIT : SYSCALL_FASTRPC), > + "g" (pid), "i" (0x8), "g" (metadata), > "g" (len), "g" (data), "0" (result)); > > } while (result != 0); > } Hm wenn ich das mit -O0 kompilieren möchte sagt mir der gcc Folgendes: rpc.c: In function 'do_send_message': rpc.c:33: warning: asm operand 1 probably doesn't match constraints rpc.c:33: error: impossible constraint in 'asm' > > +void send_message > + (dword pid, dword function, dword correlation_id, dword len, char* data) > +{ > + do_send_message(pid, function, correlation_id, len, data, FALSE); > +} > + > +void send_message_and_wait_for_rpc > + (dword pid, dword function, dword correlation_id, dword len, char* data) > +{ > + do_send_message(pid, function, correlation_id, len, data, TRUE); > +} > -- > 1.5.6.5 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From alex at tyndur.org Tue Apr 7 22:46:20 2009 From: alex at tyndur.org (Alexander Siol) Date: Tue, 7 Apr 2009 22:46:20 +0200 Subject: [tyndur-devel] [PATCH] ElTorito-CD-Images Message-ID: <20090407204620.GA4582@alex.local.siol> Der Patch im Anhang ergänzt build/scripts/image_cdrom um die Fähigkeit auch ElTorito-Images zu erzeugen, falls eine entsprechende stage2 vorhanden ist. -- Alexander Siol alex at tyndur.org dunklermeuchler at gmail.com -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : eltorito_images.patch Dateityp : text/x-diff Dateigröße : 2076 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From kevin at tyndur.org Sat Apr 11 00:22:03 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 11 Apr 2009 00:22:03 +0200 Subject: [tyndur-devel] [PATCH] servmgr: $ROOT-Variable in cmd erlauben Message-ID: <1239402123-10625-1-git-send-email-kevin@tyndur.org> + servmgr: $ROOT in Befehlszeilen durch das Rootverzeichnis ersetzen * root-cdrom: $ROOT benutzen statt hartkodiertem Pfad. Dadurch reicht es, in GRUB den Modulparameter zu aendern, wenn man mal nicht von Secondary Master booten will --- build/root-cdrom/config/servmgr/mount/cmd | 2 +- src/modules/servmgr/config.c | 48 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletions(-) diff --git a/build/root-cdrom/config/servmgr/mount/cmd b/build/root-cdrom/config/servmgr/mount/cmd index 34807da..0c9cb8a 100644 --- a/build/root-cdrom/config/servmgr/mount/cmd +++ b/build/root-cdrom/config/servmgr/mount/cmd @@ -1 +1 @@ -/modules/file mount file:/ ata:/atapi10|iso9660:/ +/modules/file mount file:/ $ROOT diff --git a/src/modules/servmgr/config.c b/src/modules/servmgr/config.c index dedd260..0ca4f73 100644 --- a/src/modules/servmgr/config.c +++ b/src/modules/servmgr/config.c @@ -48,6 +48,52 @@ static list_t* config_list; char* full_config_path; /** + * Alle Vorkommen von einer Zeichenkette in einem gegebenen Puffer ersetzen. + * + * Der alte Puffer muss per malloc alloziert worden sein und wird freigegeben. + * Dafuer wird ein neuer Puffer mit der neuen Stringlaenge alloziert. + */ +static void buffer_replace(char** buf, const char* search, const char* replace) +{ + size_t len, i, j; + size_t search_len = strlen(search); + size_t replace_len = strlen(replace); + char* old = *buf; + char* new; + int found = 0; + + for (i = 0; i < strlen(old); i++) { + if (!strncmp(old + i, search, search_len)) { + len += replace_len; + i += search_len - 1; + found = 1; + } else { + len++; + } + } + + if (!found) { + return; + } + + new = malloc(len + 1); + new[len] = '\0'; + for (i = 0, j = 0; i < strlen(old); i++) { + if (!strncmp(old + i, search, search_len)) { + memcpy(new + j, replace, replace_len); + j += replace_len; + i += search_len - 1; + } else { + new[j] = old[i]; + j++; + } + } + + free(old); + *buf = new; +} + +/** * Dateiinhalt auslesen und den Angegebenen Pointer auf einen Buffer mit dem * Inhalt setzen. Wenn die Datei nicht geoeffnet werden konnte, wird er auf * NULL gesetzt. @@ -76,6 +122,8 @@ static void config_read_file(const char* path, char** ptr) *ptr = strdup(buffer); assert(*ptr != NULL); + buffer_replace(ptr, "$ROOT", root_dir); + fclose(f); } } -- 1.6.0.2 From mail at kevin-wolf.de Sat Apr 11 21:46:01 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 11 Apr 2009 21:46:01 +0200 Subject: [tyndur-devel] [PATCH] ElTorito-CD-Images In-Reply-To: <20090407204620.GA4582@alex.local.siol> References: <20090407204620.GA4582@alex.local.siol> Message-ID: <200904112146.01521@kevin-wolf.de> Am Dienstag, 7. April 2009 22:46 schrieb Alexander Siol: > Index: build/scripts/image_cdrom > =================================================================== > --- build/scripts/image_cdrom (Revision 1085) > +++ build/scripts/image_cdrom (Arbeitskopie) > @@ -37,6 +37,8 @@ > ROOT_COMMON=build/root-common > ROOT_CDROM=build/root-cdrom > > +STAGE2_ELTORITO=/usr/lib/grub/i386-pc/stage2_eltorito > + > export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin > > source build/config/image_cdrom.sh > @@ -46,6 +48,28 @@ > > export MTOOLSRC=lostmtools.conf > > +if [ -f $STAGE2_ELTORITO ]; then # Eltorito > + > + mkdir -p $ROOT_CDROM/boot/grub > + cp $STAGE2_ELTORITO $ROOT_CDROM/boot/grub/stage2_eltorito > + cp build/config/grub_cdrom_eltorito.cfg $ROOT_CDROM/boot/grub/menu.lst Ich glaube, da wäre $ROOT angebrachter, das ist zumindest halbwegs temporär (wird auch beim make clean gelöscht) und wird schon jetzt beim Buildvorgang befüllt. $ROOT_CDROM ist eigentlich Defaultkonfiguration, die unverändert aus dem Repo kommt. > + > + # Fix für uppercase-Pfade in ISO9660-Dateisystemen. > + # Ohne wird grub die menu.lst nicht finden. > + sed -i "s/boot\/grub\/menu.lst/BOOT\/GRUB\/MENU.LST/g" > $ROOT_CDROM/boot/grub/stage2_eltorito + > + mkisofs -b boot/grub/stage2_eltorito -no-emul-boot \ > + -boot-load-size 4 -boot-info-table -o $IMAGE_PATH \ > + $ROOT $ROOT_COMMON $ROOT_CDROM > + > + rm -rf $ROOT_CDROM/boot Den kann man dann weglassen, wenn man in $ROOT arbeitet. Ein bedingungsloses rm -rf ist immer dann ungünstig, wenn was schiefgeht und man hinterher keine Chance mehr hat nachzuvollziehen, warum eigentlich. > + echo "CD-Image erfolgreich erstellt!" > + echo "Verwendete Methode: Eltorito" > + exit > +fi > + > +# Floopy-Emulation Floppy ;-) > + > # Konfigurationsdatei fuer mtools generieren > cat << EOF > $MTOOLSRC > drive l: > @@ -90,3 +114,6 @@ > cp $FLOPPY_IMAGE_PATH $ROOT_CDROM > mkisofs -b $(basename $FLOPPY_IMAGE_PATH) -o $IMAGE_PATH $ROOT > $ROOT_COMMON $ROOT_CDROM rm $ROOT_CDROM/$(basename $FLOPPY_IMAGE_PATH) > + > +echo "CD-Image erfolgreich erstellt!" > +echo "Verwendete Methode: Floppy-Emulation" > Index: build/config/grub_cdrom_eltorito.cfg > =================================================================== > --- build/config/grub_cdrom_eltorito.cfg (Revision 0) > +++ build/config/grub_cdrom_eltorito.cfg (Revision 0) > @@ -0,0 +1,8 @@ > +title tyndur > +kernel /BOOT/TYNDUR debug=s > +module /MODULES/INIT boot=file:/ > +module /MODULES/ATA > +module /MODULES/ISO9660 > +module /MODULES/CONSOLE servmgr:/term servmgr:/term > +module /MODULES/SERVMGR ata:/atapi10|iso9660:/ vterm:/vterm8/out ata > iso9660 console +boot Ansonsten sehe ich keine Probleme damit. From toni at tyndur.org Sun Apr 12 23:23:06 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 12 Apr 2009 23:23:06 +0200 Subject: [tyndur-devel] [PATCH] servmgr: $ROOT-Variable in cmd erlauben In-Reply-To: <1239402123-10625-1-git-send-email-kevin@tyndur.org> References: <1239402123-10625-1-git-send-email-kevin@tyndur.org> Message-ID: <20090412212305.GA3268@einstein.produktiv.lan> On Sat, Apr 11 00:22, Kevin Wolf wrote: > + servmgr: $ROOT in Befehlszeilen durch das Rootverzeichnis ersetzen > * root-cdrom: $ROOT benutzen statt hartkodiertem Pfad. Dadurch reicht > es, in GRUB den Modulparameter zu aendern, wenn man mal nicht von > Secondary Master booten will Sieht vernünftig aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Mon Apr 13 18:21:56 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:21:56 +0200 Subject: [tyndur-devel] [PATCH 4/4] libc: POSIX: IP-Adressen-Umwandlung String/Integer In-Reply-To: <1239639716-2793-1-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639716-2793-5-git-send-email-kevin@tyndur.org> + libc: POSIX: inet_aton() / inet_ntoa() --- src/modules/include/netinet/in.h | 20 +++++++++++++++++++- src/modules/lib/posix/net.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletions(-) diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index 5bf18d2..6638d7e 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -31,7 +31,6 @@ #include #include -#include /// Adresse fuer das INET-Protokol (IPv4) struct sockaddr_in { @@ -40,10 +39,29 @@ struct sockaddr_in { uint32_t sin_port; }; +typedef uint32_t in_addr_t; +struct in_addr { + in_addr_t s_addr; +}; + unsigned long int htonl(unsigned long int hostlong); unsigned short int htons(unsigned short int hostshort); unsigned long int ntohl(unsigned long int netlong); unsigned short int ntohs(unsigned short int netshort); +/** + * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen + * 32-Bit-Wert um. + * + * @return 0 im Fehlerfall; ungleich 0 bei Erfolg + */ +int inet_aton(const char *cp, struct in_addr *inp); + +/** + * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem + * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. + */ +char *inet_ntoa(struct in_addr in); + #endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index c6fbdb8..a463790 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -55,6 +55,35 @@ unsigned short int ntohs(unsigned short int netshort) return big_endian_dword(netshort); } +/** + * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen + * 32-Bit-Wert um. + * + * @return 0 im Fehlerfall; ungleich 0 bei Erfolg + * FIXME 0.0.0.0 ist eine gueltige Adresse + */ +int inet_aton(const char *cp, struct in_addr *inp) +{ + inp->s_addr = string_to_ip((char*) cp); + return inp->s_addr; +} + +/** + * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem + * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. + */ +char *inet_ntoa(struct in_addr in) +{ + static char buf[16]; + char* res; + + res = ip_to_string(in.s_addr); + strncpy(buf, res, 16); + free(res); + + return buf; +} + struct hostent* gethostbyname(const char* name) { static struct hostent hostent; -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:21:55 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:21:55 +0200 Subject: [tyndur-devel] [PATCH 3/4] libc: POSIX: gethostbyname() In-Reply-To: <1239639716-2793-1-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639716-2793-4-git-send-email-kevin@tyndur.org> + libc: POSIX: gethostbyname() --- src/modules/include/netinet/in.h | 1 + src/modules/include/network.h | 2 +- src/modules/lib/network.c | 2 +- src/modules/lib/posix/net.c | 40 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index 14963a4..5bf18d2 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -31,6 +31,7 @@ #include #include +#include /// Adresse fuer das INET-Protokol (IPv4) struct sockaddr_in { diff --git a/src/modules/include/network.h b/src/modules/include/network.h index 9be97db..ef0bb99 100644 --- a/src/modules/include/network.h +++ b/src/modules/include/network.h @@ -48,7 +48,7 @@ struct net_device { dword ip; }; -dword string_to_ip(char* ip); +dword string_to_ip(const char* ip); char* ip_to_string(dword ip); char* mac_to_string(uint64_t mac); void register_netcard(dword device_numer, uint64_t mac, dword ip); diff --git a/src/modules/lib/network.c b/src/modules/lib/network.c index 927ada8..d0343d3 100644 --- a/src/modules/lib/network.c +++ b/src/modules/lib/network.c @@ -40,7 +40,7 @@ * Dezimalzahlen (a.b.c.d). Andere Darstellungen (z.B. eine Hexzahl) sind * derzeit nicht unterst�tzt. */ -dword string_to_ip(char* ip) +dword string_to_ip(const char* ip) { byte ip_bytes[4] = { 0, 0, 0, 0 }; diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 2a41daf..c6fbdb8 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -28,6 +28,9 @@ #include #include +#include + +#include #include #include @@ -51,3 +54,40 @@ unsigned short int ntohs(unsigned short int netshort) { return big_endian_dword(netshort); } + +struct hostent* gethostbyname(const char* name) +{ + static struct hostent hostent; + static char* aliases[] = { NULL }; + static uint32_t ip; + static uint32_t* h_addr_list[] = { &ip, NULL }; + + // Erstmal schauen, ob es eine IP-Adresse ist + ip = string_to_ip(name); + + // Wenn nicht, muessen wir eine DNS-Anfrage machen + if (ip == 0) { + char* path; + FILE* f; + char ip_str[16]; + + asprintf(&path, "tcpip:/dns/%s", name); + f = fopen(path, "r"); + if (!f) { + return NULL; + } + fread(ip_str, 1, 16, f); + fclose(f); + + ip = string_to_ip(ip_str); + } + + // hostent aktualisieren + hostent.h_name = (char*) name; + hostent.h_aliases = aliases; + hostent.h_addrtype = AF_INET; + hostent.h_length = 4; + hostent.h_addr_list = (char**) h_addr_list; + + return &hostent; +} -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:21:52 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:21:52 +0200 Subject: [tyndur-devel] [PATCH 0/4] POSIX: Sockets Message-ID: <1239639716-2793-1-git-send-email-kevin@tyndur.org> Diese Patchserie fuegt POSIX-Wrapper fuer Netzwerk hinzu. Offensichtlich gehoert dazu keine neue Funktionalitaet, deshalb vorerst nur Clients und nur TCP ueber IPv4. Kevin Wolf (4): libc: POSIX: Socket-Funktionen libc: POSIX: arpa/inet.h libc: POSIX: gethostbyname() libc: POSIX: IP-Adressen-Umwandlung String/Integer src/include/errno.h | 12 +++ src/modules/include/arpa/inet.h | 38 ++++++++ src/modules/include/netinet/in.h | 29 ++++++ src/modules/include/network.h | 2 +- src/modules/include/sys/socket.h | 99 +++++++++++++++++++ src/modules/lib/network.c | 2 +- src/modules/lib/posix/net.c | 72 ++++++++++++++ src/modules/lib/posix/socket.c | 193 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 445 insertions(+), 2 deletions(-) create mode 100644 src/modules/include/arpa/inet.h create mode 100644 src/modules/include/sys/socket.h create mode 100644 src/modules/lib/posix/socket.c From kevin at tyndur.org Mon Apr 13 18:21:54 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:21:54 +0200 Subject: [tyndur-devel] [PATCH 2/4] libc: POSIX: arpa/inet.h In-Reply-To: <1239639716-2793-1-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639716-2793-3-git-send-email-kevin@tyndur.org> ! libc: htons() und aehnliches gehoeren laut Standard nach arpa/inet.h und nicht nach netinet/in.h --- src/modules/include/arpa/inet.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/arpa/inet.h diff --git a/src/modules/include/arpa/inet.h b/src/modules/include/arpa/inet.h new file mode 100644 index 0000000..23610a9 --- /dev/null +++ b/src/modules/include/arpa/inet.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ARPA_INET_H_ +#define _ARPA_INET_H_ + +unsigned long int htonl(unsigned long int hostlong); +unsigned short int htons(unsigned short int hostshort); +unsigned long int ntohl(unsigned long int netlong); +unsigned short int ntohs(unsigned short int netshort); + +#endif + -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:21:53 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:21:53 +0200 Subject: [tyndur-devel] [PATCH 1/4] libc: POSIX: Socket-Funktionen In-Reply-To: <1239639716-2793-1-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639716-2793-2-git-send-email-kevin@tyndur.org> + libc: POSIX: Socket-Funktionen --- src/include/errno.h | 12 +++ src/modules/include/netinet/in.h | 10 ++ src/modules/include/sys/socket.h | 99 +++++++++++++++++++ src/modules/lib/posix/net.c | 3 + src/modules/lib/posix/socket.c | 193 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 317 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/sys/socket.h create mode 100644 src/modules/lib/posix/socket.c diff --git a/src/include/errno.h b/src/include/errno.h index 2934ac1..3f8f16f 100644 --- a/src/include/errno.h +++ b/src/include/errno.h @@ -56,6 +56,18 @@ #define ESRCH 25 #define EPIPE 26 #define EILSEQ 27 + + +#define EAFNOSUPPORT 28 +#define ETIMEDOUT 29 +#define EPROTOTYPE 30 +#define ECONNREFUSED 31 +#define ENOTCONN 32 +#define ECONNRESET 33 +#define EINPROGRESS 34 +#define EALREADY 35 +#define EISCONN 36 + extern int errno; #endif diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index b48125f..14963a4 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -29,6 +29,16 @@ #ifndef _NETINET_IN_H_ #define _NETINET_IN_H_ +#include +#include + +/// Adresse fuer das INET-Protokol (IPv4) +struct sockaddr_in { + sa_family_t sin_family; + uint32_t sin_addr; + uint32_t sin_port; +}; + unsigned long int htonl(unsigned long int hostlong); unsigned short int htons(unsigned short int hostshort); unsigned long int ntohl(unsigned long int netlong); diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h new file mode 100644 index 0000000..38d12f6 --- /dev/null +++ b/src/modules/include/sys/socket.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +#include +#include + +typedef int socklen_t; +typedef unsigned int sa_family_t; + +struct sockaddr { + sa_family_t sa_family; + char sa_data[]; +}; + +struct sockaddr_storage { + sa_family_t ss_family; +}; + +enum { + SOCK_STREAM, +}; + +enum { + AF_INET, +}; + +enum { + IPPROTO_TCP, + IPPROTO_UDP, +}; + +/** + * Erstellt einen Socket + * + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) + * @param protocol Wird ignoriert; tyndur benutzt immer das Default-Protokoll, + * das zu domain und type passt + * + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. + */ +int socket(int domain, int type, int protocol); + +/** + * Verbindet einen Socket (als Client) mit einer Gegenstelle + * + * @param socket Socket, der verbunden werden soll + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) + * @param address_len Laenge der Adresse in Bytes + * + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. + */ +int connect(int socket, struct sockaddr* address, socklen_t address_len); + +/** + * Liest eine Anzahl Bytes aus einem Socket + */ +ssize_t recv(int socket, const void *buffer, size_t length, int flags); + +/** + * Sendet eine Nachricht ueber einen Socket + */ +ssize_t send(int socket, const void *buffer, size_t length, int flags); + +#endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 738eae8..2a41daf 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -29,6 +29,9 @@ #include #include +#include +#include + unsigned long int htonl(unsigned long int hostlong) { return big_endian_dword(hostlong); diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c new file mode 100644 index 0000000..61cd379 --- /dev/null +++ b/src/modules/lib/posix/socket.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include + +struct socket { + uint64_t id; + struct tree_item tinfo; + + sa_family_t sa_family; + FILE conn; +}; + +static tree_t* sockets = NULL; + +/** + * Ruft die Socketstruktur anhand des Filedeskriptors ab + */ +static struct socket* get_socket(int sock) +{ + if (sockets == NULL) { + return NULL; + } + + return tree_search(sockets, sock); +} + +/** + * Ruft die Socketstruktur anhand des Filedeskriptors ab + */ +static int create_socket(struct socket* socket) +{ + if (sockets == NULL) { + sockets = tree_create(struct socket, tinfo, id); + } + + socket->id = fileno(&socket->conn); + tree_insert(sockets, socket); + return socket->id; +} + +/** + * Erstellt einen Socket + * + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) + * @param protocol Wird ignoriert; tyndur benutzt immer das Default-Protokoll, + * das zu domain und type passt + * + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. + * + * FIXME protocol wird ignoriert + */ +int socket(int domain, int type, int protocol) +{ + int sock; + struct socket* socket; + + if (domain != AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + + if (type != SOCK_STREAM) { + errno = EPROTOTYPE; + return -1; + } + + socket = calloc(1, sizeof(*socket)); + socket->sa_family = domain; + memset(&socket->conn, 0, sizeof(socket->conn)); + + sock = create_socket(socket); + + return sock; +} + +/** + * Verbindet einen Socket (als Client) mit einer Gegenstelle + * + * @param socket Socket, der verbunden werden soll + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) + * @param address_len Laenge der Adresse in Bytes + * + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. + */ +int connect(int sock, struct sockaddr* address, socklen_t address_len) +{ + struct socket* socket = get_socket(sock); + struct sockaddr_in* inet_addr = (struct sockaddr_in*) address; + char* ip_string; + uint16_t port; + char* path; + int ret = 0; + FILE* conn; + + if (socket == NULL) { + errno = EBADF; + return -1; + } + + if (address->sa_family != socket->sa_family) { + errno = EAFNOSUPPORT; + return -1; + } + + ip_string = ip_to_string(inet_addr->sin_addr); + port = big_endian_word(inet_addr->sin_port); + if (asprintf(&path, "tcpip:/%s:%d", ip_string, port) < 0) + { + errno = ENOMEM; + ret = -1; + goto out; + } + + conn = fopen(path, "r+"); + if (conn == NULL) { + errno = ETIMEDOUT; + ret = -1; + goto out; + } + + // FIXME Boeser Hack + memcpy(&socket->conn, conn, sizeof(*conn)); + free(conn); + +out: + free(ip_string); + free(path); + + return 0; +} + +/** + * Liest eine Anzahl Bytes aus einem Socket + * + * TODO Mit den Flags was sinnvolles machen + */ +ssize_t recv(int socket, const void *buffer, size_t length, int flags) +{ + return read(socket, (void*) buffer, length); +} + +/** + * Sendet eine Anzahl Bytes ueber einen Socket + * + * TODO Mit den Flags was sinnvolles machen + */ +ssize_t send(int socket, const void *buffer, size_t length, int flags) +{ + return write(socket, buffer, length); +} -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:26:19 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:26:19 +0200 Subject: [tyndur-devel] [PATCH 0/5] libc fuer Python und Lynx Message-ID: <1239639984-3251-1-git-send-email-kevin@tyndur.org> Diese Patchserie besteht aus verschiedenen, thematisch ansonsten nicht zusammengehoerigen Patches fuer die libc, die benoetigt werden, um Python und Lynx fuer tyndur zu kompilieren bzw. erfolgreich zu starten. Kevin Wolf (5): libc: labs(), llabs() libc: Dummy for locale.h libc: sig_atomic_t Fix fuer INT_MIN libc: POSIX: Dummy fuer flock() src/include/limits.h | 2 +- src/include/stdlib.h | 25 ++++++++++- src/lib/misc.c | 36 ---------------- src/modules/include/locale.h | 92 ++++++++++++++++++++++++++++++++++++++++ src/modules/include/signal.h | 2 + src/modules/include/sys/file.h | 44 +++++++++++++++++++ src/modules/lib/posix/flock.c | 46 ++++++++++++++++++++ 7 files changed, 209 insertions(+), 38 deletions(-) delete mode 100644 src/lib/misc.c create mode 100644 src/modules/include/locale.h create mode 100644 src/modules/include/sys/file.h create mode 100644 src/modules/lib/posix/flock.c From kevin at tyndur.org Mon Apr 13 18:26:21 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:26:21 +0200 Subject: [tyndur-devel] [PATCH 2/5] libc: Dummy for locale.h In-Reply-To: <1239639984-3251-1-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639984-3251-3-git-send-email-kevin@tyndur.org> + libc: Dummy fuer localeconv() --- src/modules/include/locale.h | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 92 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/locale.h diff --git a/src/modules/include/locale.h b/src/modules/include/locale.h new file mode 100644 index 0000000..3850fd0 --- /dev/null +++ b/src/modules/include/locale.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCALE_H_ +#define _LOCALE_H_ + +#include + +struct lconv { + /* Allgemeine Definitionen */ + char *decimal_point; + char *thousands_sep; + char *grouping; + + /* Waehrungen */ + char *int_curr_symbol; + char *currency_symbol; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + + /** + * Position des Vorzeichens bei positiven Betraegen + * 1: + 100 EUR und + $100 + * 2: 100 EUR + und $100 + + * 3: 100 + EUR und + $100 + * 4: 100 EUR + und $ +100 + */ + char p_sign_posn; + + /// Position des Vorzeichens bei negativen Betraegen + char n_sign_posn; +}; + + +#ifndef CONFIG_LIBC_NO_STUBS +/** + * Gibt Informationen zur aktiven Locale zurueck + */ +static inline struct lconv* localeconv(void) +{ + static struct lconv lconv = { + .decimal_point = ",", + .thousands_sep = " ", + .mon_decimal_point = ",", + .mon_thousands_sep = " ", + .int_curr_symbol = "EUR", + .currency_symbol = "EUR", + .positive_sign = "+", + .negative_sign = "-", + .p_sign_posn = 1, + .n_sign_posn = 1, + }; + + return &lconv; +}; +#endif + +#endif -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:26:20 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:26:20 +0200 Subject: [tyndur-devel] [PATCH 1/5] libc: labs(), llabs() In-Reply-To: <1239639984-3251-1-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639984-3251-2-git-send-email-kevin@tyndur.org> + libc: long- und long-long-Varianten von abs() * libc: abs() ist eigentlich der perfekte Kandidat fuer inline --- src/include/stdlib.h | 25 ++++++++++++++++++++++++- src/lib/misc.c | 36 ------------------------------------ 2 files changed, 24 insertions(+), 37 deletions(-) delete mode 100644 src/lib/misc.c diff --git a/src/include/stdlib.h b/src/include/stdlib.h index 7327d60..97b70d4 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -74,7 +74,30 @@ char* mktemp(char* templatename); #ifndef CONFIG_LIBC_NO_STUBS double atof(const char* str); #endif -int abs(int x); + +/** + * Absolutbetrag einer Zahl errechnen + */ +static inline int abs(int x) +{ + return (x < 0 ? -x : x); +} + +/** + * Berechnet den Absolutwert eines long int + */ +static inline long int labs(long int x) +{ + return (x < 0 ? -x : x); +} + +/** + * Berechnet den Absolutwert eines long long int + */ +static inline long long int llabs(long long int x) +{ + return (x < 0 ? -x : x); +} int system(const char* command); diff --git a/src/lib/misc.c b/src/lib/misc.c deleted file mode 100644 index ec43765..0000000 --- a/src/lib/misc.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include - -/** - * Absolutbetrag einer Zahl errechnen - */ -int abs(int x) -{ - return (x < 0 ? -x : x); -} -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:26:22 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:26:22 +0200 Subject: [tyndur-devel] [PATCH 3/5] libc: sig_atomic_t In-Reply-To: <1239639984-3251-1-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639984-3251-4-git-send-email-kevin@tyndur.org> + libc: sig_atomic_t in signal.h --- src/modules/include/signal.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/src/modules/include/signal.h b/src/modules/include/signal.h index 8164637..0571c08 100644 --- a/src/modules/include/signal.h +++ b/src/modules/include/signal.h @@ -31,6 +31,8 @@ #include #include +typedef uint32_t sig_atomic_t; + // Signale /// Verbindung zu Terminal Verloren -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:26:24 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:26:24 +0200 Subject: [tyndur-devel] [PATCH 5/5] libc: POSIX: Dummy fuer flock() In-Reply-To: <1239639984-3251-1-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639984-3251-6-git-send-email-kevin@tyndur.org> + libc: POSIX: Dummy fuer flock() --- src/modules/include/sys/file.h | 44 ++++++++++++++++++++++++++++++++++++++ src/modules/lib/posix/flock.c | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/sys/file.h create mode 100644 src/modules/lib/posix/flock.c diff --git a/src/modules/include/sys/file.h b/src/modules/include/sys/file.h new file mode 100644 index 0000000..f4fcf30 --- /dev/null +++ b/src/modules/include/sys/file.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SYS_FILE_H_ +#define _SYS_FILE_H_ + +#ifndef CONFIG_LIBC_NO_STUBS +/** + * Datei-Lock nehmen oder abgeben + * + * @param fd Filedeskriptor der betroffenen Datei + * @param operation LOCK_SH (Shared Lock), LOCK_EX (Exklusiver Lock), LOCK_UN + * (Lock abgeben) + * + * @return 0 bei Erfolg, -1 im Fehlerfall + */ +int flock(int fd, int operation); +#endif + +#endif diff --git a/src/modules/lib/posix/flock.c b/src/modules/lib/posix/flock.c new file mode 100644 index 0000000..b8ec77e --- /dev/null +++ b/src/modules/lib/posix/flock.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#ifndef CONFIG_LIBC_NO_STUBS +/** + * Datei-Lock nehmen oder abgeben + * + * @param fd Filedeskriptor der betroffenen Datei + * @param operation LOCK_SH (Shared Lock), LOCK_EX (Exklusiver Lock), LOCK_UN + * (Lock abgeben) + * + * @return 0 bei Erfolg, -1 im Fehlerfall + */ +int flock(int fd, int operation) +{ + // TODO + return 0; +} +#endif -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 18:26:23 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 18:26:23 +0200 Subject: [tyndur-devel] [PATCH 4/5] Fix fuer INT_MIN In-Reply-To: <1239639984-3251-1-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> Message-ID: <1239639984-3251-5-git-send-email-kevin@tyndur.org> --- src/include/limits.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/include/limits.h b/src/include/limits.h index 53f635f..15640ef 100644 --- a/src/include/limits.h +++ b/src/include/limits.h @@ -50,7 +50,7 @@ #define LONG_MIN -0x80000000 #define INT_MAX 0x7FFFFFFF -#define INT_MIN -0x80000000 +#define INT_MIN (-INT_MAX - 1) #define ULONG_MAX 0xFFFFFFFF #define UINT_MAX 0xFFFFFFFF -- 1.6.0.2 From toni at tyndur.org Mon Apr 13 20:16:19 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:16:19 +0200 Subject: [tyndur-devel] [PATCH 1/4] libc: POSIX: Socket-Funktionen In-Reply-To: <1239639716-2793-2-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> <1239639716-2793-2-git-send-email-kevin@tyndur.org> Message-ID: <20090413181618.GA21931@einstein.produktiv.lan> On Mon, Apr 13 18:21, Kevin Wolf wrote: > + libc: POSIX: Socket-Funktionen > --- > src/include/errno.h | 12 +++ > src/modules/include/netinet/in.h | 10 ++ > src/modules/include/sys/socket.h | 99 +++++++++++++++++++ > src/modules/lib/posix/net.c | 3 + > src/modules/lib/posix/socket.c | 193 ++++++++++++++++++++++++++++++++++++++ > 5 files changed, 317 insertions(+), 0 deletions(-) > create mode 100644 src/modules/include/sys/socket.h > create mode 100644 src/modules/lib/posix/socket.c > > diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h > new file mode 100644 > index 0000000..38d12f6 > --- /dev/null > +++ b/src/modules/include/sys/socket.h > @@ -0,0 +1,99 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. Hast du hier absichtlich 4 Klauseln drin? > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > +#ifndef _SYS_SOCKET_H_ > +#define _SYS_SOCKET_H_ > + > +#include > +#include > + > +typedef int socklen_t; > +typedef unsigned int sa_family_t; > + > +struct sockaddr { > + sa_family_t sa_family; > + char sa_data[]; > +}; > + > +struct sockaddr_storage { > + sa_family_t ss_family; > +}; > + Zu diesen Strukturen wären ein paar Kommentare vielleich auch noch hilfreich... > +enum { > + SOCK_STREAM, > +}; > + > +enum { > + AF_INET, > +}; > + > +enum { > + IPPROTO_TCP, > + IPPROTO_UDP, > +}; > + > +/** > + * Erstellt einen Socket > + * > + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) > + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) > + * @param protocol Wird ignoriert; tyndur benutzt immer das Default-Protokoll, > + * das zu domain und type passt > + * > + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. > + */ > +int socket(int domain, int type, int protocol); > + > +/** > + * Verbindet einen Socket (als Client) mit einer Gegenstelle > + * > + * @param socket Socket, der verbunden werden soll > + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) > + * @param address_len Laenge der Adresse in Bytes > + * > + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. > + */ > +int connect(int socket, struct sockaddr* address, socklen_t address_len); > + > +/** > + * Liest eine Anzahl Bytes aus einem Socket > + */ > +ssize_t recv(int socket, const void *buffer, size_t length, int flags); > + > +/** > + * Sendet eine Nachricht ueber einen Socket > + */ > +ssize_t send(int socket, const void *buffer, size_t length, int flags); > + > +#endif > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > index 738eae8..2a41daf 100644 > --- a/src/modules/lib/posix/net.c > +++ b/src/modules/lib/posix/net.c > @@ -29,6 +29,9 @@ > #include > #include > > +#include > +#include > + > unsigned long int htonl(unsigned long int hostlong) > { > return big_endian_dword(hostlong); Hat eigentlich nichts mit der änderung zu tun, oder sehe ich das falsch? > diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c > new file mode 100644 > index 0000000..61cd379 > --- /dev/null > +++ b/src/modules/lib/posix/socket.c > @@ -0,0 +1,193 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include > +#include > + > +struct socket { > + uint64_t id; > + struct tree_item tinfo; > + > + sa_family_t sa_family; > + FILE conn; > +}; > + > +static tree_t* sockets = NULL; > + > +/** > + * Ruft die Socketstruktur anhand des Filedeskriptors ab > + */ > +static struct socket* get_socket(int sock) > +{ > + if (sockets == NULL) { > + return NULL; > + } > + > + return tree_search(sockets, sock); > +} > + > +/** > + * Ruft die Socketstruktur anhand des Filedeskriptors ab > + */ > +static int create_socket(struct socket* socket) > +{ > + if (sockets == NULL) { > + sockets = tree_create(struct socket, tinfo, id); > + } > + > + socket->id = fileno(&socket->conn); > + tree_insert(sockets, socket); > + return socket->id; > +} > + > +/** > + * Erstellt einen Socket > + * > + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) > + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) > + * @param protocol Wird ignoriert; tyndur benutzt immer das Default-Protokoll, > + * das zu domain und type passt > + * > + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. > + * > + * FIXME protocol wird ignoriert > + */ > +int socket(int domain, int type, int protocol) > +{ > + int sock; > + struct socket* socket; > + > + if (domain != AF_INET) { > + errno = EAFNOSUPPORT; > + return -1; > + } > + > + if (type != SOCK_STREAM) { > + errno = EPROTOTYPE; > + return -1; > + } > + > + socket = calloc(1, sizeof(*socket)); > + socket->sa_family = domain; > + memset(&socket->conn, 0, sizeof(socket->conn)); > + > + sock = create_socket(socket); > + > + return sock; > +} > + > +/** > + * Verbindet einen Socket (als Client) mit einer Gegenstelle > + * > + * @param socket Socket, der verbunden werden soll > + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) > + * @param address_len Laenge der Adresse in Bytes > + * > + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. > + */ > +int connect(int sock, struct sockaddr* address, socklen_t address_len) > +{ > + struct socket* socket = get_socket(sock); > + struct sockaddr_in* inet_addr = (struct sockaddr_in*) address; > + char* ip_string; > + uint16_t port; > + char* path; > + int ret = 0; > + FILE* conn; > + > + if (socket == NULL) { > + errno = EBADF; > + return -1; > + } > + > + if (address->sa_family != socket->sa_family) { > + errno = EAFNOSUPPORT; > + return -1; > + } > + > + ip_string = ip_to_string(inet_addr->sin_addr); > + port = big_endian_word(inet_addr->sin_port); > + if (asprintf(&path, "tcpip:/%s:%d", ip_string, port) < 0) > + { In dem fall ist aber das free(path) eher ungeschickt. > + errno = ENOMEM; > + ret = -1; > + goto out; > + } > + > + conn = fopen(path, "r+"); > + if (conn == NULL) { > + errno = ETIMEDOUT; > + ret = -1; > + goto out; > + } > + > + // FIXME Boeser Hack > + memcpy(&socket->conn, conn, sizeof(*conn)); > + free(conn); Uäh... ;-) > + > +out: > + free(ip_string); > + free(path); > + > + return 0; > +} > + > +/** > + * Liest eine Anzahl Bytes aus einem Socket > + * > + * TODO Mit den Flags was sinnvolles machen > + */ > +ssize_t recv(int socket, const void *buffer, size_t length, int flags) > +{ > + return read(socket, (void*) buffer, length); > +} > + > +/** > + * Sendet eine Anzahl Bytes ueber einen Socket > + * > + * TODO Mit den Flags was sinnvolles machen > + */ > +ssize_t send(int socket, const void *buffer, size_t length, int flags) > +{ > + return write(socket, buffer, length); > +} Was mache ich eigentlich mit so einen Socket wenn ich genug davon habe? Kann ich das dann irgendwie loswerden? -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 20:20:34 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:20:34 +0200 Subject: [tyndur-devel] [PATCH 2/4] libc: POSIX: arpa/inet.h In-Reply-To: <1239639716-2793-3-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> <1239639716-2793-3-git-send-email-kevin@tyndur.org> Message-ID: <20090413182033.GB21931@einstein.produktiv.lan> On Mon, Apr 13 18:21, Kevin Wolf wrote: > ! libc: htons() und aehnliches gehoeren laut Standard nach arpa/inet.h und > nicht nach netinet/in.h Dann koennte man sie doch dort rausloeschen, oder? -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 20:34:50 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:34:50 +0200 Subject: [tyndur-devel] [PATCH 3/4] libc: POSIX: gethostbyname() In-Reply-To: <1239639716-2793-4-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> <1239639716-2793-4-git-send-email-kevin@tyndur.org> Message-ID: <20090413183449.GC21931@einstein.produktiv.lan> On Mon, Apr 13 18:21, Kevin Wolf wrote: > + libc: POSIX: gethostbyname() > --- > src/modules/include/netinet/in.h | 1 + > src/modules/include/network.h | 2 +- > src/modules/lib/network.c | 2 +- > src/modules/lib/posix/net.c | 40 ++++++++++++++++++++++++++++++++++++++ > 4 files changed, 43 insertions(+), 2 deletions(-) > > diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h > index 14963a4..5bf18d2 100644 > --- a/src/modules/include/netinet/in.h > +++ b/src/modules/include/netinet/in.h > @@ -31,6 +31,7 @@ > > #include > #include > +#include > > /// Adresse fuer das INET-Protokol (IPv4) > struct sockaddr_in { Aha, hier rein, und im nächsten Patch grad wieder raus, muss das so sein? ;-) > diff --git a/src/modules/include/network.h b/src/modules/include/network.h > index 9be97db..ef0bb99 100644 > --- a/src/modules/include/network.h > +++ b/src/modules/include/network.h > @@ -48,7 +48,7 @@ struct net_device { > dword ip; > }; > > -dword string_to_ip(char* ip); > +dword string_to_ip(const char* ip); > char* ip_to_string(dword ip); > char* mac_to_string(uint64_t mac); > void register_netcard(dword device_numer, uint64_t mac, dword ip); > diff --git a/src/modules/lib/network.c b/src/modules/lib/network.c > index 927ada8..d0343d3 100644 > --- a/src/modules/lib/network.c > +++ b/src/modules/lib/network.c > @@ -40,7 +40,7 @@ > * Dezimalzahlen (a.b.c.d). Andere Darstellungen (z.B. eine Hexzahl) sind > * derzeit nicht unterst???tzt. > */ > -dword string_to_ip(char* ip) > +dword string_to_ip(const char* ip) > { > byte ip_bytes[4] = { 0, 0, 0, 0 }; > > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > index 2a41daf..c6fbdb8 100644 > --- a/src/modules/lib/posix/net.c > +++ b/src/modules/lib/posix/net.c > @@ -28,6 +28,9 @@ > > #include > #include > +#include Dafür brauche ich dann /dev/kristallkugel, oder wo kriege ich die her? ;-) Oder ist es schon zu spät und ich übersehe sie nur? > + > +#include > > #include > #include > @@ -51,3 +54,40 @@ unsigned short int ntohs(unsigned short int netshort) > { > return big_endian_dword(netshort); > } > + > +struct hostent* gethostbyname(const char* name) > +{ > + static struct hostent hostent; > + static char* aliases[] = { NULL }; > + static uint32_t ip; > + static uint32_t* h_addr_list[] = { &ip, NULL }; > + > + // Erstmal schauen, ob es eine IP-Adresse ist > + ip = string_to_ip(name); > + > + // Wenn nicht, muessen wir eine DNS-Anfrage machen > + if (ip == 0) { > + char* path; > + FILE* f; > + char ip_str[16]; > + > + asprintf(&path, "tcpip:/dns/%s", name); > + f = fopen(path, "r"); > + if (!f) { > + return NULL; > + } > + fread(ip_str, 1, 16, f); > + fclose(f); > + > + ip = string_to_ip(ip_str); > + } > + > + // hostent aktualisieren > + hostent.h_name = (char*) name; > + hostent.h_aliases = aliases; > + hostent.h_addrtype = AF_INET; > + hostent.h_length = 4; > + hostent.h_addr_list = (char**) h_addr_list; > + > + return &hostent; > +} -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 20:38:53 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:38:53 +0200 Subject: [tyndur-devel] [PATCH 4/4] libc: POSIX: IP-Adressen-Umwandlung String/Integer In-Reply-To: <1239639716-2793-5-git-send-email-kevin@tyndur.org> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> <1239639716-2793-5-git-send-email-kevin@tyndur.org> Message-ID: <20090413183853.GD21931@einstein.produktiv.lan> On Mon, Apr 13 18:21, Kevin Wolf wrote: > + libc: POSIX: inet_aton() / inet_ntoa() > --- > src/modules/include/netinet/in.h | 20 +++++++++++++++++++- > src/modules/lib/posix/net.c | 29 +++++++++++++++++++++++++++++ > 2 files changed, 48 insertions(+), 1 deletions(-) > > diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h > index 5bf18d2..6638d7e 100644 > --- a/src/modules/include/netinet/in.h > +++ b/src/modules/include/netinet/in.h > @@ -31,7 +31,6 @@ > > #include > #include > -#include > > /// Adresse fuer das INET-Protokol (IPv4) > struct sockaddr_in { > @@ -40,10 +39,29 @@ struct sockaddr_in { > uint32_t sin_port; > }; > > +typedef uint32_t in_addr_t; > +struct in_addr { > + in_addr_t s_addr; > +}; > + > unsigned long int htonl(unsigned long int hostlong); > unsigned short int htons(unsigned short int hostshort); > unsigned long int ntohl(unsigned long int netlong); > unsigned short int ntohs(unsigned short int netshort); > > +/** > + * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen > + * 32-Bit-Wert um. > + * > + * @return 0 im Fehlerfall; ungleich 0 bei Erfolg > + */ > +int inet_aton(const char *cp, struct in_addr *inp); Diese Sternchen entsprechen so aber nicht unserer Konvention, kommt davon wenn man aus den Manpages kopiert, dann haben die Parameter auch immer so sprechende Namen. ;-) > + > +/** > + * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem > + * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. > + */ > +char *inet_ntoa(struct in_addr in); Auch hier noch ein * am falschen Ort. > + > #endif > > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > index c6fbdb8..a463790 100644 > --- a/src/modules/lib/posix/net.c > +++ b/src/modules/lib/posix/net.c > @@ -55,6 +55,35 @@ unsigned short int ntohs(unsigned short int netshort) > return big_endian_dword(netshort); > } > > +/** > + * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen > + * 32-Bit-Wert um. > + * > + * @return 0 im Fehlerfall; ungleich 0 bei Erfolg > + * FIXME 0.0.0.0 ist eine gueltige Adresse > + */ > +int inet_aton(const char *cp, struct in_addr *inp) > +{ > + inp->s_addr = string_to_ip((char*) cp); > + return inp->s_addr; > +} > + > +/** > + * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem > + * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. > + */ > +char *inet_ntoa(struct in_addr in) > +{ > + static char buf[16]; > + char* res; > + > + res = ip_to_string(in.s_addr); > + strncpy(buf, res, 16); > + free(res); > + > + return buf; > +} > + > struct hostent* gethostbyname(const char* name) > { > static struct hostent hostent; Aber sonst sieht das gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Mon Apr 13 20:44:52 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Mon, 13 Apr 2009 20:44:52 +0200 Subject: [tyndur-devel] [PATCH 1/4] libc: POSIX: Socket-Funktionen In-Reply-To: <20090413181618.GA21931@einstein.produktiv.lan> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> <1239639716-2793-2-git-send-email-kevin@tyndur.org> <20090413181618.GA21931@einstein.produktiv.lan> Message-ID: <200904132044.53029@kevin-wolf.de> Am Montag, 13. April 2009 20:16 schrieb Antoine Kaufmann: > On Mon, Apr 13 18:21, Kevin Wolf wrote: > > + libc: POSIX: Socket-Funktionen > > --- > > src/include/errno.h | 12 +++ > > src/modules/include/netinet/in.h | 10 ++ > > src/modules/include/sys/socket.h | 99 +++++++++++++++++++ > > src/modules/lib/posix/net.c | 3 + > > src/modules/lib/posix/socket.c | 193 > > ++++++++++++++++++++++++++++++++++++++ 5 files changed, 317 > > insertions(+), 0 deletions(-) > > create mode 100644 src/modules/include/sys/socket.h > > create mode 100644 src/modules/lib/posix/socket.c > > > > diff --git a/src/modules/include/sys/socket.h > > b/src/modules/include/sys/socket.h new file mode 100644 > > index 0000000..38d12f6 > > --- /dev/null > > +++ b/src/modules/include/sys/socket.h > > @@ -0,0 +1,99 @@ > > +/* > > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > > + * > > + * This code is derived from software contributed to the tyndur Project > > + * by Kevin Wolf. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + * notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above copyright > > + * notice, this list of conditions and the following disclaimer in > > the + * documentation and/or other materials provided with the > > distribution. + * 3. All advertising materials mentioning features or use > > of this software + * must display the following acknowledgement: > > + * This product includes software developed by the tyndur Project > > + * and its contributors. > > + * 4. Neither the name of the tyndur Project nor the names of its > > + * contributors may be used to endorse or promote products derived > > + * from this software without specific prior written permission. > > Hast du hier absichtlich 4 Klauseln drin? Ups. Good catch. Die Anfänge der Patchserie sind schon etwas älter. ;-) > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > > LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > > A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > > HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, > > INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, > > BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS > > OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED > > AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT > > LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY > > WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE > > POSSIBILITY OF SUCH DAMAGE. > > + */ > > +#ifndef _SYS_SOCKET_H_ > > +#define _SYS_SOCKET_H_ > > + > > +#include > > +#include > > + > > +typedef int socklen_t; > > +typedef unsigned int sa_family_t; > > + > > +struct sockaddr { > > + sa_family_t sa_family; > > + char sa_data[]; > > +}; > > + > > +struct sockaddr_storage { > > + sa_family_t ss_family; > > +}; > > + > > Zu diesen Strukturen wären ein paar Kommentare vielleich auch noch > hilfreich... > > > +enum { > > + SOCK_STREAM, > > +}; > > + > > +enum { > > + AF_INET, > > +}; > > + > > +enum { > > + IPPROTO_TCP, > > + IPPROTO_UDP, > > +}; > > + > > +/** > > + * Erstellt einen Socket > > + * > > + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) > > + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) > > + * @param protocol Wird ignoriert; tyndur benutzt immer das > > Default-Protokoll, + * das zu domain und type passt > > + * > > + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. > > + */ > > +int socket(int domain, int type, int protocol); > > + > > +/** > > + * Verbindet einen Socket (als Client) mit einer Gegenstelle > > + * > > + * @param socket Socket, der verbunden werden soll > > + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) > > + * @param address_len Laenge der Adresse in Bytes > > + * > > + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. > > + */ > > +int connect(int socket, struct sockaddr* address, socklen_t > > address_len); + > > +/** > > + * Liest eine Anzahl Bytes aus einem Socket > > + */ > > +ssize_t recv(int socket, const void *buffer, size_t length, int flags); > > + > > +/** > > + * Sendet eine Nachricht ueber einen Socket > > + */ > > +ssize_t send(int socket, const void *buffer, size_t length, int flags); > > + > > +#endif > > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > > index 738eae8..2a41daf 100644 > > --- a/src/modules/lib/posix/net.c > > +++ b/src/modules/lib/posix/net.c > > @@ -29,6 +29,9 @@ > > #include > > #include > > > > +#include > > +#include > > + > > unsigned long int htonl(unsigned long int hostlong) > > { > > return big_endian_dword(hostlong); > > Hat eigentlich nichts mit der änderung zu tun, oder sehe ich das falsch? Hm, jo. git rebase hat sich heute irgendwann mal kräftig verschluckt, das dürfte ein Überbleibsel davon sein. Mal sehen, in welchem anderen Patch es dann fehlt. > > diff --git a/src/modules/lib/posix/socket.c > > b/src/modules/lib/posix/socket.c new file mode 100644 > > index 0000000..61cd379 > > --- /dev/null > > +++ b/src/modules/lib/posix/socket.c > > @@ -0,0 +1,193 @@ > > +/* > > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > > + * > > + * This code is derived from software contributed to the tyndur Project > > + * by Kevin Wolf. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + * notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above copyright > > + * notice, this list of conditions and the following disclaimer in > > the + * documentation and/or other materials provided with the > > distribution. + * 3. All advertising materials mentioning features or use > > of this software + * must display the following acknowledgement: > > + * This product includes software developed by the tyndur Project > > + * and its contributors. > > + * 4. Neither the name of the tyndur Project nor the names of its > > + * contributors may be used to endorse or promote products derived > > + * from this software without specific prior written permission. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > > LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > > A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > > HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, > > INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, > > BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS > > OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED > > AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT > > LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY > > WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE > > POSSIBILITY OF SUCH DAMAGE. > > + */ > > + > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > + > > +struct socket { > > + uint64_t id; > > + struct tree_item tinfo; > > + > > + sa_family_t sa_family; > > + FILE conn; > > +}; > > + > > +static tree_t* sockets = NULL; > > + > > +/** > > + * Ruft die Socketstruktur anhand des Filedeskriptors ab > > + */ > > +static struct socket* get_socket(int sock) > > +{ > > + if (sockets == NULL) { > > + return NULL; > > + } > > + > > + return tree_search(sockets, sock); > > +} > > + > > +/** > > + * Ruft die Socketstruktur anhand des Filedeskriptors ab > > + */ > > +static int create_socket(struct socket* socket) > > +{ > > + if (sockets == NULL) { > > + sockets = tree_create(struct socket, tinfo, id); > > + } > > + > > + socket->id = fileno(&socket->conn); > > + tree_insert(sockets, socket); > > + return socket->id; > > +} > > + > > +/** > > + * Erstellt einen Socket > > + * > > + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) > > + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) > > + * @param protocol Wird ignoriert; tyndur benutzt immer das > > Default-Protokoll, + * das zu domain und type passt > > + * > > + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. > > + * > > + * FIXME protocol wird ignoriert > > + */ > > +int socket(int domain, int type, int protocol) > > +{ > > + int sock; > > + struct socket* socket; > > + > > + if (domain != AF_INET) { > > + errno = EAFNOSUPPORT; > > + return -1; > > + } > > + > > + if (type != SOCK_STREAM) { > > + errno = EPROTOTYPE; > > + return -1; > > + } > > + > > + socket = calloc(1, sizeof(*socket)); > > + socket->sa_family = domain; > > + memset(&socket->conn, 0, sizeof(socket->conn)); > > + > > + sock = create_socket(socket); > > + > > + return sock; > > +} > > + > > +/** > > + * Verbindet einen Socket (als Client) mit einer Gegenstelle > > + * > > + * @param socket Socket, der verbunden werden soll > > + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) > > + * @param address_len Laenge der Adresse in Bytes > > + * > > + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. > > + */ > > +int connect(int sock, struct sockaddr* address, socklen_t address_len) > > +{ > > + struct socket* socket = get_socket(sock); > > + struct sockaddr_in* inet_addr = (struct sockaddr_in*) address; > > + char* ip_string; > > + uint16_t port; > > + char* path; > > + int ret = 0; > > + FILE* conn; > > + > > + if (socket == NULL) { > > + errno = EBADF; > > + return -1; > > + } > > + > > + if (address->sa_family != socket->sa_family) { > > + errno = EAFNOSUPPORT; > > + return -1; > > + } > > + > > + ip_string = ip_to_string(inet_addr->sin_addr); > > + port = big_endian_word(inet_addr->sin_port); > > + if (asprintf(&path, "tcpip:/%s:%d", ip_string, port) < 0) > > + { > > In dem fall ist aber das free(path) eher ungeschickt. > > > + errno = ENOMEM; > > + ret = -1; > > + goto out; > > + } > > + > > + conn = fopen(path, "r+"); > > + if (conn == NULL) { > > + errno = ETIMEDOUT; > > + ret = -1; > > + goto out; > > + } > > + > > + // FIXME Boeser Hack > > + memcpy(&socket->conn, conn, sizeof(*conn)); > > + free(conn); > > Uäh... ;-) An irgendwas muß man es ja als tyndur-Code erkennen ;-) > > + > > +out: > > + free(ip_string); > > + free(path); > > + > > + return 0; > > +} > > + > > +/** > > + * Liest eine Anzahl Bytes aus einem Socket > > + * > > + * TODO Mit den Flags was sinnvolles machen > > + */ > > +ssize_t recv(int socket, const void *buffer, size_t length, int flags) > > +{ > > + return read(socket, (void*) buffer, length); > > +} > > + > > +/** > > + * Sendet eine Anzahl Bytes ueber einen Socket > > + * > > + * TODO Mit den Flags was sinnvolles machen > > + */ > > +ssize_t send(int socket, const void *buffer, size_t length, int flags) > > +{ > > + return write(socket, buffer, length); > > +} > > Was mache ich eigentlich mit so einen Socket wenn ich genug davon habe? > Kann ich das dann irgendwie loswerden? Dann programmierst du einen Hook in close(), der für Sockets das entsprechende Element aus dem sockets-Baum rauswirft. ;-) From toni at tyndur.org Mon Apr 13 20:46:05 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:46:05 +0200 Subject: [tyndur-devel] [PATCH 1/5] libc: labs(), llabs() In-Reply-To: <1239639984-3251-2-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> <1239639984-3251-2-git-send-email-kevin@tyndur.org> Message-ID: <20090413184605.GE21931@einstein.produktiv.lan> On Mon, Apr 13 18:26, Kevin Wolf wrote: > + libc: long- und long-long-Varianten von abs() > * libc: abs() ist eigentlich der perfekte Kandidat fuer inline Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Mon Apr 13 20:47:03 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Mon, 13 Apr 2009 20:47:03 +0200 Subject: [tyndur-devel] [PATCH 2/4] libc: POSIX: arpa/inet.h In-Reply-To: <20090413182033.GB21931@einstein.produktiv.lan> References: <1239639716-2793-1-git-send-email-kevin@tyndur.org> <1239639716-2793-3-git-send-email-kevin@tyndur.org> <20090413182033.GB21931@einstein.produktiv.lan> Message-ID: <200904132047.03375@kevin-wolf.de> Am Montag, 13. April 2009 20:20 schrieb Antoine Kaufmann: > On Mon, Apr 13 18:21, Kevin Wolf wrote: > > ! libc: htons() und aehnliches gehoeren laut Standard nach arpa/inet.h > > und nicht nach netinet/in.h > > Dann koennte man sie doch dort rausloeschen, oder? Ja. War auch mal so, bis git sich dran versucht hat. :-/ From toni at tyndur.org Mon Apr 13 20:51:02 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:51:02 +0200 Subject: [tyndur-devel] [PATCH 2/5] libc: Dummy for locale.h In-Reply-To: <1239639984-3251-3-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> <1239639984-3251-3-git-send-email-kevin@tyndur.org> Message-ID: <20090413185102.GF21931@einstein.produktiv.lan> On Mon, Apr 13 18:26, Kevin Wolf wrote: > + libc: Dummy fuer localeconv() Rein damit, das ist immerhin mal ein Anfang. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 20:55:56 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:55:56 +0200 Subject: [tyndur-devel] [PATCH 4/5] Fix fuer INT_MIN In-Reply-To: <1239639984-3251-5-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> <1239639984-3251-5-git-send-email-kevin@tyndur.org> Message-ID: <20090413185556.GG21931@einstein.produktiv.lan> On Mon, Apr 13 18:26, Kevin Wolf wrote: > --- > src/include/limits.h | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/src/include/limits.h b/src/include/limits.h > index 53f635f..15640ef 100644 > --- a/src/include/limits.h > +++ b/src/include/limits.h > @@ -50,7 +50,7 @@ > #define LONG_MIN -0x80000000 > > #define INT_MAX 0x7FFFFFFF > -#define INT_MIN -0x80000000 > +#define INT_MIN (-INT_MAX - 1) > > #define ULONG_MAX 0xFFFFFFFF > #define UINT_MAX 0xFFFFFFFF Sieht lustig aus. ;-) Könnte das Problem bei anderen _MIN eventuell auch noch bestehen (z.B. LONG_MIN)? -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 20:57:33 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:57:33 +0200 Subject: [tyndur-devel] [PATCH 3/5] libc: sig_atomic_t In-Reply-To: <1239639984-3251-4-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> <1239639984-3251-4-git-send-email-kevin@tyndur.org> Message-ID: <20090413185733.GH21931@einstein.produktiv.lan> On Mon, Apr 13 18:26, Kevin Wolf wrote: > + libc: sig_atomic_t in signal.h > --- > src/modules/include/signal.h | 2 ++ > 1 files changed, 2 insertions(+), 0 deletions(-) > > diff --git a/src/modules/include/signal.h b/src/modules/include/signal.h > index 8164637..0571c08 100644 > --- a/src/modules/include/signal.h > +++ b/src/modules/include/signal.h > @@ -31,6 +31,8 @@ > #include > #include > > +typedef uint32_t sig_atomic_t; > + > // Signale > > /// Verbindung zu Terminal Verloren Wenn du meinst.... ;-) Ich habe zwar davon keine Ahnung, wird aber schon gut sein. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 20:58:17 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 20:58:17 +0200 Subject: [tyndur-devel] [PATCH 5/5] libc: POSIX: Dummy fuer flock() In-Reply-To: <1239639984-3251-6-git-send-email-kevin@tyndur.org> References: <1239639984-3251-1-git-send-email-kevin@tyndur.org> <1239639984-3251-6-git-send-email-kevin@tyndur.org> Message-ID: <20090413185817.GI21931@einstein.produktiv.lan> On Mon, Apr 13 18:26, Kevin Wolf wrote: > + libc: POSIX: Dummy fuer flock() Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Mon Apr 13 21:07:48 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 21:07:48 +0200 Subject: [tyndur-devel] [PATCH v2 4/4] libc: POSIX: IP-Adressen-Umwandlung String/Integer In-Reply-To: <1239649668-5016-1-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> Message-ID: <1239649668-5016-5-git-send-email-kevin@tyndur.org> + libc: POSIX: inet_aton() / inet_ntoa() --- src/modules/include/netinet/in.h | 19 +++++++++++++++++++ src/modules/lib/posix/net.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 0 deletions(-) diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index 366319f..a150e23 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -39,5 +39,24 @@ struct sockaddr_in { uint32_t sin_port; }; +typedef uint32_t in_addr_t; +struct in_addr { + in_addr_t s_addr; +}; + +/** + * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen + * 32-Bit-Wert um. + * + * @return 0 im Fehlerfall; ungleich 0 bei Erfolg + */ +int inet_aton(const char* ip_string, struct in_addr* ip); + +/** + * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem + * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. + */ +char* inet_ntoa(struct in_addr ip); + #endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index f544b45..545c906 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -31,6 +31,8 @@ #include #include +#include +#include unsigned long int htonl(unsigned long int hostlong) { @@ -52,6 +54,35 @@ unsigned short int ntohs(unsigned short int netshort) return big_endian_dword(netshort); } +/** + * Wandelt einen String, der eine IP-Adresse der Form a.b.c.d enthaelt in einen + * 32-Bit-Wert um. + * + * @return 0 im Fehlerfall; ungleich 0 bei Erfolg + * FIXME 0.0.0.0 ist eine gueltige Adresse + */ +int inet_aton(const char* ip_string, struct in_addr* ip) +{ + ip->s_addr = string_to_ip((char*) ip_string); + return ip->s_addr; +} + +/** + * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem + * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. + */ +char* inet_ntoa(struct in_addr ip) +{ + static char buf[16]; + char* res; + + res = ip_to_string(ip.s_addr); + strncpy(buf, res, 16); + free(res); + + return buf; +} + struct hostent* gethostbyname(const char* name) { static struct hostent hostent; -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 21:07:46 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 21:07:46 +0200 Subject: [tyndur-devel] [PATCH v2 2/4] libc: POSIX: arpa/inet.h In-Reply-To: <1239649668-5016-1-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> Message-ID: <1239649668-5016-3-git-send-email-kevin@tyndur.org> ! libc: htons() und aehnliches gehoeren laut Standard nach arpa/inet.h und nicht nach netinet/in.h --- src/modules/include/arpa/inet.h | 38 ++++++++++++++++++++++++++++++++++++++ src/modules/include/netinet/in.h | 5 ----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/modules/include/arpa/inet.h diff --git a/src/modules/include/arpa/inet.h b/src/modules/include/arpa/inet.h new file mode 100644 index 0000000..23610a9 --- /dev/null +++ b/src/modules/include/arpa/inet.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ARPA_INET_H_ +#define _ARPA_INET_H_ + +unsigned long int htonl(unsigned long int hostlong); +unsigned short int htons(unsigned short int hostshort); +unsigned long int ntohl(unsigned long int netlong); +unsigned short int ntohs(unsigned short int netshort); + +#endif + diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index 14963a4..366319f 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -39,10 +39,5 @@ struct sockaddr_in { uint32_t sin_port; }; -unsigned long int htonl(unsigned long int hostlong); -unsigned short int htons(unsigned short int hostshort); -unsigned long int ntohl(unsigned long int netlong); -unsigned short int ntohs(unsigned short int netshort); - #endif -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 21:07:47 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 21:07:47 +0200 Subject: [tyndur-devel] [PATCH v2 3/4] libc: POSIX: gethostbyname() In-Reply-To: <1239649668-5016-1-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> Message-ID: <1239649668-5016-4-git-send-email-kevin@tyndur.org> + libc: POSIX: gethostbyname() --- src/modules/include/netdb.h | 44 +++++++++++++++++++++++++++++++++++++++++ src/modules/include/network.h | 2 +- src/modules/lib/network.c | 2 +- src/modules/lib/posix/net.c | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/modules/include/netdb.h diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h new file mode 100644 index 0000000..d2a3666 --- /dev/null +++ b/src/modules/include/netdb.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NETDB_H_ +#define _NETDB_H_ + +struct hostent { + char* h_name; + char** h_aliases; + int h_addrtype; + int h_length; + char** h_addr_list; +#define h_addr h_addr_list[0] +}; + +struct hostent* gethostbyname(const char* name); + +#endif + diff --git a/src/modules/include/network.h b/src/modules/include/network.h index 9be97db..ef0bb99 100644 --- a/src/modules/include/network.h +++ b/src/modules/include/network.h @@ -48,7 +48,7 @@ struct net_device { dword ip; }; -dword string_to_ip(char* ip); +dword string_to_ip(const char* ip); char* ip_to_string(dword ip); char* mac_to_string(uint64_t mac); void register_netcard(dword device_numer, uint64_t mac, dword ip); diff --git a/src/modules/lib/network.c b/src/modules/lib/network.c index 927ada8..d0343d3 100644 --- a/src/modules/lib/network.c +++ b/src/modules/lib/network.c @@ -40,7 +40,7 @@ * Dezimalzahlen (a.b.c.d). Andere Darstellungen (z.B. eine Hexzahl) sind * derzeit nicht unterst�tzt. */ -dword string_to_ip(char* ip) +dword string_to_ip(const char* ip) { byte ip_bytes[4] = { 0, 0, 0, 0 }; diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 738eae8..f544b45 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -28,6 +28,9 @@ #include #include +#include + +#include unsigned long int htonl(unsigned long int hostlong) { @@ -48,3 +51,40 @@ unsigned short int ntohs(unsigned short int netshort) { return big_endian_dword(netshort); } + +struct hostent* gethostbyname(const char* name) +{ + static struct hostent hostent; + static char* aliases[] = { NULL }; + static uint32_t ip; + static uint32_t* h_addr_list[] = { &ip, NULL }; + + // Erstmal schauen, ob es eine IP-Adresse ist + ip = string_to_ip(name); + + // Wenn nicht, muessen wir eine DNS-Anfrage machen + if (ip == 0) { + char* path; + FILE* f; + char ip_str[16]; + + asprintf(&path, "tcpip:/dns/%s", name); + f = fopen(path, "r"); + if (!f) { + return NULL; + } + fread(ip_str, 1, 16, f); + fclose(f); + + ip = string_to_ip(ip_str); + } + + // hostent aktualisieren + hostent.h_name = (char*) name; + hostent.h_aliases = aliases; + hostent.h_addrtype = AF_INET; + hostent.h_length = 4; + hostent.h_addr_list = (char**) h_addr_list; + + return &hostent; +} -- 1.6.0.2 From kevin at tyndur.org Mon Apr 13 21:07:44 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 21:07:44 +0200 Subject: [tyndur-devel] [PATCH v2 0/4] POSIX: Sockets Message-ID: <1239649668-5016-1-git-send-email-kevin@tyndur.org> Diese Patchserie fuegt POSIX-Wrapper fuer Netzwerk hinzu. Offensichtlich gehoert dazu keine neue Funktionalitaet, deshalb vorerst nur Clients und nur TCP ueber IPv4. Kevin Wolf (4): libc: POSIX: Socket-Funktionen libc: POSIX: arpa/inet.h libc: POSIX: gethostbyname() libc: POSIX: IP-Adressen-Umwandlung String/Integer src/include/errno.h | 12 +++ src/modules/include/arpa/inet.h | 38 ++++++++ src/modules/include/netdb.h | 44 +++++++++ src/modules/include/netinet/in.h | 32 ++++++- src/modules/include/network.h | 2 +- src/modules/include/sys/socket.h | 106 +++++++++++++++++++++ src/modules/lib/network.c | 2 +- src/modules/lib/posix/net.c | 71 ++++++++++++++ src/modules/lib/posix/socket.c | 187 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 488 insertions(+), 6 deletions(-) create mode 100644 src/modules/include/arpa/inet.h create mode 100644 src/modules/include/netdb.h create mode 100644 src/modules/include/sys/socket.h create mode 100644 src/modules/lib/posix/socket.c From kevin at tyndur.org Mon Apr 13 21:07:45 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 13 Apr 2009 21:07:45 +0200 Subject: [tyndur-devel] [PATCH v2 1/4] libc: POSIX: Socket-Funktionen In-Reply-To: <1239649668-5016-1-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> Message-ID: <1239649668-5016-2-git-send-email-kevin@tyndur.org> + libc: POSIX: Socket-Funktionen --- src/include/errno.h | 12 +++ src/modules/include/netinet/in.h | 10 ++ src/modules/include/sys/socket.h | 106 +++++++++++++++++++++ src/modules/lib/posix/socket.c | 187 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 315 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/sys/socket.h create mode 100644 src/modules/lib/posix/socket.c diff --git a/src/include/errno.h b/src/include/errno.h index 2934ac1..3f8f16f 100644 --- a/src/include/errno.h +++ b/src/include/errno.h @@ -56,6 +56,18 @@ #define ESRCH 25 #define EPIPE 26 #define EILSEQ 27 + + +#define EAFNOSUPPORT 28 +#define ETIMEDOUT 29 +#define EPROTOTYPE 30 +#define ECONNREFUSED 31 +#define ENOTCONN 32 +#define ECONNRESET 33 +#define EINPROGRESS 34 +#define EALREADY 35 +#define EISCONN 36 + extern int errno; #endif diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index b48125f..14963a4 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -29,6 +29,16 @@ #ifndef _NETINET_IN_H_ #define _NETINET_IN_H_ +#include +#include + +/// Adresse fuer das INET-Protokol (IPv4) +struct sockaddr_in { + sa_family_t sin_family; + uint32_t sin_addr; + uint32_t sin_port; +}; + unsigned long int htonl(unsigned long int hostlong); unsigned short int htons(unsigned short int hostshort); unsigned long int ntohl(unsigned long int netlong); diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h new file mode 100644 index 0000000..a52b8de --- /dev/null +++ b/src/modules/include/sys/socket.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +#include +#include + +typedef int socklen_t; +typedef unsigned int sa_family_t; + +/** + * Beschreibt die Adresse einer Gegenstelle fuer einen Socket. + * + * Diese struct dient als "Vaterklasse" fuer weitere structs, die fuer die + * einzelnen Adressfamilien definiert sind. + */ +struct sockaddr { + /// Adressfamilie (AF_*) + sa_family_t sa_family; + + /// Adressfamilienspezifische Daten + char sa_data[]; +}; + +struct sockaddr_storage { + sa_family_t ss_family; +}; + +/// Protokolltypen +enum { + /// Verbindungsoriertierter Socket (z.B. TCP) + SOCK_STREAM, +}; + +/// Adressfamilien +enum { + /// IPv4 + AF_INET, +}; + +/// Protokolle fuer IP +enum { + IPPROTO_TCP, + IPPROTO_UDP, +}; + +/** + * Erstellt einen Socket + * + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) + * @param protocol Wird ignoriert; tyndur benutzt immer das Default-Protokoll, + * das zu domain und type passt + * + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. + */ +int socket(int domain, int type, int protocol); + +/** + * Verbindet einen Socket (als Client) mit einer Gegenstelle + * + * @param socket Socket, der verbunden werden soll + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) + * @param address_len Laenge der Adresse in Bytes + * + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. + */ +int connect(int socket, struct sockaddr* address, socklen_t address_len); + +/** + * Liest eine Anzahl Bytes aus einem Socket + */ +ssize_t recv(int socket, const void *buffer, size_t length, int flags); + +/** + * Sendet eine Nachricht ueber einen Socket + */ +ssize_t send(int socket, const void *buffer, size_t length, int flags); + +#endif diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c new file mode 100644 index 0000000..b8941d7 --- /dev/null +++ b/src/modules/lib/posix/socket.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include + +struct socket { + uint64_t id; + struct tree_item tinfo; + + sa_family_t sa_family; + FILE conn; +}; + +static tree_t* sockets = NULL; + +/** + * Ruft die Socketstruktur anhand des Filedeskriptors ab + */ +static struct socket* get_socket(int sock) +{ + if (sockets == NULL) { + return NULL; + } + + return tree_search(sockets, sock); +} + +/** + * Ruft die Socketstruktur anhand des Filedeskriptors ab + */ +static int create_socket(struct socket* socket) +{ + if (sockets == NULL) { + sockets = tree_create(struct socket, tinfo, id); + } + + socket->id = fileno(&socket->conn); + tree_insert(sockets, socket); + return socket->id; +} + +/** + * Erstellt einen Socket + * + * @param domain Protokollfamilie (AF_*, z.B. AF_INET fuer IPv4) + * @param type Protokolltyp (SOCK_*, z.B. SOCK_STREAM fuer TCP) + * @param protocol Wird ignoriert; tyndur benutzt immer das Default-Protokoll, + * das zu domain und type passt + * + * @return Socketnummer. Im Fehlerfall -1 und errno wird gesetzt. + * + * FIXME protocol wird ignoriert + */ +int socket(int domain, int type, int protocol) +{ + int sock; + struct socket* socket; + + if (domain != AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + + if (type != SOCK_STREAM) { + errno = EPROTOTYPE; + return -1; + } + + socket = calloc(1, sizeof(*socket)); + socket->sa_family = domain; + memset(&socket->conn, 0, sizeof(socket->conn)); + + sock = create_socket(socket); + + return sock; +} + +/** + * Verbindet einen Socket (als Client) mit einer Gegenstelle + * + * @param socket Socket, der verbunden werden soll + * @param address Adresse der Gegenstelle (z.B. IP-Adresse/TCP-Port) + * @param address_len Laenge der Adresse in Bytes + * + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. + */ +int connect(int sock, struct sockaddr* address, socklen_t address_len) +{ + struct socket* socket = get_socket(sock); + struct sockaddr_in* inet_addr = (struct sockaddr_in*) address; + char* ip_string; + uint16_t port; + char* path; + int ret = 0; + FILE* conn; + + if (socket == NULL) { + errno = EBADF; + return -1; + } + + if (address->sa_family != socket->sa_family) { + errno = EAFNOSUPPORT; + return -1; + } + + ip_string = ip_to_string(inet_addr->sin_addr); + port = big_endian_word(inet_addr->sin_port); + if (asprintf(&path, "tcpip:/%s:%d", ip_string, port) < 0) + { + errno = ENOMEM; + ret = -1; + goto out_ip_string; + } + + conn = fopen(path, "r+"); + if (conn == NULL) { + errno = ETIMEDOUT; + ret = -1; + goto out_path; + } + + // FIXME Boeser Hack + memcpy(&socket->conn, conn, sizeof(*conn)); + free(conn); + +out_path: + free(path); +out_ip_string: + free(ip_string); + + return 0; +} + +/** + * Liest eine Anzahl Bytes aus einem Socket + * + * TODO Mit den Flags was sinnvolles machen + */ +ssize_t recv(int socket, const void *buffer, size_t length, int flags) +{ + return read(socket, (void*) buffer, length); +} + +/** + * Sendet eine Anzahl Bytes ueber einen Socket + * + * TODO Mit den Flags was sinnvolles machen + */ +ssize_t send(int socket, const void *buffer, size_t length, int flags) +{ + return write(socket, buffer, length); +} -- 1.6.0.2 From toni at tyndur.org Mon Apr 13 21:15:44 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 21:15:44 +0200 Subject: [tyndur-devel] [PATCH v2 1/4] libc: POSIX: Socket-Funktionen In-Reply-To: <1239649668-5016-2-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> <1239649668-5016-2-git-send-email-kevin@tyndur.org> Message-ID: <20090413191544.GJ21931@einstein.produktiv.lan> On Mon, Apr 13 21:07, Kevin Wolf wrote: > + libc: POSIX: Socket-Funktionen Sieht besser aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 21:19:51 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 21:19:51 +0200 Subject: [tyndur-devel] [PATCH v2 2/4] libc: POSIX: arpa/inet.h In-Reply-To: <1239649668-5016-3-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> <1239649668-5016-3-git-send-email-kevin@tyndur.org> Message-ID: <20090413191951.GK21931@einstein.produktiv.lan> On Mon, Apr 13 21:07, Kevin Wolf wrote: > ! libc: htons() und aehnliches gehoeren laut Standard nach arpa/inet.h und > nicht nach netinet/in.h Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 21:29:18 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 21:29:18 +0200 Subject: [tyndur-devel] [PATCH v2 3/4] libc: POSIX: gethostbyname() In-Reply-To: <1239649668-5016-4-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> <1239649668-5016-4-git-send-email-kevin@tyndur.org> Message-ID: <20090413192918.GL21931@einstein.produktiv.lan> On Mon, Apr 13 21:07, Kevin Wolf wrote: > + libc: POSIX: gethostbyname() Sieht gut aus -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Apr 13 22:10:41 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 13 Apr 2009 22:10:41 +0200 Subject: [tyndur-devel] [PATCH v2 4/4] libc: POSIX: IP-Adressen-Umwandlung String/Integer In-Reply-To: <1239649668-5016-5-git-send-email-kevin@tyndur.org> References: <1239649668-5016-1-git-send-email-kevin@tyndur.org> <1239649668-5016-5-git-send-email-kevin@tyndur.org> Message-ID: <20090413201041.GA22528@einstein.produktiv.lan> On Mon, Apr 13 21:07, Kevin Wolf wrote: > + libc: POSIX: inet_aton() / inet_ntoa() So gefällt mir das schon besser. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Apr 18 13:05:49 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Apr 2009 13:05:49 +0200 Subject: [tyndur-devel] [PATCH 2/2] libc: key_mask fuer Baeume In-Reply-To: <1240052749-5565-1-git-send-email-kevin@tyndur.org> References: <1240052749-5565-1-git-send-email-kevin@tyndur.org> Message-ID: <1240052749-5565-3-git-send-email-kevin@tyndur.org> + libc: Nicht alle 64 Bit des Schluessels muessen als Schluessel benutzt werden, sondern koennen z.B. Flags enthalten. Das neue Feld key_mask filtert dann raus, was nicht zum Schluessel gehoert --- src/include/collections.h | 1 + src/lib/collections/tree.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/src/include/collections.h b/src/include/collections.h index 2593e3a..0ecb321 100644 --- a/src/include/collections.h +++ b/src/include/collections.h @@ -81,6 +81,7 @@ typedef struct { struct tree_item* root; size_t tree_item_offset; size_t sort_key_offset; + uint64_t key_mask; } tree_t; /** diff --git a/src/lib/collections/tree.c b/src/lib/collections/tree.c index 01c0a71..87dbcea 100644 --- a/src/lib/collections/tree.c +++ b/src/lib/collections/tree.c @@ -53,7 +53,10 @@ static inline struct tree_item* to_tree_item(tree_t* tree, void* node) { * Gibt den Schluessel eines Objekts zurueck */ static inline uint64_t get_key(tree_t* tree, struct tree_item* item) { - return *(uint64_t*)((char*) to_node(tree, item) + tree->sort_key_offset); + uint64_t res; + + res = *(uint64_t*)((char*) to_node(tree, item) + tree->sort_key_offset); + return res & tree->key_mask; } /** @@ -66,6 +69,7 @@ void tree_do_init(tree_t* tree, memset(tree, 0, sizeof(*tree)); tree->tree_item_offset = tree_item_offset; tree->sort_key_offset = sort_key_offset; + tree->key_mask = (uint64_t) -1; } /** -- 1.6.0.2 From kevin at tyndur.org Sat Apr 18 13:05:47 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Apr 2009 13:05:47 +0200 Subject: [tyndur-devel] [PATCH 0/2] libc: Bessere Baeume Message-ID: <1240052749-5565-1-git-send-email-kevin@tyndur.org> Zwei Patches gegen die libc aus dem LostIOv2-Branch, die eigentlich schonmal reinkoennten. Kevin Wolf (2): libc: Baeume initialisieren ohne malloc libc: key_mask fuer Baeume src/include/collections.h | 20 ++++++++++++++++++++ src/lib/collections/tree.c | 24 ++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) From kevin at tyndur.org Sat Apr 18 13:05:48 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Apr 2009 13:05:48 +0200 Subject: [tyndur-devel] [PATCH 1/2] libc: Baeume initialisieren ohne malloc In-Reply-To: <1240052749-5565-1-git-send-email-kevin@tyndur.org> References: <1240052749-5565-1-git-send-email-kevin@tyndur.org> Message-ID: <1240052749-5565-2-git-send-email-kevin@tyndur.org> + libc: tree_init() fuer nicht dynamisch allozierte Baeume --- src/include/collections.h | 19 +++++++++++++++++++ src/lib/collections/tree.c | 18 +++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/include/collections.h b/src/include/collections.h index df9fa2a..2593e3a 100644 --- a/src/include/collections.h +++ b/src/include/collections.h @@ -100,6 +100,25 @@ typedef struct { tree_t* tree_do_create(size_t tree_item_offset, size_t sort_key_offset); /** + * Initialisiert einen neuen AVL-Baum. Dies ist eine Alternative zu + * tree_create, wenn der Baum nicht dynamisch alloziert werden soll, sondern + * z.B. fest in einer Struktur eingebettet ist. + * + * @param type Datentyp der Objekte im Baum + * @param tree_item Name des tree_item-Felds in der Struktur der Objekte + * @param sort_key Name des Schluessels in der Struktur der Objekte + */ +#define tree_init(tree, type, tree_item, sort_key) \ + tree_do_init(tree, offsetof(type, tree_item), offsetof(type, sort_key)) + +/** + * Initialisiert einen AVL-Baum. Nicht direkt verwenden, tree_do_init ist das + * Mittel der Wahl. + */ +void tree_do_init(tree_t* tree, + size_t tree_item_offset, size_t sort_key_offset); + +/** * Gibt einen AVL-Baum frei. Zu beachten ist, dass keiner seiner Knoten * freigegeben wird, da ein Knoten immer noch ueber eine andere Datenstruktur * erreichbar sein koennte. diff --git a/src/lib/collections/tree.c b/src/lib/collections/tree.c index 40fc47d..01c0a71 100644 --- a/src/lib/collections/tree.c +++ b/src/lib/collections/tree.c @@ -56,6 +56,17 @@ static inline uint64_t get_key(tree_t* tree, struct tree_item* item) { return *(uint64_t*)((char*) to_node(tree, item) + tree->sort_key_offset); } +/** + * Initilaisiert einen neuen AVL-Baum. Nicht direkt verwenden, tree_create ist + * das Mittel der Wahl. + */ +void tree_do_init(tree_t* tree, + size_t tree_item_offset, size_t sort_key_offset) +{ + memset(tree, 0, sizeof(*tree)); + tree->tree_item_offset = tree_item_offset; + tree->sort_key_offset = sort_key_offset; +} /** * Erzeugt einen neuen AVL-Baum. Nicht direkt verwenden, tree_create ist das @@ -63,11 +74,8 @@ static inline uint64_t get_key(tree_t* tree, struct tree_item* item) { */ tree_t* tree_do_create(size_t tree_item_offset, size_t sort_key_offset) { - tree_t* tree = calloc(1, sizeof(*tree)); - - tree->tree_item_offset = tree_item_offset; - tree->sort_key_offset = sort_key_offset; - + tree_t* tree = malloc(sizeof(*tree)); + tree_do_init(tree, tree_item_offset, sort_key_offset); return tree; } -- 1.6.0.2 From kevin at tyndur.org Sat Apr 18 13:07:52 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Apr 2009 13:07:52 +0200 Subject: [tyndur-devel] [PATCH] kernel2: cmdline fuer den Initprozess Message-ID: <1240052872-5792-1-git-send-email-kevin@tyndur.org> ! kernel2: Wenn der Initprozess eine cmdline hat, funktionieren auch in der fruehen Bootphase die Exceptionmeldungen --- src/kernel2/src/init.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/kernel2/src/init.c b/src/kernel2/src/init.c index e0f2bfb..e169fac 100644 --- a/src/kernel2/src/init.c +++ b/src/kernel2/src/init.c @@ -54,7 +54,9 @@ struct multiboot_info multiboot_info; #define init_context (&init_thread.process->context) pm_thread_t init_thread; -pm_process_t init_process; +pm_process_t init_process = { + .cmdline = "(Kernel)", +}; lock_t init_lock = 0; -- 1.6.0.2 From kevin at tyndur.org Sat Apr 18 13:44:49 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Apr 2009 13:44:49 +0200 Subject: [tyndur-devel] [PATCH] Shell: Neuer Befehl kill Message-ID: <1240055089-16991-1-git-send-email-kevin@tyndur.org> + shell: kill-Befehl (sendet SIGTERM) --- src/modules/c/shell/cmds/kill.c | 78 +++++++++++++++++++++++++++++++++++++++ src/modules/c/shell/commmands.c | 1 + src/modules/c/shell/shell.c | 1 + src/modules/c/shell/shell.h | 1 + 4 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/shell/cmds/kill.c diff --git a/src/modules/c/shell/cmds/kill.c b/src/modules/c/shell/cmds/kill.c new file mode 100644 index 0000000..97e5258 --- /dev/null +++ b/src/modules/c/shell/cmds/kill.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include + +static void kill_display_usage(void); + +#ifdef CONFIG_SHELL_BUILTIN_ONLY + int shell_command_kill(int argc, char* argv[], const char* args) +#else + int main(int argc, char* argv[]) +#endif +{ + int ret; + + if (argc != 2) { + kill_display_usage(); + return -1; + } + + pid_t pid = atoi(argv[1]); + if (!pid) { + printf("Prozess %d nicht gefunden\n", pid); + return EXIT_FAILURE; + } + + ret = kill(pid, SIGTERM); + if (ret < 0) { + printf("Konnte Prozess %d nicht beenden: %d (%s)\n", pid, errno, + strerror(errno)); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +static void kill_display_usage() +{ + puts("\nAufruf: kill "); +} + diff --git a/src/modules/c/shell/commmands.c b/src/modules/c/shell/commmands.c index bc41bba..25d0cb7 100644 --- a/src/modules/c/shell/commmands.c +++ b/src/modules/c/shell/commmands.c @@ -163,6 +163,7 @@ int shell_command_help(int argc, char* argv[], const char* args) puts(" free Zeigt den Speicherverbrauch des Systems an"); puts(" ps Zeigt eine Liste mit allen Prozessen an"); puts(" pstree Zeigt die Prozesshierarchie als Baum an"); + puts(" kill Beendet den Prozess "); puts(" dbg_st Zeigt einen Stack Backtrace des Prozesses " " an"); diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index 9470fe5..3f1acf5 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -83,6 +83,7 @@ shell_command_t shell_commands[] = { {"date", &shell_command_date}, {"echo", &shell_command_echo}, {"free", &shell_command_free}, + {"kill", &shell_command_kill}, {"ls", &shell_command_ls}, {"irc", &shell_command_irc}, {"mkdir", &shell_command_mkdir}, diff --git a/src/modules/c/shell/shell.h b/src/modules/c/shell/shell.h index 53a757d..b715ed3 100644 --- a/src/modules/c/shell/shell.h +++ b/src/modules/c/shell/shell.h @@ -68,6 +68,7 @@ int shell_command_clear(int argc, char* argv[], const char* args); int shell_command_echo(int argc, char* argv[], const char* args); int shell_command_irc(int argc, char* argv[], const char* args); int shell_command_free(int argc, char* argv[], const char* args); + int shell_command_kill(int argc, char* argv[], const char* args); int shell_command_ls(int argc, char* argv[], const char* args); int shell_command_mkdir(int argc, char* argv[], const char* args); int shell_command_pipe(int argc, char* argv[], const char* args); -- 1.6.0.2 From toni at tyndur.org Sat Apr 18 14:21:18 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 18 Apr 2009 14:21:18 +0200 Subject: [tyndur-devel] [PATCH] Shell: Neuer Befehl kill In-Reply-To: <1240055089-16991-1-git-send-email-kevin@tyndur.org> References: <1240055089-16991-1-git-send-email-kevin@tyndur.org> Message-ID: <20090418122118.GA20668@einstein.produktiv.lan> On Sat, Apr 18 13:44, Kevin Wolf wrote: > + shell: kill-Befehl (sendet SIGTERM) Sieht gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 18 14:39:20 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 18 Apr 2009 14:39:20 +0200 Subject: [tyndur-devel] [PATCH] kernel2: cmdline fuer den Initprozess In-Reply-To: <1240052872-5792-1-git-send-email-kevin@tyndur.org> References: <1240052872-5792-1-git-send-email-kevin@tyndur.org> Message-ID: <20090418123920.GB20668@einstein.produktiv.lan> On Sat, Apr 18 13:07, Kevin Wolf wrote: > ! kernel2: Wenn der Initprozess eine cmdline hat, funktionieren auch in > der fruehen Bootphase die Exceptionmeldungen Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Apr 18 15:07:10 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Apr 2009 15:07:10 +0200 Subject: [tyndur-devel] [PATCH] kernel: RPC zu unbekanntem Prozess tolerieren Message-ID: <1240060030-3059-1-git-send-email-kevin@tyndur.org> * kernel: Wenn jemand zu einem unbekannten Prozess einen RPC machen will, sollte man ihm das einfach sagen statt ihn abzuschiessen. --- src/kernel/src/syscall.c | 6 ++-- src/modules/include/syscall.h | 3 +- src/modules/lib/syscalls/rpc.c | 41 +++++++++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/kernel/src/syscall.c b/src/kernel/src/syscall.c index 2ee793d..87911fa 100644 --- a/src/kernel/src/syscall.c +++ b/src/kernel/src/syscall.c @@ -34,6 +34,7 @@ */ #include +#include #include "console.h" #include "syscall.h" @@ -668,8 +669,7 @@ void syscall(struct int_stack_frame ** esp) struct task* callee = get_task(callee_pid); if (!callee) { - abort_task("SYSCALL_FASTRPC: RPC zu unbekanntem Prozess %d)", - callee_pid); + isf->eax = -ESRCH; break; } @@ -693,7 +693,7 @@ void syscall(struct int_stack_frame ** esp) )) { schedule_to_task(callee, (dword*) esp); } else { - isf->eax = -1; + isf->eax = -EAGAIN; schedule((dword*)esp); } break; diff --git a/src/modules/include/syscall.h b/src/modules/include/syscall.h index e22b0df..6bb3593 100644 --- a/src/modules/include/syscall.h +++ b/src/modules/include/syscall.h @@ -72,7 +72,8 @@ void set_rpc_handler(void (*rpc_handler)(void)); void add_intr_handler(dword intr); void rpc(pid_t pid); -void send_message(pid_t pid, dword function, dword correlation_id, dword len, char* data); +int send_message(pid_t pid, dword function, dword correlation_id, + dword len, char* data); void wait_for_rpc(void); void v_and_wait_for_rpc(void); diff --git a/src/modules/lib/syscalls/rpc.c b/src/modules/lib/syscalls/rpc.c index 72d4bbc..2a07352 100644 --- a/src/modules/lib/syscalls/rpc.c +++ b/src/modules/lib/syscalls/rpc.c @@ -1,5 +1,34 @@ -#include "types.h" -#include "syscall.h" +/* + * Copyright (c) 2006-2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include void rpc(dword pid) { @@ -16,10 +45,10 @@ void rpc(dword pid) } while (result != 0); } -void send_message +int send_message (dword pid, dword function, dword correlation_id, dword len, char* data) { - dword result = 0; + int32_t result = 0; // Auf die Variable wird zwar sonst nirgends schreibend zugegriffen, aber // das volatile ist noetig, weil gcc sonst der Meinung ist, der Arrayinhalt @@ -42,6 +71,8 @@ void send_message : "i" (SYSCALL_FASTRPC), "g" (pid), "i" (0x8), "g" (metadata), "g" (len), "g" (data), "0" (result)); - } while (result != 0); + } while (result == -EAGAIN); + + return result; } -- 1.6.0.2 From kevin at tyndur.org Sat Apr 18 21:03:55 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Apr 2009 21:03:55 +0200 Subject: [tyndur-devel] [PATCH] lpt: Section spezifizieren Message-ID: <1240081435-24702-1-git-send-email-kevin@tyndur.org> + lpt: Wenn mit lpt get/reget ein Paket aus einer anderen Section als bin installiert werden soll, wird die Section durch Schraegstrich getrennt angehaengt (z.B. libgcc/lib) --- src/modules/pas/lpt/lpt.pas | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/src/modules/pas/lpt/lpt.pas b/src/modules/pas/lpt/lpt.pas index 62db55f..10c3403 100644 --- a/src/modules/pas/lpt/lpt.pas +++ b/src/modules/pas/lpt/lpt.pas @@ -256,7 +256,16 @@ begin ReadPkglists(pkgset); - section := 'bin'; + // Parameter hat die Form Paketname/Section. Wenn keine Section angegeben + // ist, wird bin als Default benutzt. + i := Pos('/', pkgname); + if i > 0 then begin + section := Copy(pkgname, i + 1, Length(pkgname)); + pkgname := Copy(pkgname, 1, i - 1); + end else begin + section := 'bin'; + end; + version := pkgset.GetCurrentVersion(pkgname, section); if version = nil then begin -- 1.6.0.2 From toni at tyndur.org Sat Apr 18 21:06:41 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 18 Apr 2009 21:06:41 +0200 Subject: [tyndur-devel] [PATCH] lpt: Section spezifizieren In-Reply-To: <1240081435-24702-1-git-send-email-kevin@tyndur.org> References: <1240081435-24702-1-git-send-email-kevin@tyndur.org> Message-ID: <20090418190641.GD20668@einstein.produktiv.lan> On Sat, Apr 18 21:03, Kevin Wolf wrote: > + lpt: Wenn mit lpt get/reget ein Paket aus einer anderen Section als > bin installiert werden soll, wird die Section durch Schraegstrich > getrennt angehaengt (z.B. libgcc/lib) Ack -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 18 21:14:31 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 18 Apr 2009 21:14:31 +0200 Subject: [tyndur-devel] [PATCH 1/2] libc: Baeume initialisieren ohne malloc In-Reply-To: <1240052749-5565-2-git-send-email-kevin@tyndur.org> References: <1240052749-5565-1-git-send-email-kevin@tyndur.org> <1240052749-5565-2-git-send-email-kevin@tyndur.org> Message-ID: <20090418191431.GE20668@einstein.produktiv.lan> On Sat, Apr 18 13:05, Kevin Wolf wrote: > + libc: tree_init() fuer nicht dynamisch allozierte Baeume > --- > src/include/collections.h | 19 +++++++++++++++++++ > src/lib/collections/tree.c | 18 +++++++++++++----- > 2 files changed, 32 insertions(+), 5 deletions(-) > > diff --git a/src/include/collections.h b/src/include/collections.h > index df9fa2a..2593e3a 100644 > --- a/src/include/collections.h > +++ b/src/include/collections.h > @@ -100,6 +100,25 @@ typedef struct { > tree_t* tree_do_create(size_t tree_item_offset, size_t sort_key_offset); > > /** > + * Initialisiert einen neuen AVL-Baum. Dies ist eine Alternative zu > + * tree_create, wenn der Baum nicht dynamisch alloziert werden soll, sondern > + * z.B. fest in einer Struktur eingebettet ist. > + * Hier könnte man ggf. noch tree ergänzen in der Parameterliste > + * @param type Datentyp der Objekte im Baum > + * @param tree_item Name des tree_item-Felds in der Struktur der Objekte > + * @param sort_key Name des Schluessels in der Struktur der Objekte > + */ > +#define tree_init(tree, type, tree_item, sort_key) \ > + tree_do_init(tree, offsetof(type, tree_item), offsetof(type, sort_key)) > + > +/** > + * Initialisiert einen AVL-Baum. Nicht direkt verwenden, tree_do_init ist das > + * Mittel der Wahl. > + */ > +void tree_do_init(tree_t* tree, > + size_t tree_item_offset, size_t sort_key_offset); > + > +/** > * Gibt einen AVL-Baum frei. Zu beachten ist, dass keiner seiner Knoten > * freigegeben wird, da ein Knoten immer noch ueber eine andere Datenstruktur > * erreichbar sein koennte. Sonst sieht das gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 18 21:18:55 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 18 Apr 2009 21:18:55 +0200 Subject: [tyndur-devel] [PATCH 2/2] libc: key_mask fuer Baeume In-Reply-To: <1240052749-5565-3-git-send-email-kevin@tyndur.org> References: <1240052749-5565-1-git-send-email-kevin@tyndur.org> <1240052749-5565-3-git-send-email-kevin@tyndur.org> Message-ID: <20090418191855.GF20668@einstein.produktiv.lan> On Sat, Apr 18 13:05, Kevin Wolf wrote: > + libc: Nicht alle 64 Bit des Schluessels muessen als Schluessel benutzt > werden, sondern koennen z.B. Flags enthalten. Das neue Feld key_mask > filtert dann raus, was nicht zum Schluessel gehoert > --- > src/include/collections.h | 1 + > src/lib/collections/tree.c | 6 +++++- > 2 files changed, 6 insertions(+), 1 deletions(-) > > diff --git a/src/include/collections.h b/src/include/collections.h > index 2593e3a..0ecb321 100644 > --- a/src/include/collections.h > +++ b/src/include/collections.h > @@ -81,6 +81,7 @@ typedef struct { > struct tree_item* root; > size_t tree_item_offset; > size_t sort_key_offset; Wenn das Feld schon zum selber befüllen da ist, sollte da vielleicht noch ein Kommentar hin, der auch sagt, dass man das nicht ändern will wenn was drin ist... > + uint64_t key_mask; > } tree_t; > > /** Sonst kann das rein. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 18 21:20:44 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 18 Apr 2009 21:20:44 +0200 Subject: [tyndur-devel] [PATCH] kernel: RPC zu unbekanntem Prozess tolerieren In-Reply-To: <1240060030-3059-1-git-send-email-kevin@tyndur.org> References: <1240060030-3059-1-git-send-email-kevin@tyndur.org> Message-ID: <20090418192043.GG20668@einstein.produktiv.lan> On Sat, Apr 18 15:07, Kevin Wolf wrote: > * kernel: Wenn jemand zu einem unbekannten Prozess einen RPC machen > will, sollte man ihm das einfach sagen statt ihn abzuschiessen. Auch hier wäre ich sicher nicht böse, wenn diese Rückgabewerte irgendwo erklärt würden... ;-) Aber von mir aus rein damit. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sun Apr 19 00:55:57 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 19 Apr 2009 00:55:57 +0200 Subject: [tyndur-devel] [PATCH 2/4] Pascal-RTL: Unit tyndur In-Reply-To: <1240095359-29201-1-git-send-email-kevin@tyndur.org> References: <1240095359-29201-1-git-send-email-kevin@tyndur.org> Message-ID: <1240095359-29201-3-git-send-email-kevin@tyndur.org> + Pascal-RTL: tyndur: ReadUnicodeChar --- src/modules/pas/kedit/kedit.pas | 4 ++- src/modules/pas/lib/tyndur/Makefile.all | 1 + src/modules/pas/lib/tyndur/tyndur.pas | 36 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletions(-) create mode 100644 src/modules/pas/lib/tyndur/Makefile.all create mode 100644 src/modules/pas/lib/tyndur/tyndur.pas diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas index 4409f7d..473c218 100644 --- a/src/modules/pas/kedit/kedit.pas +++ b/src/modules/pas/kedit/kedit.pas @@ -1,7 +1,9 @@ program KEdit; {$H+} -uses crt, sysutils, kedit_tui, kedit_buf, kedit_input, kedit_main; +uses + crt, sysutils, tyndur, + kedit_tui, kedit_buf, kedit_input, kedit_main; type textfile = text; diff --git a/src/modules/pas/lib/tyndur/Makefile.all b/src/modules/pas/lib/tyndur/Makefile.all new file mode 100644 index 0000000..aacb99c --- /dev/null +++ b/src/modules/pas/lib/tyndur/Makefile.all @@ -0,0 +1 @@ +cp libptyndur.a tyndur.ppu ../units diff --git a/src/modules/pas/lib/tyndur/tyndur.pas b/src/modules/pas/lib/tyndur/tyndur.pas new file mode 100644 index 0000000..5cffdad --- /dev/null +++ b/src/modules/pas/lib/tyndur/tyndur.pas @@ -0,0 +1,36 @@ +unit tyndur; + +interface + + function ReadUnicodeChar: UnicodeChar; + + +implementation + + uses crt; + + function ReadUnicodeChar: UnicodeChar; + var + keys: Array [1..5] of char; + pkeys: PChar; + + res: Array [1..2] of UnicodeChar; + pres: PUnicodeChar; + + ret: integer; + i: integer; + begin + pkeys := @keys[1]; + pres := @res[1]; + for i := 1 to 4 do begin + keys[i] := readkey; + keys[i+1] := #0; + ret := Utf8ToUnicode(pres, 2, pkeys, i); + if ret >= 0 then begin + break; + end; + end; + exit(res[1]); + end; + +end. -- 1.6.0.2 From kevin at tyndur.org Sun Apr 19 00:55:59 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 19 Apr 2009 00:55:59 +0200 Subject: [tyndur-devel] [PATCH 4/4] kedit: UTF-8-Unterstuetzung In-Reply-To: <1240095359-29201-1-git-send-email-kevin@tyndur.org> References: <1240095359-29201-1-git-send-email-kevin@tyndur.org> Message-ID: <1240095359-29201-5-git-send-email-kevin@tyndur.org> + kedit: Unterstuetzung fuer UTF-8-Text --- src/modules/pas/kedit/kedit.pas | 4 ++-- src/modules/pas/kedit/kedit_main.pas | 8 +++++--- src/modules/pas/kedit/kedit_tui.pas | 9 ++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas index 473c218..71a5fcd 100644 --- a/src/modules/pas/kedit/kedit.pas +++ b/src/modules/pas/kedit/kedit.pas @@ -87,10 +87,10 @@ procedure Edit; procedure DoInput; var - key: char; + key: UnicodeChar; begin with state do begin - key:=readkey; + key := ReadUnicodeChar; case key of #27: { VT100-Escapesequenz } begin diff --git a/src/modules/pas/kedit/kedit_main.pas b/src/modules/pas/kedit/kedit_main.pas index 486841b..8e2948d 100644 --- a/src/modules/pas/kedit/kedit_main.pas +++ b/src/modules/pas/kedit/kedit_main.pas @@ -7,7 +7,7 @@ const MaxColumns = 255; type - type_text = Array [1..MaxLines] of AnsiString; + type_text = Array [1..MaxLines] of UnicodeString; // Beschreibt einen offenen Puffer kedit_state = record @@ -125,7 +125,7 @@ begin for j := 1 to emptylines do begin WriteLn(sfile); end; - WriteLn(sfile,text^[i]); + WriteLn(sfile, Utf8Encode(text^[i])); emptylines:=0; end; end; @@ -140,6 +140,7 @@ var lfile: textfile; cnt: longint; i: integer; attr: word; + s: String; begin if loadname = '' then begin Textbackground(1); @@ -178,7 +179,8 @@ begin cnt := 0; while not(eof(lfile)) do begin Inc(cnt); - ReadLn(lfile, text^[cnt]); + ReadLn(lfile, s); + text^[cnt] := Utf8Decode(s); end; Close(lfile); diff --git a/src/modules/pas/kedit/kedit_tui.pas b/src/modules/pas/kedit/kedit_tui.pas index 2d0f2e8..8067ed1 100644 --- a/src/modules/pas/kedit/kedit_tui.pas +++ b/src/modules/pas/kedit/kedit_tui.pas @@ -252,7 +252,7 @@ begin screenY := 1 + y - scrolly; GotoXY(1, screenY); - Write(Copy(text^[y], 1+scrollx, 79)); + Write(Utf8Encode(Copy(text^[y], 1+scrollx, 79))); Write(Space(79 - Length(Copy(text^[y], 1+scrollx, 79)))); GotoXY(CursX - ScrollX, 1 + CursY - ScrollY); end; @@ -267,6 +267,7 @@ var syntax_state: longint; syntax_chg: TSyntaxChange; fromCol, toCol: integer; + s: UnicodeString; begin // Titelleiste DrawTitleBar(state); @@ -277,7 +278,8 @@ begin lastVisible := TextLines + state^.scrolly; if not highlight then begin for i := firstVisible to lastVisible do begin - Write(Copy(state^.text^[i], 1 + state^.scrollx, 80)); + s := Copy(state^.text^[i], 1 + state^.scrollx, 80); + Write(Utf8Encode(s)); Write(Space(80-Length(Copy(state^.text^[i],1+state^.scrollx,80)))); end; end else begin @@ -316,7 +318,8 @@ begin end; if fromCol <= toCol then begin - Write(Copy(state^.text^[i], fromCol, toCol - fromCol + 1)); + s := Copy(state^.text^[i], fromCol, toCol - fromCol + 1); + Write(Utf8Encode(s)); end; if syntax_chg.posY > fromCol then begin -- 1.6.0.2 From kevin at tyndur.org Sun Apr 19 00:55:58 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 19 Apr 2009 00:55:58 +0200 Subject: [tyndur-devel] [PATCH 3/4] kirc: Unterstuetzung fuer UTF-8-Eingabe In-Reply-To: <1240095359-29201-1-git-send-email-kevin@tyndur.org> References: <1240095359-29201-1-git-send-email-kevin@tyndur.org> Message-ID: <1240095359-29201-4-git-send-email-kevin@tyndur.org> + kirc: Unterstuetzung fuer UTF-8-Eingabe (vom Netzwerk kommender Text wird weiterhin so an vterm weitergeleitet wie er ist; automagische Zeichensatzerkennung sollte aber relativ leicht machbar sein) --- src/modules/pas/kirc/ircwindow.pas | 45 +++++++++++++++++++++-------------- 1 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/modules/pas/kirc/ircwindow.pas b/src/modules/pas/kirc/ircwindow.pas index 16d8e7b..4060708 100644 --- a/src/modules/pas/kirc/ircwindow.pas +++ b/src/modules/pas/kirc/ircwindow.pas @@ -15,7 +15,7 @@ type fTitle: String; fCommandHandler: TIRCCommandHandler; - outBuffer: string; + outBuffer: UnicodeString; posy: byte; inBuffer: array [0..BUFFER_LINES - 1] of record @@ -28,7 +28,7 @@ type procedure ScrollLines(num: integer); procedure SetTitle(title: String); - function AutoCompleteOutBuffer(): String; + function AutoCompleteOutBuffer(): UnicodeString; public constructor Init(title: String); @@ -42,7 +42,7 @@ type end; implementation -uses sysutils, crt; +uses sysutils, crt, tyndur; constructor TIRCWindow.Init(title: String); var @@ -126,7 +126,7 @@ begin Write(StringOfChar(' ' , 80)); GotoXY(1, 24); TextColor(7); - Write(outBuffer); + Write(Utf8Encode(outBuffer)); GotoXY(1, 24); end; @@ -184,8 +184,8 @@ end; procedure TIRCWindow.CheckInput; var - c: char; - autoCompletion, curToken: String; + c: UnicodeChar; + autoCompletion, curToken: UnicodeString; cursorpos : integer; begin if not keypressed then begin @@ -195,7 +195,7 @@ begin TextColor(7); TextBackground(1); - c := readkey; + c := ReadUnicodeChar; case c of #8: if Length(outBuffer) > 0 then begin if length(outBuffer) < 80 then begin @@ -206,7 +206,7 @@ begin end else begin SetLength(outBuffer, Length(outBuffer) - 1); GotoXY(1, 24); - Write(Copy(outBuffer, length(outBuffer) - 78, 79)); + Write(Utf8Encode(Copy(outBuffer, length(outBuffer) - 78, 79))); end; end; #9: begin @@ -214,7 +214,7 @@ begin if autoCompletion <> '' then begin outBuffer := outBuffer + autoCompletion + ' '; GotoXY(1, 24); - Write(Copy(outBuffer, length(outBuffer) - 78, 79)); + Write(Utf8Encode(Copy(outBuffer, length(outBuffer) - 78, 79))); end; end; #10: ; @@ -227,17 +227,17 @@ begin if length(outBuffer) < 80 then begin GotoXY(cursorPos, 24); - Write(Copy(outBuffer, cursorPos, length(outBuffer) - cursorPos + 1)); + Write(Utf8Encode(Copy(outBuffer, cursorPos, length(outBuffer) - cursorPos + 1))); end else begin GotoXY(1, 24); - Write(Copy(outBuffer, length(outBuffer) - 78, 79)); + Write(Utf8Encode(Copy(outBuffer, length(outBuffer) - 78, 79))); end; end; end; if c = #10 then begin if fCommandHandler <> nil then begin - fCommandHandler(outBuffer); + fCommandHandler(Utf8Encode(outBuffer)); TextColor(7); TextBackground(1); @@ -263,19 +263,21 @@ begin end else begin autoCompletion := ''; end; - Write(Copy(autoCompletion, 1, 79), StringOfChar(' ', 79 - length(autoCompletion))); - + Write(Utf8Encode(Copy(autoCompletion, 1, 79))); + Write(StringOfChar(' ', 79 - length(autoCompletion))); + TextBackground(1); TextColor(7); GotoXY(length(outBuffer) + 1, 24); end; -function TIRCWindow.AutoCompleteOutBuffer(): String; +function TIRCWindow.AutoCompleteOutBuffer(): UnicodeString; var - completionToken, curToken: String; + completionToken, curToken: UnicodeString; spacePos: integer; curInBufferLine: integer; + s: UnicodeString; i: integer; begin @@ -287,8 +289,15 @@ begin repeat curToken := ''; for i := 1 to length(inBuffer[curInBufferLine].s) do begin - if inBuffer[curInBufferLine].s[i] in ['A' .. 'Z', 'a' .. 'z', '0' .. '9'] then begin - curToken := curToken + inBuffer[curInBufferLine].s[i]; + s := Utf8Decode(inBuffer[curInBufferLine].s); + if s = '' then begin + continue; + end; + if s[i] in ['A' .. 'Z', 'a' .. 'z', '0' .. '9'] then begin + curToken := curToken + s[i]; + end else if Ord(s[i]) > 128 then begin + // Nicht-ASCII-Zeichen sind wahrscheinlich auch Buchstaben + curToken := curToken + s[i]; end else begin // TODO CompareText benutzen if Copy(curToken, 1, length(completionToken)) = completionToken then begin -- 1.6.0.2 From kevin at tyndur.org Sun Apr 19 00:55:56 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 19 Apr 2009 00:55:56 +0200 Subject: [tyndur-devel] [PATCH 1/4] Pascal-RTL: Unicode-Strings initialisieren In-Reply-To: <1240095359-29201-1-git-send-email-kevin@tyndur.org> References: <1240095359-29201-1-git-send-email-kevin@tyndur.org> Message-ID: <1240095359-29201-2-git-send-email-kevin@tyndur.org> + Pascal-RTL: system initialisiert den WideStringManager --- src/modules/pas/lib/rtl/system.pas | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/src/modules/pas/lib/rtl/system.pas b/src/modules/pas/lib/rtl/system.pas index 136c886..b9e1f6f 100644 --- a/src/modules/pas/lib/rtl/system.pas +++ b/src/modules/pas/lib/rtl/system.pas @@ -269,4 +269,6 @@ Begin // IOError initialisieren InOutRes := 0; + + InitUnicodeStringManager; End. -- 1.6.0.2 From kevin at tyndur.org Sun Apr 19 00:55:55 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 19 Apr 2009 00:55:55 +0200 Subject: [tyndur-devel] [PATCH 0/4] UTF-8 fuer Pascalprogramme Message-ID: <1240095359-29201-1-git-send-email-kevin@tyndur.org> Diese Patchserie erweitert zunaechst die Pascal-RTL um grundlegende Unterstuetzung fuer UTF-8 und passt anschliessend kirc und kedit an. Kevin Wolf (4): Pascal-RTL: Unicode-Strings initialisieren Pascal-RTL: Unit tyndur kirc: Unterstuetzung fuer UTF-8-Eingabe kedit: UTF-8-Unterstuetzung src/modules/pas/kedit/kedit.pas | 8 +++-- src/modules/pas/kedit/kedit_main.pas | 8 +++-- src/modules/pas/kedit/kedit_tui.pas | 9 ++++-- src/modules/pas/kirc/ircwindow.pas | 45 ++++++++++++++++++------------ src/modules/pas/lib/rtl/system.pas | 2 + src/modules/pas/lib/tyndur/Makefile.all | 1 + src/modules/pas/lib/tyndur/tyndur.pas | 36 ++++++++++++++++++++++++ 7 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 src/modules/pas/lib/tyndur/Makefile.all create mode 100644 src/modules/pas/lib/tyndur/tyndur.pas From kevin at tyndur.org Wed Apr 22 20:18:17 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 22 Apr 2009 20:18:17 +0200 Subject: [tyndur-devel] [PATCH 5/5] libc: POSIX: uname() In-Reply-To: <1240424297-4863-1-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> Message-ID: <1240424297-4863-6-git-send-email-kevin@tyndur.org> + libc: POSIX: uname() --- src/include/lost/config.h | 9 ++++++ src/modules/include/sys/utsname.h | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/sys/utsname.h diff --git a/src/include/lost/config.h b/src/include/lost/config.h index 67cf7cc..25794af 100644 --- a/src/include/lost/config.h +++ b/src/include/lost/config.h @@ -74,5 +74,14 @@ #define CONFIG_LIBC_NO_STUBS +#define TYNDUR_VERSION "0.2.1" +#if CONFIG_ARCH == ARCH_I386 + #define TYNDUR_ARCH "i386" +#elif CONFIG_ARCH == ARCH_AMD64 + #define TYNDUR_ARCH "amd64" +#else + #error Unbekannte Architektur +#endif + #endif // _CONFIG_H_ diff --git a/src/modules/include/sys/utsname.h b/src/modules/include/sys/utsname.h new file mode 100644 index 0000000..7b53d53 --- /dev/null +++ b/src/modules/include/sys/utsname.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SYS_UTSNAME_H_ +#define _SYS_UTSNAME_H_ + +#include + +struct utsname { + char sysname[32]; + char nodename[32]; + char release[32]; + char version[32]; + char machine[32]; +}; + +static int uname(struct utsname* utsname) +{ + strcpy(utsname->sysname, "tyndur"); + strcpy(utsname->nodename, "tyndur"); + strcpy(utsname->release, "Gothmog"); + strcpy(utsname->version, TYNDUR_VERSION); + strcpy(utsname->machine, TYNDUR_ARCH); + + return 0; +} + +#endif -- 1.6.0.2 From kevin at tyndur.org Wed Apr 22 20:18:12 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 22 Apr 2009 20:18:12 +0200 Subject: [tyndur-devel] [PATCH 0/5] libc: Noch'n Stueck POSIX Message-ID: <1240424297-4863-1-git-send-email-kevin@tyndur.org> Hier mal wieder ein paar bei Portierversuchen angefallene Funktionen. Ein bisschen Signale, ein bisschen Netzwerk und uname(). Kevin Wolf (5): libc: POSIX: sigaction libc: POSIX: getservbyname() libc: netinet/in.h zieht arpa/inet.h nach libc: POSIX: Mehr Signale libc: POSIX: uname() src/include/lost/config.h | 9 +++ src/modules/include/netdb.h | 21 +++++++ src/modules/include/netinet/in.h | 1 + src/modules/include/signal.h | 74 ++++++++++++++++++++------ src/modules/include/sys/utsname.h | 52 ++++++++++++++++++ src/modules/lib/posix/net.c | 36 +++++++++++++ src/modules/lib/posix/signal.c | 106 +++++++++++++++++++++++++++++++++++-- 7 files changed, 277 insertions(+), 22 deletions(-) create mode 100644 src/modules/include/sys/utsname.h From kevin at tyndur.org Wed Apr 22 20:18:15 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 22 Apr 2009 20:18:15 +0200 Subject: [tyndur-devel] [PATCH 3/5] libc: netinet/in.h zieht arpa/inet.h nach In-Reply-To: <1240424297-4863-1-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> Message-ID: <1240424297-4863-4-git-send-email-kevin@tyndur.org> * libc: Funktionen wie htons() gehoeren zwar eigentlich nach arpa/inet.h, werden aber laut Manpage gelegentlich auch in netinet/in.h erwartet - und mutt bestaetigt das. --- src/modules/include/netinet/in.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index a150e23..2dc3b8e 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -31,6 +31,7 @@ #include #include +#include /// Adresse fuer das INET-Protokol (IPv4) struct sockaddr_in { -- 1.6.0.2 From kevin at tyndur.org Wed Apr 22 20:18:13 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 22 Apr 2009 20:18:13 +0200 Subject: [tyndur-devel] [PATCH 1/5] libc: POSIX: sigaction In-Reply-To: <1240424297-4863-1-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> Message-ID: <1240424297-4863-2-git-send-email-kevin@tyndur.org> + libc: POSIX: Signale von reinen Handler auf sigactions umgestellt (die aber alles ausser dem Handler ignorieren). sigaction() hinzugefuegt. --- src/modules/include/signal.h | 56 +++++++++++++++++++++++++++------------ src/modules/lib/posix/signal.c | 47 ++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 22 deletions(-) diff --git a/src/modules/include/signal.h b/src/modules/include/signal.h index 0571c08..364cd67 100644 --- a/src/modules/include/signal.h +++ b/src/modules/include/signal.h @@ -75,7 +75,7 @@ typedef uint32_t sig_atomic_t; /// Pipe-Fehler #define SIGPIPE 13 -/// TODO +/// alarm()-Timer ist abgelaufen #define SIGALRM 14 /// Prozess terminieren (kann abgefangen werden) @@ -110,22 +110,6 @@ void _signal_default_handler(int signal); #define SIG_IGN (NULL) - -/// Typ fuer einen Pointer auf einen Signal-Handler -typedef void (*sighandler_t)(int); - -/// Einen Signal-Hander aendern -sighandler_t signal(int signum, sighandler_t handler); - -/// Ein Signal zum aktuellen Prozess senden -int raise(int signal); - -/// Ein Signal an einen anderen Prozess senden -int kill(pid_t pid, int signal); - - - - // Verwaltung von sigsets /// Typ fuer eine Sammlung von Signalen @@ -149,5 +133,43 @@ int sigdelset(sigset_t *sigset, int signal); int sigismember(const sigset_t *sigset, int signal); + +// Signal-Handler + +/// Typ fuer einen Pointer auf einen Signal-Handler +typedef void (*sighandler_t)(int); + +/// Bei einem Signal auszufuehrende Aktion +struct sigaction { + sighandler_t sa_handler; + sigset_t sa_mask; + int sa_flags; +}; + + +/** + * Aendert die auszufuehrende Aktion fuer ein Signal und gibt die alte Aktion + * zurueck. + * + * @param sig Nummer des Signals, fuer das die Aktion geaendert wird + * @param action Neue Aktion. Wenn NULL, wird nur die aktuelle Aktion + * zurueckgegeben, aber keine Aenderung vorgenommen + * @param old Wenn nicht NULL, wird hier die alte Aktion gespeichert + */ +int sigaction(int sig, const struct sigaction* action, struct sigaction* old); + +/// Einen Signal-Hander aendern +sighandler_t signal(int signum, sighandler_t handler); + +/// Ein Signal zum aktuellen Prozess senden +int raise(int signal); + +/// Ein Signal an einen anderen Prozess senden +int kill(pid_t pid, int signal); + + + + + #endif // ifndef _SIGNAL_H_ diff --git a/src/modules/lib/posix/signal.c b/src/modules/lib/posix/signal.c index 4d70a61..03cfb56 100644 --- a/src/modules/lib/posix/signal.c +++ b/src/modules/lib/posix/signal.c @@ -37,7 +37,7 @@ #include /// Array mit Pointern auf die Signal-Handler -static sighandler_t signal_handlers [_SIGNO_MAX]; +static struct sigaction sigactions[_SIGNO_MAX]; static bool initialized = FALSE; /** @@ -46,8 +46,9 @@ static bool initialized = FALSE; static void init_signals(void) { int i; + memset(sigactions, 0, sizeof(sigactions)); for (i = 0; i < _SIGNO_MAX; i++) { - signal_handlers[i] = SIG_DFL; + sigactions[i].sa_handler = SIG_DFL; } initialized = TRUE; @@ -73,7 +74,7 @@ int raise(int signum) return -1; } - sighandler_t handler = signal_handlers[signum]; + sighandler_t handler = sigactions[signum].sa_handler; if (handler != NULL) { handler(signum); } @@ -150,14 +151,50 @@ sighandler_t signal(int signum, sighandler_t handler) } // Alter Handler Speichern, weil er zurueck gegeben wird - sighandler_t old_handler = signal_handlers[signum]; + sighandler_t old_handler = sigactions[signum].sa_handler; // Neuer setzen - signal_handlers[signum] = handler; + sigactions[signum].sa_handler = handler; return old_handler; } +/** + * Aendert die auszufuehrende Aktion fuer ein Signal und gibt die alte Aktion + * zurueck. + * TODO Momentan nur Handler, POSIX sieht da mehr vor + * + * @param sig Nummer des Signals, fuer das die Aktion geaendert wird + * @param action Neue Aktion. Wenn NULL, wird nur die aktuelle Aktion + * zurueckgegeben, aber keine Aenderung vorgenommen + * @param old Wenn nicht NULL, wird hier die alte Aktion gespeichert + */ +int sigaction(int sig, const struct sigaction* action, struct sigaction* old) +{ + // Initialisieren falls das noch nicht gemacht ist + if (initialized == FALSE) { + init_signals(); + } + + // Ungueltige Signale und SIGKILL koennen nicht gesetzt werden + if ((sig >= _SIGNO_MAX) || (sig == SIGKILL)) { + errno = EINVAL; + return -1; + } + + // Alte Werte zurueckgeben + if (old != NULL) { + memcpy(old, &sigactions[sig], sizeof(*old)); + } + + // Neue Werte setzen + if (action != NULL) { + memcpy(&sigactions[sig], action, sizeof(*action)); + } + + return 0; +} + /** * Sigset initialisieren und/oder leeren. -- 1.6.0.2 From kevin at tyndur.org Wed Apr 22 20:18:16 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 22 Apr 2009 20:18:16 +0200 Subject: [tyndur-devel] [PATCH 4/5] libc: POSIX: Mehr Signale In-Reply-To: <1240424297-4863-1-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> Message-ID: <1240424297-4863-5-git-send-email-kevin@tyndur.org> + libc: POSIX: Signale blockieren mit sigprocmask() ! libc: POSIX: raise() setzt errno, wenn es -1 zurueckgibt --- src/modules/include/signal.h | 20 +++++++++++++- src/modules/lib/posix/signal.c | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletions(-) diff --git a/src/modules/include/signal.h b/src/modules/include/signal.h index 364cd67..ab67d88 100644 --- a/src/modules/include/signal.h +++ b/src/modules/include/signal.h @@ -146,6 +146,12 @@ struct sigaction { int sa_flags; }; +enum { + SIG_BLOCK, + SIG_UNBLOCK, + SIG_SETMASK, +}; + /** * Aendert die auszufuehrende Aktion fuer ein Signal und gibt die alte Aktion @@ -158,9 +164,21 @@ struct sigaction { */ int sigaction(int sig, const struct sigaction* action, struct sigaction* old); -/// Einen Signal-Hander aendern +/// Einen Signal-Handler aendern sighandler_t signal(int signum, sighandler_t handler); +/** + * Verwaltung von blockierten Signalen + * + * @param mode SIG_BLOCK: Alle Signale aus sigset blockieren + * SIG_UNBLOCK: Alle Signale aus sigset wieder aktivieren + * SIG_SETMASK: sigset als neue Signal-Maske benutzen + * + * @return 0 bei Erfolg. -1 und errno = EINVAL, wenn mode einen unerlaubten + * Wert hat. + */ +int sigprocmask(int mode, const sigset_t* sigset, sigset_t* oldset); + /// Ein Signal zum aktuellen Prozess senden int raise(int signal); diff --git a/src/modules/lib/posix/signal.c b/src/modules/lib/posix/signal.c index 03cfb56..e35064d 100644 --- a/src/modules/lib/posix/signal.c +++ b/src/modules/lib/posix/signal.c @@ -38,6 +38,7 @@ /// Array mit Pointern auf die Signal-Handler static struct sigaction sigactions[_SIGNO_MAX]; +static sigset_t sigmask; static bool initialized = FALSE; /** @@ -46,7 +47,10 @@ static bool initialized = FALSE; static void init_signals(void) { int i; + memset(sigactions, 0, sizeof(sigactions)); + memset(&sigmask, 0, sizeof(sigmask)); + for (i = 0; i < _SIGNO_MAX; i++) { sigactions[i].sa_handler = SIG_DFL; } @@ -71,9 +75,16 @@ int raise(int signum) // Wenn das Signal Groesser ist als die Groesste gueltige wird sofort // abgebrochen. if (signum >= _SIGNO_MAX) { + errno = EINVAL; return -1; } + // Pruefen, ob das Signal nicht blockiert ist + if (sigismember(&sigmask, signum)) { + return 0; + } + + // Handler aufrufen sighandler_t handler = sigactions[signum].sa_handler; if (handler != NULL) { handler(signum); @@ -290,6 +301,54 @@ int sigismember(const sigset_t *sigset, int signum) } /** + * Verwaltung von blockierten Signalen + * + * @param mode SIG_BLOCK: Alle Signale aus sigset blockieren + * SIG_UNBLOCK: Alle Signale aus sigset wieder aktivieren + * SIG_SETMASK: sigset als neue Signal-Maske benutzen + * + * @return 0 bei Erfolg. -1 und errno = EINVAL, wenn mode einen unerlaubten + * Wert hat. + */ +int sigprocmask(int mode, const sigset_t* sigset, sigset_t* oldset) +{ + int i; + + if (oldset != NULL) { + memcpy(oldset, &sigmask, sizeof(sigset_t)); + } + + switch (mode) { + case SIG_BLOCK: + for (i = 0; i < _SIGNO_MAX; i++) { + if (sigismember(sigset, i)) { + sigaddset(&sigmask, i); + } + } + break; + + case SIG_UNBLOCK: + for (i = 0; i < _SIGNO_MAX; i++) { + if (sigismember(sigset, i)) { + sigdelset(&sigmask, i); + } + } + break; + + case SIG_SETMASK: + memcpy(&sigmask, sigset, sizeof(sigset_t)); + break; + + default: + errno = EINVAL; + return -1; + } + + return 0; +} + + +/** * Callbackfunktion fuer alarm() */ static void do_alarm(void) -- 1.6.0.2 From kevin at tyndur.org Wed Apr 22 20:18:14 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 22 Apr 2009 20:18:14 +0200 Subject: [tyndur-devel] [PATCH 2/5] libc: POSIX: getservbyname() In-Reply-To: <1240424297-4863-1-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> Message-ID: <1240424297-4863-3-git-send-email-kevin@tyndur.org> + libc: POSIX: getservbyname(). Die Service-Datenbank ist vorerst in der libc hartkodiert. --- src/modules/include/netdb.h | 21 +++++++++++++++++++++ src/modules/lib/posix/net.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 0 deletions(-) diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h index d2a3666..12e6e9a 100644 --- a/src/modules/include/netdb.h +++ b/src/modules/include/netdb.h @@ -38,7 +38,28 @@ struct hostent { #define h_addr h_addr_list[0] }; +struct servent { + char* s_name; + char** s_aliases; + + /// Portnummer des Diensts, in Big Endian + int s_port; + + char* s_proto; + +}; + struct hostent* gethostbyname(const char* name); +/** + * Gibt Informationen zu einem Netzwerkdienst zurueck. Wenn der Dienst nicht + * gefunden werden kann, wird NULL zurueckgegeben. + * + * @param name Name des Diensts (z.B. "imap") + * @param protocol Name des Transportprotokolls (z.B. "tcp"). Falls nicht + * angegeben, soll jeder Treffer zaehlen. + */ +struct servent* getservbyname(const char* name, const char* protocol); + #endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 545c906..0b335a8 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -119,3 +119,39 @@ struct hostent* gethostbyname(const char* name) return &hostent; } + + +/* Definition der bekannten Netzwerkdienste */ +static char* service_aliases_http[] = { "http", NULL }; +static char* service_aliases_imap[] = { "imap", NULL }; +static char* service_aliases_irc[] = { "irc", NULL }; + +static struct servent services[] = { + { "http", service_aliases_http, big_endian_word(80), "tcp" }, + { "imap", service_aliases_imap, big_endian_word(143), "tcp" }, + { "irc", service_aliases_irc, big_endian_word(6667), "tcp" }, + { NULL, NULL, 0, NULL } +}; + +/** + * Gibt Informationen zu einem Netzwerkdienst zurueck. Wenn der Dienst nicht + * gefunden werden kann, wird NULL zurueckgegeben. + * + * @param name Name des Diensts (z.B. "imap") + * @param protocol Name des Transportprotokolls (z.B. "tcp"). Falls nicht + * angegeben, soll jeder Treffer zaehlen. + */ +struct servent* getservbyname(const char* name, const char* protocol) +{ + int i; + for (i = 0; services[i].s_name != NULL; i++) { + if (strcmp(name, services[i].s_name)) { + continue; + } + if ((protocol == NULL) || strcmp(protocol, services[i].s_proto)) { + return &services[i]; + } + } + + return NULL; +} -- 1.6.0.2 From toni at tyndur.org Wed Apr 22 21:00:39 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Wed, 22 Apr 2009 21:00:39 +0200 Subject: [tyndur-devel] [PATCH 1/4] Pascal-RTL: Unicode-Strings initialisieren In-Reply-To: <1240095359-29201-2-git-send-email-kevin@tyndur.org> References: <1240095359-29201-1-git-send-email-kevin@tyndur.org> <1240095359-29201-2-git-send-email-kevin@tyndur.org> Message-ID: <20090422190039.GA8785@einstein.produktiv.lan> On Sun, Apr 19 00:55, Kevin Wolf wrote: > + Pascal-RTL: system initialisiert den WideStringManager Sieht, soweit ich das beurteilen kann, einleuchtend aus. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Wed Apr 22 21:27:55 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Wed, 22 Apr 2009 21:27:55 +0200 Subject: [tyndur-devel] [PATCH 2/4] Pascal-RTL: Unit tyndur In-Reply-To: <1240095359-29201-3-git-send-email-kevin@tyndur.org> References: <1240095359-29201-1-git-send-email-kevin@tyndur.org> <1240095359-29201-3-git-send-email-kevin@tyndur.org> Message-ID: <20090422192755.GB8785@einstein.produktiv.lan> On Sun, Apr 19 00:55, Kevin Wolf wrote: > + Pascal-RTL: tyndur: ReadUnicodeChar > --- > src/modules/pas/kedit/kedit.pas | 4 ++- > src/modules/pas/lib/tyndur/Makefile.all | 1 + > src/modules/pas/lib/tyndur/tyndur.pas | 36 +++++++++++++++++++++++++++++++ > 3 files changed, 40 insertions(+), 1 deletions(-) > create mode 100644 src/modules/pas/lib/tyndur/Makefile.all > create mode 100644 src/modules/pas/lib/tyndur/tyndur.pas > > diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas > index 4409f7d..473c218 100644 > --- a/src/modules/pas/kedit/kedit.pas > +++ b/src/modules/pas/kedit/kedit.pas > @@ -1,7 +1,9 @@ > program KEdit; > {$H+} > > -uses crt, sysutils, kedit_tui, kedit_buf, kedit_input, kedit_main; > +uses > + crt, sysutils, tyndur, > + kedit_tui, kedit_buf, kedit_input, kedit_main; > > type > textfile = text; > diff --git a/src/modules/pas/lib/tyndur/Makefile.all b/src/modules/pas/lib/tyndur/Makefile.all > new file mode 100644 > index 0000000..aacb99c > --- /dev/null > +++ b/src/modules/pas/lib/tyndur/Makefile.all > @@ -0,0 +1 @@ > +cp libptyndur.a tyndur.ppu ../units > diff --git a/src/modules/pas/lib/tyndur/tyndur.pas b/src/modules/pas/lib/tyndur/tyndur.pas > new file mode 100644 > index 0000000..5cffdad > --- /dev/null > +++ b/src/modules/pas/lib/tyndur/tyndur.pas > @@ -0,0 +1,36 @@ > +unit tyndur; > + > +interface > + > + function ReadUnicodeChar: UnicodeChar; > + > + > +implementation > + > + uses crt; > + > + function ReadUnicodeChar: UnicodeChar; > + var > + keys: Array [1..5] of char; > + pkeys: PChar; > + > + res: Array [1..2] of UnicodeChar; > + pres: PUnicodeChar; > + > + ret: integer; > + i: integer; > + begin > + pkeys := @keys[1]; > + pres := @res[1]; > + for i := 1 to 4 do begin > + keys[i] := readkey; > + keys[i+1] := #0; > + ret := Utf8ToUnicode(pres, 2, pkeys, i); > + if ret >= 0 then begin > + break; > + end; > + end; > + exit(res[1]); > + end; > + > +end. Hm gibts hier keinen Fehlerfall der abgefangen werden müsste? -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Apr 23 20:33:16 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 23 Apr 2009 20:33:16 +0200 Subject: [tyndur-devel] [PATCH 3/4] kirc: Unterstuetzung fuer UTF-8-Eingabe In-Reply-To: <1240095359-29201-4-git-send-email-kevin@tyndur.org> References: <1240095359-29201-1-git-send-email-kevin@tyndur.org> <1240095359-29201-4-git-send-email-kevin@tyndur.org> Message-ID: <20090423183316.GA9080@einstein.produktiv.lan> On Sun, Apr 19 00:55, Kevin Wolf wrote: > + kirc: Unterstuetzung fuer UTF-8-Eingabe (vom Netzwerk kommender Text > wird weiterhin so an vterm weitergeleitet wie er ist; automagische > Zeichensatzerkennung sollte aber relativ leicht machbar sein) Ich glaube das sieht gut aus. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Thu Apr 23 21:52:23 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 23 Apr 2009 21:52:23 +0200 Subject: [tyndur-devel] [PATCH] kedit: Workaround fuer Tabs Message-ID: <1240516343-22822-1-git-send-email-kevin@tyndur.org> * kedit: Beim Laden Tabs durch 8 Leerzeichen ersetzen, ansonsten kommt das Rendering fuerchterlich durcheinander, wenn es ein Zeichen malt und der Cursor geht acht Zeichen weiter. Dieser Patch haengt von der UTF-8-Serie ab. --- src/modules/pas/kedit/kedit_main.pas | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/pas/kedit/kedit_main.pas b/src/modules/pas/kedit/kedit_main.pas index 8e2948d..18dbef7 100644 --- a/src/modules/pas/kedit/kedit_main.pas +++ b/src/modules/pas/kedit/kedit_main.pas @@ -41,7 +41,7 @@ function RTrim(stext: string):string; implementation -uses crt, dos, sysutils, kedit_tui; +uses crt, dos, sysutils, strutils, kedit_tui; @@ -180,7 +180,10 @@ begin while not(eof(lfile)) do begin Inc(cnt); ReadLn(lfile, s); - text^[cnt] := Utf8Decode(s); + + // FIXME Sobald kedit Tabs kann, duefern die hier nicht mehr zu + // Leerzeichen werden + text^[cnt] := Utf8Decode(AnsiReplaceStr(s, #9, StringOfChar(' ', 8))); end; Close(lfile); -- 1.6.0.2 From toni at tyndur.org Thu Apr 23 21:59:26 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 23 Apr 2009 21:59:26 +0200 Subject: [tyndur-devel] [PATCH] kedit: Workaround fuer Tabs In-Reply-To: <1240516343-22822-1-git-send-email-kevin@tyndur.org> References: <1240516343-22822-1-git-send-email-kevin@tyndur.org> Message-ID: <20090423195925.GB9080@einstein.produktiv.lan> On Thu, Apr 23 21:52, Kevin Wolf wrote: > * kedit: Beim Laden Tabs durch 8 Leerzeichen ersetzen, ansonsten kommt > das Rendering fuerchterlich durcheinander, wenn es ein Zeichen malt > und der Cursor geht acht Zeichen weiter. Das ist... nett... Aber dann halt rein damit. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 25 16:47:55 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 16:47:55 +0200 Subject: [tyndur-devel] Schreibpuffer Message-ID: <1240670877-17506-1-git-send-email-toni@tyndur.org> Mit dieser Serie wird standardmässig Blockpufferung auf alle geoeffneten Dateien eingeschaltet. From toni at tyndur.org Sat Apr 25 16:47:56 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 16:47:56 +0200 Subject: [tyndur-devel] [PATCH] libc: Blockpuffer auf allen Dateien aktivieren In-Reply-To: <1240670877-17506-1-git-send-email-toni@tyndur.org> References: <1240670877-17506-1-git-send-email-toni@tyndur.org> Message-ID: <1240670877-17506-2-git-send-email-toni@tyndur.org> * libc: Blockpuffer auf allen Dateien aktivieren * libc: Buffer fuer stderr deaktivieren --- src/modules/include/lostio.h | 6 ++++++ src/modules/lib/lostio/handler.c | 12 +++++++++--- src/modules/lib/stdlibc/file.c | 30 ++++++++++++++++++++++++++++-- src/modules/lib/stdlibc/stdio.c | 4 ++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/modules/include/lostio.h b/src/modules/include/lostio.h index 60cddf1..57e3cf7 100644 --- a/src/modules/include/lostio.h +++ b/src/modules/include/lostio.h @@ -117,6 +117,12 @@ typedef struct } typehandle_t; +/// Geoeffnete Datei auf Clientseite (Wrapper fuer FILE) +struct lostio_internal_file { + io_resource_t res; + bool free_buffer; +}; + ///LostIO-Schnittstelle initialisieren void lostio_init(void); diff --git a/src/modules/lib/lostio/handler.c b/src/modules/lib/lostio/handler.c index ce61485..0c9c1b6 100644 --- a/src/modules/lib/lostio/handler.c +++ b/src/modules/lib/lostio/handler.c @@ -63,6 +63,12 @@ void rpc_io_open(pid_t pid, dword correlation_id, size_t data_size, void* data) //Wird bei pipes als quelle verwendet io_resource_t* io_source = (io_resource_t*) ((dword)data + 1 + sizeof(pid_t)); + + // FIXME + struct lostio_internal_file* int_source = malloc(sizeof(*int_source)); + int_source->res = *io_source; + int_source->free_buffer = FALSE; + io_source = &int_source->res; byte* attr = (byte*) data; pid_t* caller_pid = (pid_t*) ((dword)data + 1 ); @@ -79,6 +85,7 @@ void rpc_io_open(pid_t pid, dword correlation_id, size_t data_size, void* data) { io_res.pid = 0; rpc_send_response(pid, correlation_id, sizeof(io_resource_t), (char*) &io_res); + free(io_source); } else { @@ -120,6 +127,7 @@ void rpc_io_open(pid_t pid, dword correlation_id, size_t data_size, void* data) if(io_res.id == 0) { io_res.pid = 0; + free(io_source); } rpc_send_response(pid, correlation_id, sizeof(io_resource_t), (char*) &io_res); @@ -562,13 +570,11 @@ static lostio_filehandle_t* lostio_open(char* path, byte attr, pid_t pid, io_res handle->id = handle_id++; handle->pid = pid; handle->flags = attr; - handle->source = malloc(sizeof(io_resource_t)); + handle->source = io_source; handle->pos = 0; handle->data = NULL; handle->node = node; - memcpy(handle->source, io_source, sizeof(io_resource_t)); - filehandles = list_push(filehandles, (void*) handle); //printf("[ LOSTIO ] Oeffne '%s' '%s'\n", node->name, path); diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c index bd4cb1c..34b8171 100644 --- a/src/modules/lib/stdlibc/file.c +++ b/src/modules/lib/stdlibc/file.c @@ -142,6 +142,16 @@ FILE* fopen (const char* filename, const char* mode) // Pfad im Handle hinterlegen io_res->path = malloc(strlen(filename) + 1); strcpy(io_res->path, filename); + + + struct lostio_internal_file* int_res = malloc(sizeof(*int_res)); + int_res->res = *io_res; + int_res->free_buffer = FALSE; + setvbuf(&int_res->res, malloc(BUFSIZ), _IOFBF, BUFSIZ); + int_res->free_buffer = TRUE; + + free(io_res); + io_res = &int_res->res; } free(resp); @@ -191,6 +201,8 @@ int fclose (FILE* io_res) return EOF; } + setvbuf(io_res, NULL, _IONBF, 0); + result = rpc_get_dword(io_res->pid, "IO_CLOSE", sizeof(io_resource_id_t), (char*) &(io_res->id)); free(io_res); @@ -749,15 +761,21 @@ int fpurge(io_resource_t* io_res) */ int setvbuf(FILE* io_res, char* buffer, int mode, size_t size) { + struct lostio_internal_file* int_res = + (struct lostio_internal_file*) io_res; + char* old_buffer; + // Wenn das Dateihandle nicht in Ordung ist, wird abgebrochen if (io_res == NULL) { return -1; } + old_buffer = io_res->buffer_ptr; + if (buffer == NULL) { io_res->buffer_ptr = NULL; io_res->buffer_mode = IO_BUFFER_MODE_NONE; - return 0; + goto out; } //Hier wird ein switch benutzt, damit keine nicht Definierten Werte fuer @@ -791,7 +809,15 @@ int setvbuf(FILE* io_res, char* buffer, int mode, size_t size) default: return -1; } - + +out: + // Wenn bis jetzt ein intern Alloziierter Puffer benutzt wurde, muss er + // freigegeben werden. + if (int_res->free_buffer && old_buffer && (old_buffer != buffer)) { + free(old_buffer); + int_res->free_buffer = FALSE; + } + return 0; } diff --git a/src/modules/lib/stdlibc/stdio.c b/src/modules/lib/stdlibc/stdio.c index 6685a82..e1fa127 100644 --- a/src/modules/lib/stdlibc/stdio.c +++ b/src/modules/lib/stdlibc/stdio.c @@ -102,6 +102,10 @@ void stdio_init(void) } else { stderr = fopen(path, "a"); } + + // stderr soll ungepuffert sein + setvbuf(stderr, NULL, _IONBF, 0); + fclose(path_file); } } -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 16:47:57 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 16:47:57 +0200 Subject: [tyndur-devel] [PATCH] libc: Fix fuer die Schreibpuffer in stdio In-Reply-To: <1240670877-17506-1-git-send-email-toni@tyndur.org> References: <1240670877-17506-1-git-send-email-toni@tyndur.org> Message-ID: <1240670877-17506-3-git-send-email-toni@tyndur.org> ! libc: Fehler behoben, der verhindert, dass gepuffert wird, und zu einem Buffer overflow führen kann. ! libc: Puffer in fclose und fseek flushen ! libc: Fix fuers Befuellen der Blockpuffer, damit dabei nichts ueberschrieben wird. --- src/modules/lib/stdlibc/file.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c index 34b8171..6441fcd 100644 --- a/src/modules/lib/stdlibc/file.c +++ b/src/modules/lib/stdlibc/file.c @@ -201,6 +201,7 @@ int fclose (FILE* io_res) return EOF; } + fflush(io_res); setvbuf(io_res, NULL, _IONBF, 0); result = rpc_get_dword(io_res->pid, "IO_CLOSE", sizeof(io_resource_id_t), @@ -489,10 +490,11 @@ size_t fwrite(const void* data, size_t blocksize, size_t blockcount, //Ueberpruefen, ob genug Platz im Buffer ist, dann werden die Daten // in den Buffer kopiert, sonst wird der Buffer geleert, und die // Daten werden direkt geschrieben. - if (io_res->buffer_size < (io_res->buffer_pos + data_size)) + if (io_res->buffer_size >= (io_res->buffer_pos + data_size)) { //Daten in den Buffer kopieren. - memcpy(io_res->buffer_ptr, data, data_size); + memcpy(io_res->buffer_ptr + io_res->buffer_pos, data, + data_size); io_res->buffer_pos += data_size; return data_size; } else { @@ -508,7 +510,7 @@ size_t fwrite(const void* data, size_t blocksize, size_t blockcount, // geleert, und die Daten werden auch direkt geschrieben. Auch wenn // die Daten mindestens einen Zeilenumbruch enthalten, wird der // Buffer geleert. - if ((io_res->buffer_size < (io_res->buffer_pos + data_size)) || + if ((io_res->buffer_size >= (io_res->buffer_pos + data_size)) || (memchr(data, '\n', data_size) != NULL)) { if (fflush(io_res) == EOF) { @@ -583,7 +585,9 @@ int fseek (FILE* io_res, long int offset, int origin) if ((io_res == NULL) || (io_res->pid == 0)) { return -1; } - + + fflush(io_res); + // ungetc-Buffer leeren if (io_res->ungetc_count != 0) { io_res->ungetc_count = 0; -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 16:53:44 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 16:53:44 +0200 Subject: [tyndur-devel] [PATCH] libc: Pufferung fuer stdout In-Reply-To: <1240670877-17506-1-git-send-email-toni@tyndur.org> References: <1240670877-17506-1-git-send-email-toni@tyndur.org> Message-ID: <1240671224-17708-1-git-send-email-toni@tyndur.org> * libc: Code fuer Pufferung von stdout aus crt0 nach stdio_init() verschoben, damit er auch von der pascal rtl benutzt werden kann. * libc: Puffer fuer stdin deaktivieren, das spart etwas speicher. --- src/modules/lib/crt0.c | 11 ----------- src/modules/lib/stdlibc/stdio.c | 9 +++++++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/modules/lib/crt0.c b/src/modules/lib/crt0.c index a62a65b..615baf9 100644 --- a/src/modules/lib/crt0.c +++ b/src/modules/lib/crt0.c @@ -50,14 +50,6 @@ void __attribute__((weak)) _start(void) init_waitpid(); #ifndef _NO_STDIO_ stdio_init(); - #ifndef _NO_STDIO_BUFFER_ - // Buffer fuer stdout allozieren - size_t stdout_buffer_size = 256; - void* stdout_buffer = malloc(stdout_buffer_size); - - // Buffer einrichten - setvbuf(stdout, stdout_buffer, _IOLBF, stdout_buffer_size); - #endif #endif //Kommandozeilenargumente Parsen ---- @@ -101,10 +93,7 @@ void __attribute__((weak)) _start(void) // freigegeben. // FIXME: Alle Buffer flushen!! #ifndef _NO_STDIO_ - #ifndef _NO_STDIO_BUFFER_ fflush(stdout); - free(stdout_buffer); - #endif #endif exit(result); diff --git a/src/modules/lib/stdlibc/stdio.c b/src/modules/lib/stdlibc/stdio.c index e1fa127..e6a1955 100644 --- a/src/modules/lib/stdlibc/stdio.c +++ b/src/modules/lib/stdlibc/stdio.c @@ -37,6 +37,9 @@ FILE* stdin = NULL; FILE* stdout = NULL; FILE* stderr = NULL; +/// Puffer fuer die Ausgabe +static char stdout_buf[512]; + /** * Initialisiert die Ein- und Ausgabe Filehandles */ @@ -65,6 +68,9 @@ void stdio_init(void) stdin = fopen(path, "rs"); } fclose(path_file); + + // stdin muss nicht gepuffert sein + setvbuf(stdin, NULL, _IONBF, 0); } // stdout aktualisieren @@ -84,6 +90,9 @@ void stdio_init(void) stdout = fopen(path, "a"); } fclose(path_file); + + // Zeilenpuffer fuer stdout aktivieren + setvbuf(stdout, stdout_buf, _IOLBF, sizeof(stdout_buf)); } // stderr -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:07:31 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:07:31 +0200 Subject: [tyndur-devel] cdi: Interrupts Message-ID: <1240672054-18390-1-git-send-email-toni@tyndur.org> Mit dieser Patchserie wird es möglich mit unserer cdi-Implementierung mehrere Interrupt-Handler zu benutzen in einem Treiber. Weiter wurde eine Funktion eingeführt um auf Interrupts zu warten. From toni at tyndur.org Sat Apr 25 17:07:32 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:07:32 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: Interrupthandlern die Int-Nummer uebergeben In-Reply-To: <1240672054-18390-1-git-send-email-toni@tyndur.org> References: <1240672054-18390-1-git-send-email-toni@tyndur.org> Message-ID: <1240672054-18390-2-git-send-email-toni@tyndur.org> * libc: Interrupthandler kriegen jetzt die Interruptnummer als Parameter uebergeben. * floppy, kbc, cdi/core: Notwendige Aenderungen damit das kompiliert --- src/modules/cdi/lib/misc.c | 2 +- src/modules/floppy/floppy.c | 4 ++-- src/modules/include/rpc.h | 2 +- src/modules/kbc/keyboard.c | 4 ++-- src/modules/kbc/mouse.c | 2 +- src/modules/kbc/mouse.h | 2 +- src/modules/lib/rpc/messaging.c | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/modules/cdi/lib/misc.c b/src/modules/cdi/lib/misc.c index 6e102ea..4a22f78 100644 --- a/src/modules/cdi/lib/misc.c +++ b/src/modules/cdi/lib/misc.c @@ -23,7 +23,7 @@ static struct cdi_device* driver_irq_device = NULL; /** * Interner IRQ-Handler, der den IRQ-Handler des Treibers aufruft */ -static void irq_handler(void) +static void irq_handler(byte irq) { driver_irq_handler(driver_irq_device); } diff --git a/src/modules/floppy/floppy.c b/src/modules/floppy/floppy.c index 188d787..b0de3b3 100644 --- a/src/modules/floppy/floppy.c +++ b/src/modules/floppy/floppy.c @@ -141,7 +141,7 @@ void floppy_select_drive(byte drive); void floppy_send_byte(byte cmd); byte floppy_read_byte(void); void floppy_set_motor(bool state); -void floppy_irq_handler(void); +void floppy_irq_handler(byte irq); bool floppy_wait_irq(int num); void floppy_int_sense(void); void floppy_reset(void); @@ -482,7 +482,7 @@ byte floppy_read_byte() /** * Wird aufgerufen wenn der IRQ6 auftritt */ -void floppy_irq_handler() +void floppy_irq_handler(byte irq) { DEBUG_MSG("IRQ"); p(); diff --git a/src/modules/include/rpc.h b/src/modules/include/rpc.h index 2fc4542..bd2e2ac 100644 --- a/src/modules/include/rpc.h +++ b/src/modules/include/rpc.h @@ -57,7 +57,7 @@ extern handler_function_t rpc_response_handler; void init_messaging(void); bool register_message_handler(char* fnname, handler_function_t handler); -void register_intr_handler(byte intr, void (*handler)(void)); +void register_intr_handler(byte intr, void (*handler)(byte)); dword rpc_get_dword(pid_t pid, char* function_name, size_t data_length, char* data); int rpc_get_int(pid_t pid, char* function_name, size_t data_length, char* data); diff --git a/src/modules/kbc/keyboard.c b/src/modules/kbc/keyboard.c index 412119d..19acb07 100644 --- a/src/modules/kbc/keyboard.c +++ b/src/modules/kbc/keyboard.c @@ -65,7 +65,7 @@ static void rpc_register_callback(pid_t pid, dword cid, size_t data_size, /** * IRQ-Hander */ -static void kbd_irq_handler(void); +static void kbd_irq_handler(byte irq); /** @@ -120,7 +120,7 @@ void keyboard_init(void) /** * IRQ-Hander */ -void kbd_irq_handler() { +void kbd_irq_handler(byte irq) { uint8_t scancode; uint8_t keycode = 0; bool break_code = FALSE; diff --git a/src/modules/kbc/mouse.c b/src/modules/kbc/mouse.c index 0b16dbe..9b25f65 100644 --- a/src/modules/kbc/mouse.c +++ b/src/modules/kbc/mouse.c @@ -146,7 +146,7 @@ void mouse_install() mouse_cycle = 0; } -void mouse_irq_handler() +void mouse_irq_handler(byte irq) { byte status = inb(0x64); if (!(status & 0x20)) { diff --git a/src/modules/kbc/mouse.h b/src/modules/kbc/mouse.h index 12b107d..c5cc11f 100644 --- a/src/modules/kbc/mouse.h +++ b/src/modules/kbc/mouse.h @@ -10,7 +10,7 @@ void mouse_write(byte a_write); byte mouse_read(void); void mouse_install(void); -void mouse_irq_handler(void); +void mouse_irq_handler(byte irq); size_t mouse_read_handler(lostio_filehandle_t* filehandle, void* buf, size_t blocksize, size_t blockcount); diff --git a/src/modules/lib/rpc/messaging.c b/src/modules/lib/rpc/messaging.c index 388866e..cee2ac1 100644 --- a/src/modules/lib/rpc/messaging.c +++ b/src/modules/lib/rpc/messaging.c @@ -44,7 +44,7 @@ typedef struct { handler_function_t handler; } msg_handler_t; -void (*intr_handler[256])(void) = { NULL }; +void (*intr_handler[256])(byte) = { NULL }; msg_handler_t message_handler[MAX_MESSAGE_HANDLERS]; handler_function_t rpc_response_handler = NULL; @@ -95,7 +95,7 @@ bool register_message_handler(char* fnname, handler_function_t handler) return TRUE; } -void register_intr_handler(byte intr, void (*handler)(void)) +void register_intr_handler(byte intr, void (*handler)(byte)) { intr_handler[intr] = handler; add_intr_handler(intr); @@ -116,7 +116,7 @@ void librpc_c_rpc_handler(dword caller_pid, dword data_size, char* data) if (function < 256) { // Interrupt-Handler if ((intr_handler[function] != NULL) && (caller_pid == my_pid)) { - intr_handler[function](); + intr_handler[function](function); } } else if ((function >= RPC_SIGNALS_START) && (function <= RPC_SIGNALS_END)) -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:07:33 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:07:33 +0200 Subject: [tyndur-devel] [PATCH 2/3] cdi/core: Mehrere IRQ-Handler pro Treiber In-Reply-To: <1240672054-18390-1-git-send-email-toni@tyndur.org> References: <1240672054-18390-1-git-send-email-toni@tyndur.org> Message-ID: <1240672054-18390-3-git-send-email-toni@tyndur.org> ! cdi/core: Jetzt funktioniert das mit den IRQs auch, wenn man mal auf absurde Idee kommt, mehrere IRQs in einem Treiber benutzen zu wollen. ;-) --- src/modules/cdi/lib/misc.c | 34 +++++++++++++++++++++++++--------- 1 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/modules/cdi/lib/misc.c b/src/modules/cdi/lib/misc.c index 4a22f78..ae66a9e 100644 --- a/src/modules/cdi/lib/misc.c +++ b/src/modules/cdi/lib/misc.c @@ -16,16 +16,26 @@ #include "cdi.h" #include "cdi/misc.h" -// TODO Bei mehr als einem registrierten IRQ geht das so nicht mehr -static void (*driver_irq_handler)(struct cdi_device*) = NULL; -static struct cdi_device* driver_irq_device = NULL; +#define LOST_IRQ_OFFSET 0x20 +#define IRQ_COUNT 0x10 + +static void (*driver_irq_handler[IRQ_COUNT])(struct cdi_device*) = { NULL }; +static struct cdi_device* driver_irq_device[IRQ_COUNT] = { NULL }; /** * Interner IRQ-Handler, der den IRQ-Handler des Treibers aufruft */ -static void irq_handler(byte irq) +static void irq_handler(uint8_t irq) { - driver_irq_handler(driver_irq_device); + // Oops, das war wohl kein IRQ, den wollen wir nicht. + if ((irq < LOST_IRQ_OFFSET) || (irq > LOST_IRQ_OFFSET + IRQ_COUNT)) { + return; + } + + irq -= LOST_IRQ_OFFSET; + if (driver_irq_handler[irq]) { + driver_irq_handler[irq](driver_irq_device[irq]); + } } /** @@ -35,13 +45,19 @@ static void irq_handler(byte irq) * @param handler Handlerfunktion * @param device Geraet, das dem Handler als Parameter uebergeben werden soll */ -void cdi_register_irq(uint8_t irq, void (*handler)(struct cdi_device*), +void cdi_register_irq(uint8_t irq, void (*handler)(struct cdi_device*), struct cdi_device* device) { - driver_irq_handler = handler; - driver_irq_device = device; + if (irq > IRQ_COUNT) { + // FIXME: Eigentlich sollte diese Funktion etwas weniger optimistisch + // sein, und einen Rueckgabewert haben. + return; + } + + driver_irq_handler[irq] = handler; + driver_irq_device[irq] = device; - register_intr_handler(0x20 + irq, irq_handler); + register_intr_handler(LOST_IRQ_OFFSET + irq, irq_handler); } /** -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:07:34 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:07:34 +0200 Subject: [tyndur-devel] [PATCH 3/3] cdi/core: Funktionen um auf IRQs zu warten In-Reply-To: <1240672054-18390-1-git-send-email-toni@tyndur.org> References: <1240672054-18390-1-git-send-email-toni@tyndur.org> Message-ID: <1240672054-18390-4-git-send-email-toni@tyndur.org> + cdi/core: Zwei neue Funktionen um effizient auf IRQs zu warten --- src/modules/cdi/include/cdi/misc.h | 24 +++++++++++- src/modules/cdi/lib/misc.c | 73 +++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/modules/cdi/include/cdi/misc.h b/src/modules/cdi/include/cdi/misc.h index dc9e277..2a130f6 100644 --- a/src/modules/cdi/include/cdi/misc.h +++ b/src/modules/cdi/include/cdi/misc.h @@ -24,7 +24,29 @@ */ void cdi_register_irq(uint8_t irq, void (*handler)(struct cdi_device*), struct cdi_device* device); - + +/** + * Setzt den IRQ-Zaehler fuer cdi_wait_irq zurueck. + * + * @param irq Nummer des IRQ + * + * @return 0 bei Erfolg, -1 im Fehlerfall + */ +int cdi_reset_wait_irq(uint8_t irq); + +/** + * Wartet bis der IRQ aufgerufen wurde. Der interne Zaehler muss zuerst mit + * cdi_reset_wait_irq zurueckgesetzt werden, damit auch die IRQs abgefangen + * werden koennen, die kurz vor dem Aufruf von dieser Funktion aufgerufen + * werden. + * + * @param irq Nummer des IRQ auf den gewartet werden soll + * @param timeout Anzahl der Millisekunden, die maximal gewartet werden sollen + * + * @return 0 wenn der irq aufgerufen wurde, -1 sonst. + */ +int cdi_wait_irq(uint8_t irq, uint32_t timeout); + /** * Reserviert physisch zusammenhaengenden Speicher. * diff --git a/src/modules/cdi/lib/misc.c b/src/modules/cdi/lib/misc.c index ae66a9e..4f2c19d 100644 --- a/src/modules/cdi/lib/misc.c +++ b/src/modules/cdi/lib/misc.c @@ -21,6 +21,7 @@ static void (*driver_irq_handler[IRQ_COUNT])(struct cdi_device*) = { NULL }; static struct cdi_device* driver_irq_device[IRQ_COUNT] = { NULL }; +static uint8_t driver_irq_count[IRQ_COUNT] = { 0 }; /** * Interner IRQ-Handler, der den IRQ-Handler des Treibers aufruft @@ -33,6 +34,7 @@ static void irq_handler(uint8_t irq) } irq -= LOST_IRQ_OFFSET; + driver_irq_count[irq]++; if (driver_irq_handler[irq]) { driver_irq_handler[irq](driver_irq_device[irq]); } @@ -59,7 +61,76 @@ void cdi_register_irq(uint8_t irq, void (*handler)(struct cdi_device*), register_intr_handler(LOST_IRQ_OFFSET + irq, irq_handler); } - + +/** + * Setzt den IRQ-Zaehler fuer cdi_wait_irq zurueck. + * + * @param irq Nummer des IRQ + * + * @return 0 bei Erfolg, -1 im Fehlerfall + */ +int cdi_reset_wait_irq(uint8_t irq) +{ + if (irq > IRQ_COUNT) { + return -1; + } + + driver_irq_count[irq] = 0; + return 0; +} + +// Dummy-Callback fuer den timer_register-Aufruf in cdi_wait_irq +static void wait_irq_dummy_callback(void) { } + +/** + * Wartet bis der IRQ aufgerufen wurde. Der interne Zaehler muss zuerst mit + * cdi_reset_wait_irq zurueckgesetzt werden, damit auch die IRQs abgefangen + * werden koennen, die kurz vor dem Aufruf von dieser Funktion aufgerufen + * werden. + * + * @param irq Nummer des IRQ auf den gewartet werden soll + * @param timeout Anzahl der Millisekunden, die maximal gewartet werden sollen + * + * @return 0 wenn der irq aufgerufen wurde, -1 wenn eine ungueltige IRQ-Nummer + * angegeben wurde, -2 wenn eine nicht registrierte IRQ-Nummer angegeben wurde, + * und -3 im Falle eines Timeouts. + */ +int cdi_wait_irq(uint8_t irq, uint32_t timeout) +{ + uint64_t timeout_ticks; + + if (irq > IRQ_COUNT) { + return -1; + } + + if (!driver_irq_handler[irq]) { + return -2; + } + + // Wenn der IRQ bereits gefeuert wurde, koennen wir uns ein paar Syscalls + // sparen + if (driver_irq_count [irq]) { + return 0; + } + + timeout_ticks = get_tick_count() + (uint64_t) timeout * 1000; + timer_register(wait_irq_dummy_callback, timeout * 1000); + + p(); + while (!driver_irq_count [irq]) { + v_and_wait_for_rpc(); + + if (timeout_ticks < get_tick_count()) { + return -3; + } + p(); + } + v(); + + return 0; +} + + /** * Reserviert physisch zusammenhaengenden Speicher. * -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:11:09 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:11:09 +0200 Subject: [tyndur-devel] [PATCH] config: Terminalbezeichnung anpassen Message-ID: <1240672269-18604-1-git-send-email-toni@tyndur.org> * config: Terminalbezeichnung von lost auf tyndur aendern --- build/root-common/config/shell/start.lsh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/build/root-common/config/shell/start.lsh b/build/root-common/config/shell/start.lsh index 3441449..1c47474 100644 --- a/build/root-common/config/shell/start.lsh +++ b/build/root-common/config/shell/start.lsh @@ -1,5 +1,5 @@ #!file:/apps/sh set PATH file:/apps;file:/system/lpt-bin -set TERM lost +set TERM tyndur cd file:/ -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:16:29 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:16:29 +0200 Subject: [tyndur-devel] vterm: EOF Message-ID: <1240672591-18954-1-git-send-email-toni@tyndur.org> Diese Patchserie sorgt dafür dass vterm das EOF nur noch setzt, wenn Strg+D gedrueckt wurde. From toni at tyndur.org Sat Apr 25 17:16:30 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:16:30 +0200 Subject: [tyndur-devel] [PATCH 1/2] vterm: EOF gescheit setzen In-Reply-To: <1240672591-18954-1-git-send-email-toni@tyndur.org> References: <1240672591-18954-1-git-send-email-toni@tyndur.org> Message-ID: <1240672591-18954-2-git-send-email-toni@tyndur.org> * vtem: EOF nur nach Betaetigen von Strg+D setzen --- src/modules/vterm/lostio.c | 8 +++++++- src/modules/vterm/term.c | 7 ++++++- src/modules/vterm/vterm.h | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/vterm/lostio.c b/src/modules/vterm/lostio.c index 92d57fa..428d339 100644 --- a/src/modules/vterm/lostio.c +++ b/src/modules/vterm/lostio.c @@ -107,6 +107,13 @@ size_t terminal_read(lostio_filehandle_t* file, void* buf, size_t size = blocksize * blockcount; vterminal_t* vterm = (vterminal_t*) file->node->data; + if (vterm->set_eof) { + vterm->set_eof = FALSE; + file->flags |= LOSTIO_FLAG_EOF; + v(); + return 0; + } + if (vterm->in_buffer_size == 0) { v(); return 0; @@ -119,7 +126,6 @@ size_t terminal_read(lostio_filehandle_t* file, void* buf, memcpy(buf, vterm->in_buffer, size); vterm->in_buffer_size -= size; - vterm->in_node->size = vterm->in_buffer_size; // Die uebrigen Daten am ende des Buffers an den Anfang schieben if (vterm->in_buffer_size != 0) { memmove(vterm->in_buffer, vterm->in_buffer + size, diff --git a/src/modules/vterm/term.c b/src/modules/vterm/term.c index 5fab963..3e6881f 100644 --- a/src/modules/vterm/term.c +++ b/src/modules/vterm/term.c @@ -107,6 +107,8 @@ vterminal_t* vterm_create(char shortcut) vfstree_create_node(path, LOSTIO_TYPES_IN, 0, vterm, LOSTIO_FLAG_NOAUTOEOF); vterm->in_node = vfstree_get_node_by_path(path); + // Sonst setzt LIO das EOF + vterm->in_node->size = 1; // Out-Node memcpy(path + name_len + 1, "/out", 5); @@ -149,7 +151,6 @@ static void input_buffer_append(vterminal_t* vterm, char c) { // FIXME; Ineffizienter konnte ich das nicht loesen. ;-) vterm->in_buffer_size += 1; - vterm->in_node->size = current_vterm->in_buffer_size; vterm->in_buffer = realloc(vterm->in_buffer, vterm->in_buffer_size); // Daten in den Puffer kopieren vterm->in_buffer[vterm->in_buffer_size - 1] = c; @@ -237,6 +238,10 @@ bool vterm_process_raw_input(uint8_t keycode, struct modifiers* modifiers) case KEYCODE_F11: vterm_switch_to(11); return TRUE; case KEYCODE_F12: vterm_switch_to(12); return TRUE; } + } else if (modifiers->control && (keycode == 32)) { + // Strg + D = EOF + current_vterm->set_eof = TRUE; + return TRUE; } else if (keycode == KEYCODE_SCROLL_LOCK) { current_vterm->output.scroll_lock = !current_vterm->output.scroll_lock; return TRUE; diff --git a/src/modules/vterm/vterm.h b/src/modules/vterm/vterm.h index 450252a..d5149da 100644 --- a/src/modules/vterm/vterm.h +++ b/src/modules/vterm/vterm.h @@ -163,6 +163,9 @@ typedef struct { /// Anzahl der Zeichen im utf-8 Puffer size_t utf8_buffer_offset; + + /// Beim naechsten Lesen EOF setzen + bool set_eof; } vterminal_t; /// Status der Modifiertasten -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:16:31 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:16:31 +0200 Subject: [tyndur-devel] [PATCH 2/2] libc: EOF-Workarounds entfernen aus readline() In-Reply-To: <1240672591-18954-1-git-send-email-toni@tyndur.org> References: <1240672591-18954-1-git-send-email-toni@tyndur.org> Message-ID: <1240672591-18954-3-git-send-email-toni@tyndur.org> - libc: EOF-Workarounds entfernen aus readline(), da vterm das jetzt sauber macht. --- src/modules/lib/readline.c | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-) diff --git a/src/modules/lib/readline.c b/src/modules/lib/readline.c index a73725f..5c7fab0 100644 --- a/src/modules/lib/readline.c +++ b/src/modules/lib/readline.c @@ -58,13 +58,9 @@ static char keyboard_read_char(void) char c = 0; while (!fread(&c, 1, 1, stdin)) { - // FIXME Das gehoert eigentlich rein, geht aber nicht, weil vterm ein EOF - // liefert, wenn der Eingabepuffer gerade leer ist. - /* if (feof(stdin)) { return 0; } - */ } return c; @@ -239,13 +235,9 @@ static bool complete_word(char* buffer, int* pos, int* len) */ char* readline(const char* prompt) { - // FIXME Das gehoert eigentlich rein, geht aber nicht, weil vterm ein EOF - // liefert, wenn der Eingabepuffer gerade leer ist. - /* if (feof(stdin)) { return NULL; } - */ char* buffer = malloc(BUFFER_SIZE); int pos, size; -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:18:04 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:18:04 +0200 Subject: [tyndur-devel] [PATCH] libc: Synchrones Lesen in LIO Message-ID: <1240672684-19126-1-git-send-email-toni@tyndur.org> * libc: Anfaenge von Synchronem Lesen in LostIO brauchbar gemacht. ! vterm: lostio_dispatch() nur aufrufen wenn neue Eingaben da sind, und nicht nach jedem rpc. --- src/modules/lib/lostio/handler.c | 18 +++++--- src/modules/lib/lostio/include/lostio_internal.h | 9 ++++ src/modules/lib/lostio/sync.c | 49 +++++++++++----------- src/modules/lib/stdlibc/file.c | 4 ++ src/modules/vterm/input.c | 3 + src/modules/vterm/vterm.c | 1 - 6 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/modules/lib/lostio/handler.c b/src/modules/lib/lostio/handler.c index 0c9c1b6..5e8f361 100644 --- a/src/modules/lib/lostio/handler.c +++ b/src/modules/lib/lostio/handler.c @@ -191,7 +191,12 @@ void rpc_io_read(pid_t pid, dword correlation_id, size_t data_size, void* data) size_t size = typehandle->read(filehandle, buf, read_request->blocksize, read_request->blockcount); - rpc_send_response(pid, correlation_id, size, (char*) buf); + if (!size && (filehandle->flags & IO_OPEN_MODE_SYNC)) { + // Synchrones lesen + lostio_sync_read_wait(pid, correlation_id, read_request); + } else { + rpc_send_response(pid, correlation_id, size, (char*) buf); + } return; } @@ -200,11 +205,12 @@ void rpc_io_read(pid_t pid, dword correlation_id, size_t data_size, void* data) size_t size = typehandle->read(filehandle, shm_ptr, read_request->blocksize, read_request->blockcount); close_shared_memory(read_request->shared_mem_id); - -/* printf("size = %d, ptr = %p, value = %d\n", - sizeof(reply.size), &reply.size, reply.size); - fflush(stdout);*/ - rpc_send_dword_response(pid, correlation_id, size); + if (!size && (filehandle->flags & IO_OPEN_MODE_SYNC)) { + // Synchrones lesen + lostio_sync_read_wait(pid, correlation_id, read_request); + } else { + rpc_send_dword_response(pid, correlation_id, size); + } //v(); } diff --git a/src/modules/lib/lostio/include/lostio_internal.h b/src/modules/lib/lostio/include/lostio_internal.h index ba7a691..49fa280 100644 --- a/src/modules/lib/lostio/include/lostio_internal.h +++ b/src/modules/lib/lostio/include/lostio_internal.h @@ -76,6 +76,15 @@ void rpc_io_unlink(pid_t pid, dword correlation_id, size_t data_size, void* d //bool vfstree_delete_node(char* path); +/** + * Schiebt eine Anfrage fuer synchrones Lesen auf, falls keine Daten vorhanden + * sind. + * + * @param read_request Gesendete anfrage + */ +void lostio_sync_read_wait(pid_t pid, dword correlation_id, + io_read_request_t* read_request); + ///Filehandle aus der Liste holen lostio_filehandle_t* get_filehandle(pid_t pid, dword id); diff --git a/src/modules/lib/lostio/sync.c b/src/modules/lib/lostio/sync.c index d57e7bd..d6e126f 100644 --- a/src/modules/lib/lostio/sync.c +++ b/src/modules/lib/lostio/sync.c @@ -36,11 +36,11 @@ #include "stdlib.h" #include "string.h" #include "stdio.h" +#include /// In dieser Struktur werden die Informationen zu aufgeschobenen reads /// gespeichert struct sync_read_s { - lostio_filehandle_t* filehandle; io_read_request_t read_request; dword correlation_id; pid_t pid; @@ -48,32 +48,33 @@ struct sync_read_s { static list_t* sync_read_list = NULL; + /** * Verarbeitet eventuell vorhandene aufgeschobene Anfragen fuer synchrones * Lesen. */ -void lostio_sync_dispatch() +void lostio_sync_dispatch(void) { - int i = 0; - struct sync_read_s* sync_read; + int i; + size_t sz; // Wenn noch keine Anfragen vorhanden sind, wird abgebrochen. if (sync_read_list == NULL) { return; } - while ((sync_read = list_get_element_at(sync_read_list, i)) != NULL) { - // Pruefen ob jetzt genug Daten vorhanden sind. - if ((sync_read->filehandle->node->size - sync_read->filehandle->pos) >= - (sync_read->read_request.blocksize * sync_read->read_request. - blockcount)) - { - rpc_io_read(sync_read->pid, sync_read->correlation_id, - sizeof(io_read_request_t), &sync_read->read_request); + p(); + sz = list_size(sync_read_list); + { + struct sync_read_s* reads[sz]; + i = 0; + while ((reads[i++] = list_pop(sync_read_list))) { } + v(); - list_remove(sync_read_list, i); - } else { - i++; + for (i = 0; i < sz; i++) { + rpc_io_read(reads[i]->pid, reads[i]->correlation_id, + sizeof(reads[i]->read_request), &reads[i]->read_request); + free(reads[i]); } } } @@ -82,27 +83,27 @@ void lostio_sync_dispatch() * Schiebt eine Anfrage fuer synchrones Lesen auf, falls keine Daten vorhanden * sind. * - * @param filehandle Filehandle von dem gelesen werden soll * @param read_request Gesendete anfrage */ -void lostio_sync_read_wait(lostio_filehandle_t* filehandle, pid_t pid, - dword correlation_id, io_read_request_t* read_request) +void lostio_sync_read_wait(pid_t pid, dword correlation_id, + io_read_request_t* read_request) { - struct sync_read_s* sync_read = malloc(sizeof(struct sync_read_s)); + struct sync_read_s* sync_read = malloc(sizeof(*sync_read)); + p(); if (sync_read_list == NULL) { sync_read_list = list_create(); } - sync_read->pid = pid; - sync_read->correlation_id = correlation_id; - // Read-Request kopieren, da er beim zurueckspringen aus dem rpc-Handler // zerstoert wird. - memcpy(&sync_read->read_request, read_request, sizeof(io_read_request_t)); + memcpy(&sync_read->read_request, read_request, + sizeof(sync_read->read_request)); - sync_read->filehandle = filehandle; + sync_read->pid = pid; + sync_read->correlation_id = correlation_id; sync_read_list = list_push(sync_read_list, sync_read); + v(); } diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c index 6441fcd..4b1fdbe 100644 --- a/src/modules/lib/stdlibc/file.c +++ b/src/modules/lib/stdlibc/file.c @@ -116,6 +116,10 @@ FILE* fopen (const char* filename, const char* mode) *attr |= IO_OPEN_MODE_LINK; break; + case 's': + *attr |= IO_OPEN_MODE_SYNC; + break; + } } diff --git a/src/modules/vterm/input.c b/src/modules/vterm/input.c index 78e5f91..0f38f55 100644 --- a/src/modules/vterm/input.c +++ b/src/modules/vterm/input.c @@ -105,6 +105,9 @@ static void rpc_kbd_callback(pid_t pid, dword cid, size_t data_size, p(); send_key_to_vterm(vterm, kbd_data[0], !kbd_data[1]); v(); + + // Synchrones Lesen benachrichtigen + lostio_dispatch(); } /** diff --git a/src/modules/vterm/vterm.c b/src/modules/vterm/vterm.c index d3fcd7f..345406b 100644 --- a/src/modules/vterm/vterm.c +++ b/src/modules/vterm/vterm.c @@ -70,7 +70,6 @@ int main(int argc, char* argv[]) // Auf Anfragen warten while(TRUE) { wait_for_rpc(); - lostio_dispatch(); } } -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:23:56 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:23:56 +0200 Subject: [tyndur-devel] libc: Mehr Multibyte- und wchar-Funktionen Message-ID: <1240673039-19706-1-git-send-email-toni@tyndur.org> Diese Serie bereichert unsere Libc um ein paar weitere Multibyte-Funktionen und ein paar Funktionen für Strings aus breiten Zeichen in der wchar.h sind auch dazu gekommen. From toni at tyndur.org Sat Apr 25 17:23:57 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:23:57 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: fgetwc, fputwc und verwandte Funktionen In-Reply-To: <1240673039-19706-1-git-send-email-toni@tyndur.org> References: <1240673039-19706-1-git-send-email-toni@tyndur.org> Message-ID: <1240673039-19706-2-git-send-email-toni@tyndur.org> * libc: wchar.h nach modules/include verschoben, da sie stdio.h inkludieren muss. + libc: fgetwc, getwc, getchar: Breite Zeichen aus Datei lesen + libc: fputwc, putwc, putwchar: Breite Zeichen in Datei schreiben --- src/include/wchar.h | 37 ---------- src/modules/include/wchar.h | 96 +++++++++++++++++++++++++ src/modules/lib/stdlibc/wstdio.c | 142 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+), 37 deletions(-) delete mode 100644 src/include/wchar.h create mode 100644 src/modules/include/wchar.h create mode 100644 src/modules/lib/stdlibc/wstdio.c diff --git a/src/include/wchar.h b/src/include/wchar.h deleted file mode 100644 index f9cd89b..0000000 --- a/src/include/wchar.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2008 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _WCHAR_H_ -#define _WCHAR_H_ - -#include - -typedef wchar_t wint_t; - -#endif //ifndef _WCHAR_H_ - diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h new file mode 100644 index 0000000..d173bce --- /dev/null +++ b/src/modules/include/wchar.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_H_ +#define _WCHAR_H_ + +#include +#include + +#define WEOF ((wint_t) -1) + +typedef wchar_t wint_t; + +/* WSTDIO */ + +/** + * Breites Zeichen aus einer Datei lesen. + * + * @param stream Die geoeffnete Datei + * + * @return Das gelesene Zeichen oder WEOF im Fehlerfall. + */ +wint_t fgetwc(FILE* stream); + +/** + * Wie fgetwc, mit dem Unterschied, dass getwc als Makro implementiert werden + * darf, das den Parameter mehrmals auswertet + * + * @see fgetwc + */ +wint_t getwc(FILE* stream); + +/** + * Breites Zeichen von der Standardeingabe lesen. + * + * @see fgetwc + */ +wint_t getwchar(void); + + +/** + * Ein breites Zeichen in eine Datei schreiben, dabei wird das Zeichen + * entsprechend codiert. + * + * @param wc Das zu schreibende Zeichen + * @param stream Die geoeffnete Datei + * + * @return Das geschriebene Zeichen oder WEOF im Fehlerfall + */ +wint_t fputwc(wchar_t wc, FILE* stream); + +/** + * Wie fputwc, mit dem Unterschied, dass putwc als Makro implementiert werden + * darf, das seine Parameter mehrmals auswertet. + * + * @see fputwc + */ +wint_t putwc(wchar_t wc, FILE* stream); + +/** + * Breites Zeichen auf die Standardausgabe schreiben + * + * @see fputwc + * @param wc Das zu schreibende Zeichen + * + * @return Das geschriebene Zeichen oder WEOF im Fehlerfall + */ +wint_t putwchar(wchar_t wc); + +#endif //ifndef _WCHAR_H_ + diff --git a/src/modules/lib/stdlibc/wstdio.c b/src/modules/lib/stdlibc/wstdio.c new file mode 100644 index 0000000..6d61666 --- /dev/null +++ b/src/modules/lib/stdlibc/wstdio.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +/** + * Breites Zeichen aus einer Datei lesen. + * + * @param stream Die geoeffnete Datei + * + * @return Das gelesene Zeichen oder WEOF im Fehlerfall. + */ +wint_t fgetwc(FILE* stream) +{ + char mbc[MB_CUR_MAX]; + int len = 0; + int mbres; + int c; + wint_t result; + + do { + if ((c = fgetc(stream)) == EOF) { + return WEOF; + } + + mbc[len++] = c; + } while (((mbres = mbtowc(&result, mbc, len)) == -1) && (len < MB_CUR_MAX)); + + // Das Zeichen konnte nicht konvertiert werden. Wir schicken alle bytes bis + // aufs erste mittels ungetc zurueck + if (mbres < 0) { + int i; + for (i = len - 1; i > 0; i--) { + ungetc(mbc[i], stream); + } + + errno = EILSEQ; + return WEOF; + } + + return result; +} + +/** + * Wie fgetwc, mit dem Unterschied, dass getwc als Makro implementiert werden + * darf, das den Parameter mehrmals auswertet + * + * @see fgetwc + */ +wint_t getwc(FILE* stream) +{ + return fgetwc(stream); +} + +/** + * Breites Zeichen von der Standardeingabe lesen. + * + * @see fgetwc + */ +wint_t getwchar() +{ + return fgetwc(stdin); +} + + +/** + * Ein breites Zeichen in eine Datei schreiben, dabei wird das Zeichen + * entsprechend codiert. + * + * @param wc Das zu schreibende Zeichen + * @param stream Die geoeffnete Datei + * + * @return Das geschriebene Zeichen oder WEOF im Fehlerfall + */ +wint_t fputwc(wchar_t wc, FILE* stream) +{ + char mbc[MB_CUR_MAX]; + int len; + + if ((len = wctomb(mbc, wc)) < 0) { + errno = EILSEQ; + return WEOF; + } + + if (!fwrite(mbc, len, 1, stream)) { + return WEOF; + } + + return wc; +} + +/** + * Wie fputwc, mit dem Unterschied, dass putwc als Makro implementiert werden + * darf, das seine Parameter mehrmals auswertet. + * + * @see fputwc + */ +wint_t putwc(wchar_t wc, FILE* stream) +{ + return fputwc(wc, stream); +} + +/** + * Breites Zeichen auf die Standardausgabe schreiben + * + * @see fputwc + * @param wc Das zu schreibende Zeichen + * + * @return Das geschriebene Zeichen oder WEOF im Fehlerfall + */ +wint_t putwchar(wchar_t wc) +{ + return fputwc(wc, stdout); +} + -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:23:58 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:23:58 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: Ein bisschen mehr wchar.h In-Reply-To: <1240673039-19706-1-git-send-email-toni@tyndur.org> References: <1240673039-19706-1-git-send-email-toni@tyndur.org> Message-ID: <1240673039-19706-3-git-send-email-toni@tyndur.org> + libc: Die Funktionen mbrtowc, wcrtomb, wcwidth und wcswidth, damit kommt curses schon weiter beim Kompilieren mit UTF-8-Support --- src/include/limits.h | 3 + src/modules/include/wchar.h | 52 +++++++++++++++++ src/modules/lib/posix/regex/regex2.h | 8 --- src/modules/lib/stdlibc/wchar.c | 101 ++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 src/modules/lib/stdlibc/wchar.c diff --git a/src/include/limits.h b/src/include/limits.h index 1ea8cc5..62f8399 100644 --- a/src/include/limits.h +++ b/src/include/limits.h @@ -57,4 +57,7 @@ #define _POSIX_PATH_MAX 4096 +/** Maximale laenge eines Multibyte-Zeichens in Bytes */ +#define MB_LEN_MAX 4 + #endif diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h index d173bce..6ed1d51 100644 --- a/src/modules/include/wchar.h +++ b/src/modules/include/wchar.h @@ -34,8 +34,60 @@ #define WEOF ((wint_t) -1) +/** + * Sollte theoretisch alle Werte von wchar_t und zusaetzlich WEOF annehmen + * koennen. + */ typedef wchar_t wint_t; +/** + * Repraesentiert den internen Shift-Status einer Funktion, brauchen wir mit + * UTF-8 nicht. + */ +typedef int mbstate_t; + + + +/* WSTRINGS */ + +/** + * Reentrante Variante von mbtowc, bei uns mit UTF-8 aber identisch. + * @see mbtowc + */ +size_t mbrtowc(wchar_t* wc, const char* s, size_t len, mbstate_t* ps); + +/** + * Reentrante Variante von wctomb, bei uns mit UTF-8 aber identisch. + * @see wctomb + */ +size_t wcrtomb(char* buf, wchar_t wc, mbstate_t* ps); + + +/** + * Anzahl der Spalten, die ein Zeichen in Anspruch nimmt, errechnen. Fuer c = 0 + * wird 0 zuruekgegeben. Falls es sich nicht um ein druckbares Zeichen handelt, + * wird -1 zurueckgegeben. + * + * @param wc Das breite Zeichen + * + * @return Anzahl Spalten, oder -1 wenn das Zeichen nicht druckbar ist. + */ +int wcwidth(wchar_t wc); + +/** + * Anzahl der Spalten, die ein String aus breiten Zeichen in Anspruch nimmt, + * errechnen. Wird ein nicht druckbares Zeichen erkannt, wird abgebrochen. + * + * @see wcwidth + * @param wcs Zeiger auf das erste Zeichen + * @param len Anzahl der Zeichen + * + * @return Anzahl der Zeichen oder -1 im Fehlerfall. + */ +int wcswidth(const wchar_t* wcs, size_t len); + + + /* WSTDIO */ /** diff --git a/src/modules/lib/posix/regex/regex2.h b/src/modules/lib/posix/regex/regex2.h index 38855e8..294b4c4 100644 --- a/src/modules/lib/posix/regex/regex2.h +++ b/src/modules/lib/posix/regex/regex2.h @@ -159,11 +159,3 @@ struct re_guts { #define OUT (CHAR_MAX+1) /* a non-character value */ #define ISWORD(c) (isalnum((uch)(c)) || (c) == '_') - - -#include -typedef union { - int64_t __mbstateL; /* for alignment */ - char __mbstate8[128]; -} mbstate_t; - diff --git a/src/modules/lib/stdlibc/wchar.c b/src/modules/lib/stdlibc/wchar.c new file mode 100644 index 0000000..79bb27e --- /dev/null +++ b/src/modules/lib/stdlibc/wchar.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +/** + * Reentrante Variante von mbtowc, bei uns mit UTF-8 aber identisch. + * @see mbtowc + */ +size_t mbrtowc(wchar_t* wc, const char* s, size_t len, mbstate_t* ps) +{ + return mbtowc(wc, s, len); +} + +/** + * Reentrante Variante von wctomb, bei uns mit UTF-8 aber identisch. + * @see wctomb + */ +size_t wcrtomb(char* buf, wchar_t wc, mbstate_t* ps) +{ + return wctomb(buf, wc); +} + +/** + * Anzahl der Spalten, die ein Zeichen in Anspruch nimmt, errechnen. Fuer c = 0 + * wird 0 zuruekgegeben. Falls es sich nicht um ein druckbares Zeichen handelt, + * wird -1 zurueckgegeben. + * + * @param wc Das breite Zeichen + * + * @return Anzahl Spalten, oder -1 wenn das Zeichen nicht druckbar ist. + */ +int wcwidth(wchar_t wc) +{ + // Muss nach Spezifikation so sein + if (!wc) { + return 0; + } + + // Steuerzeichen sind nicht druckbar + if (wc < 32) { + return -1; + } + + // Das ist so sicher noch etwas rudimentaer, doch im Moment reicht das so + // fuer uns. + return 1; +} + +/** + * Anzahl der Spalten, die ein String aus breiten Zeichen in Anspruch nimmt, + * errechnen. Wird ein nicht druckbares Zeichen erkannt, wird abgebrochen. + * + * @see wcwidth + * @param wcs Zeiger auf das erste Zeichen + * @param len Anzahl der Zeichen + * + * @return Anzahl der Zeichen oder -1 im Fehlerfall. + */ +int wcswidth(const wchar_t* wcs, size_t len) +{ + int cols = 0; + int cur; + size_t i; + + for (i = 0; i < len; i++) { + if ((cur = wcwidth(wcs[i])) == -1) { + return -1; + } + cols += cur; + } + + return cols; +} + -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:23:59 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:23:59 +0200 Subject: [tyndur-devel] [PATCH 3/3] libc: Ein paar wchar.h-Stringfunktionen In-Reply-To: <1240673039-19706-1-git-send-email-toni@tyndur.org> References: <1240673039-19706-1-git-send-email-toni@tyndur.org> Message-ID: <1240673039-19706-4-git-send-email-toni@tyndur.org> + libc: Ein paar Stringfunktionen in der wchar.h aus freebsd portiert + libc: Noch ein bisschen wctype.h damit die BSD-Funktionen kompilieren Signed-off-by: Antoine Kaufmann --- src/include/wctype.h | 46 +++ src/modules/include/wchar.h | 422 +++++++++++++++++++++++++ src/modules/lib/stdlibc/wstring/wcpcpy.c | 55 ++++ src/modules/lib/stdlibc/wstring/wcpncpy.c | 60 ++++ src/modules/lib/stdlibc/wstring/wcscasecmp.c | 59 ++++ src/modules/lib/stdlibc/wstring/wcscat.c | 57 ++++ src/modules/lib/stdlibc/wstring/wcschr.c | 53 +++ src/modules/lib/stdlibc/wstring/wcscmp.c | 57 ++++ src/modules/lib/stdlibc/wstring/wcscoll.c | 37 +++ src/modules/lib/stdlibc/wstring/wcscpy.c | 55 ++++ src/modules/lib/stdlibc/wstring/wcscspn.c | 64 ++++ src/modules/lib/stdlibc/wstring/wcsdup.c | 52 +++ src/modules/lib/stdlibc/wstring/wcslcat.c | 74 +++++ src/modules/lib/stdlibc/wstring/wcslcpy.c | 72 +++++ src/modules/lib/stdlibc/wstring/wcslen.c | 53 +++ src/modules/lib/stdlibc/wstring/wcsncasecmp.c | 70 ++++ src/modules/lib/stdlibc/wstring/wcsncat.c | 68 ++++ src/modules/lib/stdlibc/wstring/wcsncmp.c | 67 ++++ src/modules/lib/stdlibc/wstring/wcsncpy.c | 70 ++++ src/modules/lib/stdlibc/wstring/wcsnlen.c | 53 +++ src/modules/lib/stdlibc/wstring/wcspbrk.c | 64 ++++ src/modules/lib/stdlibc/wstring/wcsrchr.c | 60 ++++ src/modules/lib/stdlibc/wstring/wcsspn.c | 67 ++++ src/modules/lib/stdlibc/wstring/wcsstr.c | 66 ++++ src/modules/lib/stdlibc/wstring/wcstok.c | 108 +++++++ src/modules/lib/stdlibc/wstring/wmemchr.c | 59 ++++ src/modules/lib/stdlibc/wstring/wmemcmp.c | 62 ++++ src/modules/lib/stdlibc/wstring/wmemcpy.c | 50 +++ src/modules/lib/stdlibc/wstring/wmemmove.c | 49 +++ src/modules/lib/stdlibc/wstring/wmemset.c | 56 ++++ 30 files changed, 2185 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/stdlibc/wstring/wcpcpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcpncpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscasecmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscat.c create mode 100644 src/modules/lib/stdlibc/wstring/wcschr.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscoll.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscspn.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsdup.c create mode 100644 src/modules/lib/stdlibc/wstring/wcslcat.c create mode 100644 src/modules/lib/stdlibc/wstring/wcslcpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcslen.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncasecmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncat.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsnlen.c create mode 100644 src/modules/lib/stdlibc/wstring/wcspbrk.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsrchr.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsspn.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsstr.c create mode 100644 src/modules/lib/stdlibc/wstring/wcstok.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemchr.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemcmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemcpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemmove.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemset.c diff --git a/src/include/wctype.h b/src/include/wctype.h index e69de29..8f21b94 100644 --- a/src/include/wctype.h +++ b/src/include/wctype.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_H_ +#define _WCTYPE_H_ + +#define iswupper(c) ((c) >= L'A' && (c) <= L'Z') +#define iswlower(c) ((c) >= L'a' && (c) <= L'z') + +static inline wint_t towlower(wint_t c) +{ + return iswupper(c) ? c + (L'a' - L'A') : c; +} + +static inline wint_t towupper(wint_t c) +{ + return iswlower(c) ? c - (L'a' - L'A') : c; +} + +#endif /* ndef WCTYPE_H */ + diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h index 6ed1d51..d664741 100644 --- a/src/modules/include/wchar.h +++ b/src/modules/include/wchar.h @@ -87,6 +87,428 @@ int wcwidth(wchar_t wc); int wcswidth(const wchar_t* wcs, size_t len); +/** + * Einen String aus breiten Zeichen kopieren, das ist das Pendant zu stpcpy. Die + * beiden Strings duerfen sich nicht ueberlappen. Das abschliessende L'0' wird + * mitkopiert. + * + * @see stpcpy + * @see wcscpy + * @see wcpncpy + * @param dst Zeiger auf die Speicherstelle in die der Kopiertestring abgelegt + * werden soll. Dabei muss vom Aufrufer sichergestellt werden, dass + * dort mindestens speicher fuer wcslen(src) + 1 breite Zeichen ist. + * @param src + * + * @return Zeiger auf das Ende (L'0') des Zielstrings. + */ +wchar_t* wcpcpy(wchar_t* dst, const wchar_t* src); + +/** + * String aus breiten Zeichen kopieren. Dabei werden hoechstens len Zeichen + * kopiert. Sind in src weniger als len Zeichen wird dst mit L'\0' aufgefuellt. + * Ist src laenger als oder gleich lang wie len wird der String in dst nich + * nullterminiert, der Rueckgabewert zeigt also nich auf ein L'\0'. Die beiden + * Speicherbereiche duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcpncpy + * @param dst Zeiger auf den Speicherbereich der len breite Zeichen aufnehmen + * kann. Es werden genau len Zeichen hineingeschrieben. + * @param src Quellstring + * @param len Anzahl der Zeichen, die in dst geschrieben werden sollen. + * + * @return Zeiger auf das letzte geschriebene Byte, also immer dst + len - 1 + */ +wchar_t* wcpncpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen inklusive abschliessendes L'\0'. Diese + * Funktion ist das Pendant zu strcasecmp. + * + * @see strcasecmp + * @see wcscmp + * @see towlower + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscasecmp(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei wird der Inhalt von + * src inklusive dem abschliessenden L'\0' ans Ende von dst kopiert. Der + * Aufrufer muss sicherstellen, dass nach dst genug Speicher frei ist. Diese + * Funktion ist das Pendant zu strcat. + * + * @see strcat + * @see wcsncat + * @param dst Zeiger auf den String an dessen Ende src angehaengt werden soll. + * @param src Zeiger auf den String der an dst angehaengt werden soll. + * + * @return dst + */ +wchar_t* wcscat(wchar_t* dst, const wchar_t* src); + +/** + * Erstes Vorkommen eines breiten Zeichens aus einem String aus breiten Zeichen + * heraussuchen. Diese Funktion ist das Pendant zu strchr. + * + * @see strchr + * @param wcs Zeiger auf den String in dem gesucht werden soll. + * @param wc Zeichen das gesucht werden soll. + * + * @return Zeiger auf das erste gefundene Zeichen oder NULL wenn keines gefunden + * wurde. + */ +wchar_t* wcschr(const wchar_t* wcs, wchar_t wc); + +/** + * Zwei Strings aus breiten Zeichen inklusive dem abschliessenden L'\0' + * vergleichen. Diese Funktion ist das Pendant zu strcmp. + * + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscmp(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * TODO + */ +int wcscoll(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * String aus Breiten Zeichen inklusive abschliessendem L'\0' kopieren. Der + * Aufrufer hat sicherzustellen, dass dst genug Platz bietet. Die beiden Strings + * duerfen sich nicht uberlappen. Diese Funktion ist das Pendant zu strcpy. + * + * @see strcpy + * @see wcsncpy + * @see wcpcpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den String der kopiert werden soll. + * + * @return dst + */ +wchar_t* wcscpy(wchar_t* dst, const wchar_t* src); + +/** + * String aus breiten Zeichen nach einem Vorkommen eines Zeichens aus set + * durchsuchen. Diese Funktion ist das Pendant zu strcspn. + * + * @see strcspn + * @see wcsspn + * @param wcs Zeiger auf den String, dar durchsucht werden soll + * @param set Zeiger auf den String mit den zu suchenden Zeichen. + * + * @return Offset vom Anfang des Strings oder wcslen(wcs) wenn kein Vorkommen + * gefunden wurde. + */ +size_t wcscspn(const wchar_t* wcs, const wchar_t* set); + +/** + * String aus breiten Zeichen in einen neu allozierten Speicherbereich kopieren. + * Diese Funktion ist das Pendant zu strdup. + * + * @see strdup + * @param wcs Zeiger auf den zu kopierenden String + * + * @return Zeiger auf die Kopie. Muss vom Aufrufer freigegeben werden. Im + * Fehlerfall NULL. + */ +wchar_t* wcsdup(const wchar_t* wcs); + +/** + * Kopiert src an das Ende des Strings dst. Dabei wird der String dst auf + * maximal len - 1 Zeichen und L'\0' verlaengert, ausser wenn len == 0. + * + * @see wcsncat + * @param dst Zeiger auf String an den src angehaengt werden soll + * @param src Zeiger auf String der an dst angehaengt werden soll + * @param len Anzahl Zeichen auf die dst Maximal verlaengert werden darf + * inklusiv L'\0.' + * + * @return wcslen(urspruengliches dst) + wcslen(src); Wenn der Rueckgabewert >= + * len ist, wurde src nich vollstaendig kopiert. + */ +size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Kopiert einen String aus breiten Zeichen. Dabei werden maximal len - 1 + * Zeichen kopiert, und dst wird immer mit L'\0' terminiert, wenn len != 0 ist. + * + * @see wcscpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den Quellstring + * @param len Anzahl der Zeichen inklusiv abschliessendes L'\0', die maximal in + * dst geschrieben werden sollen. + * + * @return wcslen(src); Wenn der Rueckgabewert <= len ist, wurde src nicht + * vollstaendig kopiert. + */ +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Laenge eines Strings aus breiten Zeichen bestimmen. Dabei werden die Zeichen + * gezaehlt, bis ein abschliessendes L'\0' gefunden wird. Das L'\0' wird nicht + * mitgezaehlt. Diese Funktion ist das Pendant zu strlen. + * + * @see strlen + * @param wcs Zeiger auf den String + * + * @return Laenge des Strings in Zeichen + */ +size_t wcslen(const wchar_t* wcs); + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen. Dabei werden maximal die ersten len + * Zeichen von Beiden Strings verglichen. Diese Funktion ist das Pendant zu + * strncasecmp. + * + * @see strncasecmp + * @see wcscasecmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein L'\0' gefunden wird. + * + * @return 0 wenn die beiden Strings gleich sind, < 0 wenn das Zeichen in wcs2 + * groesser ist als das in wcs1 und > 0 wenn das Zeichen in wcs1 + * groesser ist als das in wcs2. + */ +int wcsncasecmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei werden maximal len + * Zeichen aus src kopiert. Der Aufrufer muss sicherstellen, dass nach dem + * String, auf den dst zeigt, noch mindestens len + 1 Zeichen platz haben. dst + * wird in jedem Fall mit L'\0' terminiert. Diese Funktion ist das Pendant zu + * strncat. + * + * @see strncat + * @see wcscat + * @param dst String an den src angehaengt werden soll + * @param src String der an dst angehaengt werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden aus src + * + * @return dst + */ +wchar_t* wcsncat(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Zwei Strings aus breiten Zeichen vergleichen. Dabei werden maximal len + * Zeichen verglichen. Diese Funktion ist das Pendant zu strncmp. + * + * @see strncmp + * @see wcscmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein abschliessendes L'\0' angetroffen wurde. + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcsncmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * String aus breiten Zeichen kopieren. Dabei werden maximal len Zeichen + * kopiert. Die restlichen Zeichen im Puffer werden mit L'\0' gefuellt. Ist src + * gleich lang wie oder laenger als len, wird dst nicht mit L'\0' terminiert. + * Die beiden Strings duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcscpy + * @param src String der kopiert werden soll + * @param dst Zeiger auf den Speicherbereich in den src kopiert werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden sollen + * + * @return dst + */ +wchar_t* wcsncpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Laenge eines Strings aus breiten Zeichen errechnen. Dabei werden maximal max + * Zeichen gezaehlt. Diese Funktion ist das Pendant zu strnlen. + * + * @see strnlen + * @see wcslen + * @param wcs String + * @param max Anzahl der Zeichen, die maximal gezaehlt werden sollen + * + * @return Anzahl der Zeichen ohne abschliessendes L'\0' + */ +size_t wcsnlen(const wchar_t* wcs, size_t max); + +/** + * Erstes vorkommen eines breiten Zeichens aus set im String aus breiten Zeichen + * wcs suchen. Diese Funktion ist das Pendant zu strpbrk. + * + * @see strpbrk + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set String aus Zeichen nach denen gesucht werden soll + * + * @return Zeiger auf die Position an der ein Zeichen gefunden wurde oder NULL + * falls keines gefunden wurde. + */ +wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* set); + +/** + * Letztes Vorkommen eines breiten Zeichens in einem String aus breiten Zeichen + * suchen. Diese Funktion ist das Pendant zu strrchr. + * + * @see strrchr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param wc Zeichen das gesucht werden soll + * + * @return Zeiger auf das letzte gefundene Vorkommen, oder NULL falls das + * Zeichen nicht gefunden wurde. + */ +wchar_t* wcsrchr(const wchar_t* wcs, wchar_t wc); + +/** + * Durchsucht einen String aus breiten Zeichen nach dem ersten Zeichen das nicht + * in set vorkommt. Diese Funktion ist das Pendant zu strspn. + * + * @see strspn + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set Zeichen die zugelassen sind + * + * @return Offset des ersten Zeichens das nicht in set vorkommt, oder + * wcslen(wcs) falls alle Zeichen in set enthalten sind. + */ +size_t wcsspn(const wchar_t* wcs, const wchar_t* set); + +/** + * Erstes Vorkommen des Breiten Strings find in wcs suchen. Diese Funktion ist + * das Pendant zu strstr. + * + * @see strstr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param find String der gesucht werden soll + * + * @return Zeiger auf das erste Vorkommen in wcs oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wcsstr(const wchar_t* wcs, const wchar_t* find); + +/** + * String aus breiten Zeichen in Tokens aufspalten, die durch die in delim + * angegebenen Zeichen getrennt werden. wcs wird dabei veraendert. Ist wcs != + * NULL beginnt die suche dort, sonst wird bei *last begonnen. *last wird + * jeweils auf den Anfang des naechsten Token gesetzt, oder auf NULL, wenn das + * Ende erreicht wurde. + * Diese Funktion ist das Pendant zu strtok. + * + * @see strtok + * @param wcs Zeiger auf das Zeichen bei dem die Zerlegung in Tokens begonnen + * werden soll, oder NULL, wenn der Wert von *last genommen werden + * soll. + * @param delim Zeichen die zwei Tokens voneinander trennen koennen + * @param last Zeiger auf die Speicherstelle an der die Funktion die Position + * des naechsten token speichern kann fuer den internen Gebrauch, + * um beim Naechsten Aufruf mit wcs == NULL das naechste Token + * zurueck geben zu koennen. + * + * @return Zeiger auf das aktuelle Token, oder NULL wenn keine Tokens mehr + * vorhanden sind. + */ +wchar_t* wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** last); + +/** + * Speicherbereich aus breiten Zeichen nach einem bestimmten Zeichen + * durchsuchen. Diese Funktion ist das Pendant zu memchr. + * + * @see memchr + * @see wcschr + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zu suchendes Zeichen + * @param len Laenge des Speicherbereichs + * + * @return Zeiger auf das gefundene Zeichen oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wmemchr(const wchar_t* wcs, wchar_t wc, size_t len); + +/** + * Zwei Speicherbereiche aus breiten Zeichen vergleichen. Diese Funktion ist das + * Pendant zu memcmp. + * + * @see memcmp + * @see wcscpm + * @see wcsncmp + * @param wcs1 Zeiger auf den ersten Speicherbereich + * @param wcs2 Zeiger auf den zweiten Speicherbereich + * @param len Laenge der beiden Speicherbereiche + * + * @return 0 wenn die beiden Speicherbereiche gleich sind, < 0 wenn das erste + * unterschiedliche Zeichen in wcs1 kleiner ist als das + * Korrespondierende in wcs2 oder > 0 wenn es groesser ist. + */ +int wmemcmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich nicht ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memcpy + * @see wcsncpy + * @see wcscpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemcpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memmove + * @see wmemcpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Speicherbereich aus breiten Zeichen mit einem bestimmten Zeichen ausfuellen. + * Diese Funktion ist das pendant zu memset. + * + * @see memset + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zeichen mit dem der Speicherbereich gefuellt werden soll + * @param len Laenge des Speicherbereichs + * + * @return wcs + */ +wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t len); + + + /* WSTDIO */ diff --git a/src/modules/lib/stdlibc/wstring/wcpcpy.c b/src/modules/lib/stdlibc/wstring/wcpcpy.c new file mode 100644 index 0000000..5d71596 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcpcpy.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 + * David E. O'Brien + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/** + * Einen String aus breiten Zeichen kopieren, das ist das Pendant zu stpcpy. Die + * beiden Strings duerfen sich nicht ueberlappen. Das abschliessende L'0' wird + * mitkopiert. + * + * @see stpcpy + * @see wcscpy + * @see wcpncpy + * @param dst Zeiger auf die Speicherstelle in die der Kopiertestring abgelegt + * werden soll. Dabei muss vom Aufrufer sichergestellt werden, dass + * dort mindestens speicher fuer wcslen(src) + 1 breite Zeichen ist. + * @param src + * + * @return Zeiger auf das Ende (L'0') des Zielstrings. + */ +wchar_t* wcpcpy(wchar_t* dst, const wchar_t* src) +{ + for (; (*dst = *src); ++src, ++dst) { } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcpncpy.c b/src/modules/lib/stdlibc/wstring/wcpncpy.c new file mode 100644 index 0000000..b04be05 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcpncpy.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2009 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/** + * String aus breiten Zeichen kopieren. Dabei werden hoechstens len Zeichen + * kopiert. Sind in src weniger als len Zeichen wird dst mit L'\0' aufgefuellt. + * Ist src laenger als oder gleich lang wie len wird der String in dst nich + * nullterminiert, der Rueckgabewert zeigt also nich auf ein L'\0'. Die beiden + * Speicherbereiche duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcpncpy + * @param dst Zeiger auf den Speicherbereich der len breite Zeichen aufnehmen + * kann. Es werden genau len Zeichen hineingeschrieben. + * @param src Quellstring + * @param len Anzahl der Zeichen, die in dst geschrieben werden sollen. + * + * @return Zeiger auf das letzte geschriebene Byte, also immer dst + len - 1 + */ +wchar_t* wcpncpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + for (; len--; dst++, src++) { + if (!(*dst = *src)) { + wchar_t *ret = dst; + while (len--) { + *++dst = L'\0'; + } + return ret; + } + } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscasecmp.c b/src/modules/lib/stdlibc/wstring/wcscasecmp.c new file mode 100644 index 0000000..32bc3a5 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscasecmp.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2009 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen inklusive abschliessendes L'\0'. Diese + * Funktion ist das Pendant zu strcasecmp. + * + * @see strcasecmp + * @see wcscmp + * @see towlower + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscasecmp(const wchar_t* wcs1, const wchar_t* wcs2) +{ + wchar_t wc1, wc2; + + for (; *wcs1; wcs1++, wcs2++) { + wc1 = towlower(*wcs1); + wc2 = towlower(*wcs2); + if (wc1 != wc2) { + return (int) (wc1 - wc2); + } + } + + return -*wcs2; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscat.c b/src/modules/lib/stdlibc/wstring/wcscat.c new file mode 100644 index 0000000..a6e3917 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscat.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include + + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei wird der Inhalt von + * src inklusive dem abschliessenden L'\0' ans Ende von dst kopiert. Der + * Aufrufer muss sicherstellen, dass nach dst genug Speicher frei ist. Diese + * Funktion ist das Pendant zu strcat. + * + * @see strcat + * @see wcsncat + * @param dst Zeiger auf den String an dessen Ende src angehaengt werden soll. + * @param src Zeiger auf den String der an dst angehaengt werden soll. + * + * @return dst + */ +wchar_t* wcscat(wchar_t* dst, const wchar_t* src) +{ + wchar_t* wcp; + + wcp = dst; + while (*wcp != L'\0') { + wcp++; + } + while ((*wcp++ = *src++) != L'\0') { } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcschr.c b/src/modules/lib/stdlibc/wstring/wcschr.c new file mode 100644 index 0000000..d5a49c9 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcschr.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + + +/** + * Erstes Vorkommen eines breiten Zeichens aus einem String aus breiten Zeichen + * heraussuchen. Diese Funktion ist das Pendant zu strchr. + * + * @see strchr + * @param wcs Zeiger auf den String in dem gesucht werden soll. + * @param wc Zeichen das gesucht werden soll. + * + * @return Zeiger auf das erste gefundene Zeichen oder NULL wenn keines gefunden + * wurde. + */ +wchar_t* wcschr(const wchar_t* wcs, wchar_t wc) +{ + while (*wcs != wc && *wcs != L'\0') { + wcs++; + } + + if (*wcs == wc) { + return (wchar_t*) wcs; + } + + return NULL; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscmp.c b/src/modules/lib/stdlibc/wstring/wcscmp.c new file mode 100644 index 0000000..a156009 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscmp.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + + +/** + * Zwei Strings aus breiten Zeichen inklusive dem abschliessenden L'\0' + * vergleichen. Diese Funktion ist das Pendant zu strcmp. + * + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscmp(const wchar_t* wcs1, const wchar_t* wcs2) +{ + while (*wcs1 == *wcs2++) { + if (*wcs1++ == L'\0') { + return 0; + } + } + + return (*(unsigned int *)wcs1 - *(unsigned int *)--wcs2); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscoll.c b/src/modules/lib/stdlibc/wstring/wcscoll.c new file mode 100644 index 0000000..8f0ce49 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscoll.c @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + + +/** + * TODO + */ +int wcscoll(const wchar_t* wcs1, const wchar_t* wcs2) +{ + return wcscmp(wcs1, wcs2); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscpy.c b/src/modules/lib/stdlibc/wstring/wcscpy.c new file mode 100644 index 0000000..c25fb53 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscpy.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp + */ + +#include + + +/** + * String aus Breiten Zeichen inklusive abschliessendem L'\0' kopieren. Der + * Aufrufer hat sicherzustellen, dass dst genug Platz bietet. Die beiden Strings + * duerfen sich nicht uberlappen. Diese Funktion ist das Pendant zu strcpy. + * + * @see strcpy + * @see wcsncpy + * @see wcpcpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den String der kopiert werden soll. + * + * @return dst + */ +wchar_t* wcscpy(wchar_t* dst, const wchar_t* src) +{ + wchar_t* wcp; + + wcp = dst; + while ((*wcp++ = *src++) != L'\0') { } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscspn.c b/src/modules/lib/stdlibc/wstring/wcscspn.c new file mode 100644 index 0000000..45f8023 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscspn.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include + + +/** + * String aus breiten Zeichen nach einem Vorkommen eines Zeichens aus set + * durchsuchen. Diese Funktion ist das Pendant zu strcspn. + * + * @see strcspn + * @see wcsspn + * @param wcs Zeiger auf den String, dar durchsucht werden soll + * @param set Zeiger auf den String mit den zu suchenden Zeichen. + * + * @return Offset vom Anfang des Strings oder wcslen(wcs) wenn kein Vorkommen + * gefunden wurde. + */ +size_t wcscspn(const wchar_t* wcs, const wchar_t* set) +{ + const wchar_t* p; + const wchar_t* q; + + p = wcs; + while (*p) { + q = set; + while (*q) { + if (*p == *q) { + goto done; + } + q++; + } + p++; + } + +done: + return (p - wcs); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsdup.c b/src/modules/lib/stdlibc/wstring/wcsdup.c new file mode 100644 index 0000000..2f94511 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsdup.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2005 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +/** + * String aus breiten Zeichen in einen neu allozierten Speicherbereich kopieren. + * Diese Funktion ist das Pendant zu strdup. + * + * @see strdup + * @param wcs Zeiger auf den zu kopierenden String + * + * @return Zeiger auf die Kopie. Muss vom Aufrufer freigegeben werden. Im + * Fehlerfall NULL. + */ +wchar_t* wcsdup(const wchar_t* wcs) +{ + wchar_t* copy; + size_t len; + + len = wcslen(wcs) + 1; + if ((copy = malloc(len * sizeof(wchar_t))) == NULL) { + return NULL; + } + + return wmemcpy(copy, wcs, len); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcslcat.c b/src/modules/lib/stdlibc/wstring/wcslcat.c new file mode 100644 index 0000000..85bc8e4 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcslcat.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp + */ + +#include + + +/** + * Kopiert src an das Ende des Strings dst. Dabei wird der String dst auf + * maximal len - 1 Zeichen und L'\0' verlaengert, ausser wenn len == 0. + * + * @see wcsncat + * @param dst Zeiger auf String an den src angehaengt werden soll + * @param src Zeiger auf String der an dst angehaengt werden soll + * @param len Anzahl Zeichen auf die dst Maximal verlaengert werden darf + * inklusiv L'\0.' + * + * @return wcslen(urspruengliches dst) + wcslen(src); Wenn der Rueckgabewert >= + * len ist, wurde src nich vollstaendig kopiert. + */ +size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t len) +{ + wchar_t* d = dst; + const wchar_t* s = src; + size_t n = len; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != L'\0' && n-- != 0) { + d++; + } + dlen = d - dst; + n = len - dlen; + + if (n == 0) { + return(dlen + wcslen(s)); + } + while (*s != L'\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = L'\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} + diff --git a/src/modules/lib/stdlibc/wstring/wcslcpy.c b/src/modules/lib/stdlibc/wstring/wcslcpy.c new file mode 100644 index 0000000..a172f96 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcslcpy.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp + */ + +#include + + +/** + * Kopiert einen String aus breiten Zeichen. Dabei werden maximal len - 1 + * Zeichen kopiert, und dst wird immer mit L'\0' terminiert, wenn len != 0 ist. + * + * @see wcscpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den Quellstring + * @param len Anzahl der Zeichen inklusiv abschliessendes L'\0', die maximal in + * dst geschrieben werden sollen. + * + * @return wcslen(src); Wenn der Rueckgabewert <= len ist, wurde src nicht + * vollstaendig kopiert. + */ +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + wchar_t* d = dst; + const wchar_t* s = src; + size_t n = len; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) { + break; + } + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (len != 0) { + *d = '\0'; /* NUL-terminate dst */ + } + while (*s++) { } + } + + return(s - src - 1); /* count does not include NUL */ +} + diff --git a/src/modules/lib/stdlibc/wstring/wcslen.c b/src/modules/lib/stdlibc/wstring/wcslen.c new file mode 100644 index 0000000..1d80076 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcslen.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include + + +/** + * Laenge eines Strings aus breiten Zeichen bestimmen. Dabei werden die Zeichen + * gezaehlt, bis ein abschliessendes L'\0' gefunden wird. Das L'\0' wird nicht + * mitgezaehlt. Diese Funktion ist das Pendant zu strlen. + * + * @see strlen + * @param wcs Zeiger auf den String + * + * @return Laenge des Strings in Zeichen + */ +size_t wcslen(const wchar_t* wcs) +{ + const wchar_t* p; + + p = wcs; + while (*p) { + p++; + } + + return p - wcs; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncasecmp.c b/src/modules/lib/stdlibc/wstring/wcsncasecmp.c new file mode 100644 index 0000000..05ecb5b --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncasecmp.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2009 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen. Dabei werden maximal die ersten len + * Zeichen von Beiden Strings verglichen. Diese Funktion ist das Pendant zu + * strncasecmp. + * + * @see strncasecmp + * @see wcscasecmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein L'\0' gefunden wird. + * + * @return 0 wenn die beiden Strings gleich sind, < 0 wenn das Zeichen in wcs2 + * groesser ist als das in wcs1 und > 0 wenn das Zeichen in wcs1 + * groesser ist als das in wcs2. + */ +int wcsncasecmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len) +{ + wchar_t wc1, wc2; + + if (len == 0) { + return 0; + } + + for (; *wcs1; wcs1++, wcs2++) { + wc1 = towlower(*wcs1); + wc2 = towlower(*wcs2); + if (wc1 != wc2) { + return ((int) wc1 - wc2); + } + + if (--len == 0) { + return 0; + } + } + + return -*wcs2; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncat.c b/src/modules/lib/stdlibc/wstring/wcsncat.c new file mode 100644 index 0000000..874866e --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncat.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include + + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei werden maximal len + * Zeichen aus src kopiert. Der Aufrufer muss sicherstellen, dass nach dem + * String, auf den dst zeigt, noch mindestens len + 1 Zeichen platz haben. dst + * wird in jedem Fall mit L'\0' terminiert. Diese Funktion ist das Pendant zu + * strncat. + * + * @see strncat + * @see wcscat + * @param dst String an den src angehaengt werden soll + * @param src String der an dst angehaengt werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden aus src + * + * @return dst + */ +wchar_t* wcsncat(wchar_t* dst, const wchar_t* src, size_t len) +{ + wchar_t* p; + wchar_t* q; + const wchar_t* r; + + p = dst; + while (*p) { + p++; + } + + q = p; + r = src; + while (*r && len) { + *q++ = *r++; + len--; + } + *q = '\0'; + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncmp.c b/src/modules/lib/stdlibc/wstring/wcsncmp.c new file mode 100644 index 0000000..bc37bab --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncmp.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + + +/** + * Zwei Strings aus breiten Zeichen vergleichen. Dabei werden maximal len + * Zeichen verglichen. Diese Funktion ist das Pendant zu strncmp. + * + * @see strncmp + * @see wcscmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein abschliessendes L'\0' angetroffen wurde. + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcsncmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len) +{ + + if (len == 0) { + return 0; + } + + do { + if (*wcs1 != *wcs2++) { + /* XXX assumes wchar_t = int */ + return (*(unsigned int*)wcs1 - *(unsigned int*)--wcs2); + } + + if (*wcs1++ == 0) { + break; + } + } while (--len != 0); + return 0; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncpy.c b/src/modules/lib/stdlibc/wstring/wcsncpy.c new file mode 100644 index 0000000..9bad4dc --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncpy.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + + +/** + * String aus breiten Zeichen kopieren. Dabei werden maximal len Zeichen + * kopiert. Die restlichen Zeichen im Puffer werden mit L'\0' gefuellt. Ist src + * gleich lang wie oder laenger als len, wird dst nicht mit L'\0' terminiert. + * Die beiden Strings duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcscpy + * @param src String der kopiert werden soll + * @param dst Zeiger auf den Speicherbereich in den src kopiert werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden sollen + * + * @return dst + */ +wchar_t* wcsncpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + if (len != 0) { + wchar_t* d = dst; + const wchar_t* s = src; + + do { + if ((*d++ = *s++) == L'\0') { + /* NUL pad the remaining n-1 bytes */ + while (--len != 0) { + *d++ = L'\0'; + } + break; + } + } while (--len != 0); + } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsnlen.c b/src/modules/lib/stdlibc/wstring/wcsnlen.c new file mode 100644 index 0000000..07c09a9 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsnlen.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2009 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + + +/** + * Laenge eines Strings aus breiten Zeichen errechnen. Dabei werden maximal max + * Zeichen gezaehlt. Diese Funktion ist das Pendant zu strnlen. + * + * @see strnlen + * @see wcslen + * @param wcs String + * @param max Anzahl der Zeichen, die maximal gezaehlt werden sollen + * + * @return Anzahl der Zeichen ohne abschliessendes L'\0' + */ +size_t wcsnlen(const wchar_t* wcs, size_t max) +{ + size_t len; + + for (len = 0; len < max; len++, wcs++) { + if (!*wcs) { + break; + } + } + + return len; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcspbrk.c b/src/modules/lib/stdlibc/wstring/wcspbrk.c new file mode 100644 index 0000000..bc9c594 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcspbrk.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp + */ + +#include + + +/** + * Erstes vorkommen eines breiten Zeichens aus set im String aus breiten Zeichen + * wcs suchen. Diese Funktion ist das Pendant zu strpbrk. + * + * @see strpbrk + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set String aus Zeichen nach denen gesucht werden soll + * + * @return Zeiger auf die Position an der ein Zeichen gefunden wurde oder NULL + * falls keines gefunden wurde. + */ +wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* set) +{ + const wchar_t* p; + const wchar_t* q; + + p = wcs; + while (*p) { + q = set; + while (*q) { + if (*p == *q) { + /* LINTED interface specification */ + return (wchar_t*) p; + } + q++; + } + p++; + } + + return NULL; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsrchr.c b/src/modules/lib/stdlibc/wstring/wcsrchr.c new file mode 100644 index 0000000..23d3a65 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsrchr.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + + +/** + * Letztes Vorkommen eines breiten Zeichens in einem String aus breiten Zeichen + * suchen. Diese Funktion ist das Pendant zu strrchr. + * + * @see strrchr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param wc Zeichen das gesucht werden soll + * + * @return Zeiger auf das letzte gefundene Vorkommen, oder NULL falls das + * Zeichen nicht gefunden wurde. + */ +wchar_t* wcsrchr(const wchar_t* wcs, wchar_t wc) +{ + const wchar_t* last; + + last = NULL; + for (;;) { + if (*wcs == wc) { + last = wcs; + } + + if (*wcs == L'\0') { + break; + } + wcs++; + } + + return ((wchar_t*) last); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsspn.c b/src/modules/lib/stdlibc/wstring/wcsspn.c new file mode 100644 index 0000000..398af6f --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsspn.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcsspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include + + +/** + * Durchsucht einen String aus breiten Zeichen nach dem ersten Zeichen das nicht + * in set vorkommt. Diese Funktion ist das Pendant zu strspn. + * + * @see strspn + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set Zeichen die zugelassen sind + * + * @return Offset des ersten Zeichens das nicht in set vorkommt, oder + * wcslen(wcs) falls alle Zeichen in set enthalten sind. + */ +size_t wcsspn(const wchar_t* wcs, const wchar_t* set) +{ + const wchar_t* p; + const wchar_t* q; + + p = wcs; + while (*p) { + q = set; + while (*q) { + if (*p == *q) { + break; + } + q++; + } + if (!*q) { + goto done; + } + p++; + } + +done: + return (p - wcs); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsstr.c b/src/modules/lib/stdlibc/wstring/wcsstr.c new file mode 100644 index 0000000..5e8357c --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsstr.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/** + * Erstes Vorkommen des Breiten Strings find in wcs suchen. Diese Funktion ist + * das Pendant zu strstr. + * + * @see strstr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param find String der gesucht werden soll + * + * @return Zeiger auf das erste Vorkommen in wcs oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wcsstr(const wchar_t* wcs, const wchar_t* find) +{ + wchar_t c, sc; + size_t len; + + if ((c = *find++) != L'\0') { + len = wcslen(find); + do { + do { + if ((sc = *wcs++) == L'\0') { + return NULL; + } + } while (sc != c); + } while (wcsncmp(wcs, find, len) != 0); + wcs--; + } + + return ((wchar_t*) wcs); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcstok.c b/src/modules/lib/stdlibc/wstring/wcstok.c new file mode 100644 index 0000000..e067ee9 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcstok.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notices, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notices, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE + * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + + +/** + * String aus breiten Zeichen in Tokens aufspalten, die durch die in delim + * angegebenen Zeichen getrennt werden. wcs wird dabei veraendert. Ist wcs != + * NULL beginnt die suche dort, sonst wird bei *last begonnen. *last wird + * jeweils auf den Anfang des naechsten Token gesetzt, oder auf NULL, wenn das + * Ende erreicht wurde. + * Diese Funktion ist das Pendant zu strtok. + * + * @see strtok + * @param wcs Zeiger auf das Zeichen bei dem die Zerlegung in Tokens begonnen + * werden soll, oder NULL, wenn der Wert von *last genommen werden + * soll. + * @param delim Zeichen die zwei Tokens voneinander trennen koennen + * @param last Zeiger auf die Speicherstelle an der die Funktion die Position + * des naechsten token speichern kann fuer den internen Gebrauch, + * um beim Naechsten Aufruf mit wcs == NULL das naechste Token + * zurueck geben zu koennen. + * + * @return Zeiger auf das aktuelle Token, oder NULL wenn keine Tokens mehr + * vorhanden sind. + */ +wchar_t* wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** last) +{ + const wchar_t* spanp; + wchar_t* tok; + wchar_t c, sc; + + if (wcs == NULL && (wcs = *last) == NULL) { + return NULL; + } + + /* + * Skip (span) leading delimiters (wcs += wcsspn(wcs, delim), sort of). + */ +cont: + c = *wcs++; + for (spanp = delim; (sc = *spanp++) != L'\0';) { + if (c == sc) { + goto cont; + } + } + + if (c == L'\0') { /* no non-delimiter characters */ + *last = NULL; + return NULL; + } + tok = wcs - 1; + + /* + * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *wcs++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == L'\0') { + wcs = NULL; + } else { + wcs[-1] = L'\0'; + } + *last = wcs; + + return tok; + } + } while (sc != L'\0'); + } + /* NOTREACHED */ +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemchr.c b/src/modules/lib/stdlibc/wstring/wmemchr.c new file mode 100644 index 0000000..481ccdc --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemchr.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include + + +/** + * Speicherbereich aus breiten Zeichen nach einem bestimmten Zeichen + * durchsuchen. Diese Funktion ist das Pendant zu memchr. + * + * @see memchr + * @see wcschr + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zu suchendes Zeichen + * @param len Laenge des Speicherbereichs + * + * @return Zeiger auf das gefundene Zeichen oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wmemchr(const wchar_t* wcs, wchar_t wc, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) { + if (*wcs == wc) { + /* LINTED const castaway */ + return (wchar_t*) wcs; + } + wcs++; + } + + return NULL; +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemcmp.c b/src/modules/lib/stdlibc/wstring/wmemcmp.c new file mode 100644 index 0000000..c8412e7 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemcmp.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include + + +/** + * Zwei Speicherbereiche aus breiten Zeichen vergleichen. Diese Funktion ist das + * Pendant zu memcmp. + * + * @see memcmp + * @see wcscpm + * @see wcsncmp + * @param wcs1 Zeiger auf den ersten Speicherbereich + * @param wcs2 Zeiger auf den zweiten Speicherbereich + * @param len Laenge der beiden Speicherbereiche + * + * @return 0 wenn die beiden Speicherbereiche gleich sind, < 0 wenn das erste + * unterschiedliche Zeichen in wcs1 kleiner ist als das + * Korrespondierende in wcs2 oder > 0 wenn es groesser ist. + */ +int wmemcmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) { + if (*wcs1 != *wcs2) { + /* wchar might be unsigned */ + return *wcs1 > *wcs2 ? 1 : -1; + } + + wcs1++; + wcs2++; + } + return 0; +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemcpy.c b/src/modules/lib/stdlibc/wstring/wmemcpy.c new file mode 100644 index 0000000..072c5f4 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemcpy.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#include + + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich nicht ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memcpy + * @see wcsncpy + * @see wcscpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemcpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + return (wchar_t*) memcpy(dst, src, len * sizeof(wchar_t)); +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemmove.c b/src/modules/lib/stdlibc/wstring/wmemmove.c new file mode 100644 index 0000000..8da074d --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemmove.c @@ -0,0 +1,49 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#include + + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memmove + * @see wmemcpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t len) +{ + return (wchar_t*) memmove(dst, src, len * sizeof(wchar_t)); +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemset.c b/src/modules/lib/stdlibc/wstring/wmemset.c new file mode 100644 index 0000000..e45ab60 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemset.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include + + +/** + * Speicherbereich aus breiten Zeichen mit einem bestimmten Zeichen ausfuellen. + * Diese Funktion ist das pendant zu memset. + * + * @see memset + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zeichen mit dem der Speicherbereich gefuellt werden soll + * @param len Laenge des Speicherbereichs + * + * @return wcs + */ +wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t len) +{ + size_t i; + wchar_t* p; + + p = wcs; + for (i = 0; i < len; i++) { + *p = wc; + p++; + } + + return wcs; +} + -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:25:49 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:25:49 +0200 Subject: [tyndur-devel] [PATCH] Buildsystem: make clean macht jetzt etwas cleaner Message-ID: <1240673149-19887-1-git-send-email-toni@tyndur.org> * buildmk.sh: Bei make clean auch *.ppu und den anderen Kram vom fpc loeschen. Auch versuchen eine Datei zu loeschen die gleich heisst wie das Verzeichnis, um auch bei Applikationen ohne .mod sauber zu machen. --- buildmk.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/buildmk.sh b/buildmk.sh index 143b498..5ea44df 100644 --- a/buildmk.sh +++ b/buildmk.sh @@ -222,7 +222,7 @@ done cat <> Makefile clean: - rm -f *.o *.a *.mod + rm -f *.o *.a *.mod *.ppu link.res ppas.sh `basename \`pwd\`` for file in *; do if [ -f "\$\$file/Makefile" -a \( ! -f "\$\$file/.nobuild" -o -f "\$\$file/.ignorenobuild" \) ]; then \$(MAKE) -sC "\$\$file" clean; rm "\$\$file/Makefile"; fi done .SILENT: all makefiles subdirs obj clean clean_root updateroot image-floppy image-hd test-qemu test-qemu-hd -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:26:49 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:26:49 +0200 Subject: [tyndur-devel] [PATCH] servmgr: Fix fuer uninitialisierte Variable Message-ID: <1240673209-20058-1-git-send-email-toni@tyndur.org> ! servmgr: Wenn man in buffer_replace die Variable len initialisiert, laesst sich das dann auch mit -O2 kompilieren. Signed-off-by: Antoine Kaufmann --- src/modules/servmgr/config.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/modules/servmgr/config.c b/src/modules/servmgr/config.c index 0ca4f73..c722e41 100644 --- a/src/modules/servmgr/config.c +++ b/src/modules/servmgr/config.c @@ -62,6 +62,7 @@ static void buffer_replace(char** buf, const char* search, const char* replace) char* new; int found = 0; + len = 0; for (i = 0; i < strlen(old); i++) { if (!strncmp(old + i, search, search_len)) { len += replace_len; -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:28:06 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:28:06 +0200 Subject: [tyndur-devel] [PATCH] libc: readline() multibyte-kompatibel machen Message-ID: <1240673286-20223-1-git-send-email-toni@tyndur.org> * libc: readline() kommt jetzt auch mit Zeichen klar, die mehr als ein Byte in Anspruch nehmen (z.B. UTF-8). --- src/modules/lib/readline.c | 111 +++++++++++++++++++++++++++++++------------ 1 files changed, 80 insertions(+), 31 deletions(-) diff --git a/src/modules/lib/readline.c b/src/modules/lib/readline.c index 5c7fab0..97242d5 100644 --- a/src/modules/lib/readline.c +++ b/src/modules/lib/readline.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -53,13 +54,13 @@ char* rl_line_buffer; * @return Das eingelesene Zeichen oder NULL, wenn das Ende der Eingabedatei * erreicht ist. */ -static char keyboard_read_char(void) +static wint_t keyboard_read_char(void) { - char c = 0; - - while (!fread(&c, 1, 1, stdin)) { + wint_t c = 0; + + while ((c = fgetwc(stdin)) == WEOF) { if (feof(stdin)) { - return 0; + return WEOF; } } @@ -69,42 +70,94 @@ static char keyboard_read_char(void) /** * Loescht ein Zeichen aus dem Puffer */ -static void delchar(char* buffer, int pos) +static void delchar(char* buffer, int pos, int* size) { int i; size_t len = strlen(buffer); + int clen; if (len < pos) { return; } - for (i = pos; i < BUFFER_SIZE - 1; i++) { - buffer[i] = buffer[i + 1]; + clen = mblen(buffer + pos, len - pos + 1); + for (i = pos; i < BUFFER_SIZE - clen; i++) { + buffer[i] = buffer[i + clen]; if (buffer[i] == '\0') { break; } } - buffer[BUFFER_SIZE - 1] = '\0'; + buffer[BUFFER_SIZE - clen] = '\0'; + *size -= clen; } /** * Fuegt ein Zeichen in den Buffer ein */ -static void inschar(char* buffer, int pos, char c) +static void inschar(char* buffer, int* pos, int* size, wint_t c) { int i; size_t len = strlen(buffer); + char mbbuf[MB_CUR_MAX]; + int clen; + - if ((len < pos) || (len + 1 >= BUFFER_SIZE)) { + clen = wctomb(mbbuf, c); + if ((len < *pos) || (len + clen >= BUFFER_SIZE) || (clen == -1)) { return; } - for (i = len + 1; i > pos; i--) { - buffer[i] = buffer[i - 1]; + for (i = len + clen; i > *pos; i--) { + buffer[i] = buffer[i - clen]; + } + + memcpy(buffer + *pos, mbbuf, clen); + + *pos += clen; + *size += clen; +} + +/** + * Veraendert die Pufferposition; positiv => rechts, negativ => links + */ +static void move_cursor(char* buffer, int* pos, int size, int offset) +{ + int clen; + + if (offset > 0) { + // Rechts + if ((clen = mblen(buffer + *pos, size - *pos + 1)) > 0) { + *pos += clen; + } + } else { + // Links, bis wir ein ganzes Zeichen haben + while (--(*pos) && (mblen(buffer + *pos, size - *pos + 1) == -1)) { } + } +} + +/** + * Zaehlt die Anzahl der angezeigten Zeichen im Puffer + * + * @param start Position von der angefangen werden soll zu zaehlen + * @param size Anzahl Zeichen im Puffer + */ +static int count_visible_chars(char* buffer, int start, int size) +{ + int clen; + int count = 0; + + while ((start < size)) { + if ((clen = mblen(buffer + start, size - start + 1)) == -1) { + // Unvollstaendiges MB-Zeichen wird uebersprungen + start++; + } else { + count++; + start += clen; + } } - buffer[pos] = c; + return count; } /** @@ -253,10 +306,10 @@ char* readline(const char* prompt) pos = size = 0; while (!enter) { - char c = keyboard_read_char(); + wint_t c = keyboard_read_char(); switch (c) { - + case WEOF: case '\0': c = keyboard_read_char(); enter = TRUE; @@ -283,7 +336,7 @@ char* readline(const char* prompt) if (pos > 0) { printf("\033[1D"); fflush(stdout); - pos--; + move_cursor(buffer, &pos, size, -1); } break; @@ -292,7 +345,7 @@ char* readline(const char* prompt) if (pos < size) { printf("\033[1C"); fflush(stdout); - pos++; + move_cursor(buffer, &pos, size, 1); } break; @@ -338,8 +391,7 @@ char* readline(const char* prompt) } if (pos < size) { - delchar(buffer, pos); - size--; + delchar(buffer, pos, &size); printf("\033[K\033[s%s\033[u", &buffer[pos]); fflush(stdout); } @@ -349,17 +401,16 @@ char* readline(const char* prompt) // Pos1 case 'H': - printf("\033[%dD", pos); + printf("\033[%dD", count_visible_chars(buffer, 0, pos)); pos = 0; fflush(stdout); break; // Ende case 'F': - printf("\033[%dC", strlen(buffer) - pos); + printf("\033[%dC", + count_visible_chars(buffer, pos, size)); pos = strlen(buffer); - delchar(buffer, pos); - printf("\033[K\033[s%s\033[u", &buffer[pos]); fflush(stdout); break; @@ -377,9 +428,8 @@ seq_nomatch: case '\b': if (pos > 0) { - pos--; - size--; - delchar(buffer, pos); + move_cursor(buffer, &pos, size, -1); + delchar(buffer, pos, &size); printf("\033[1D\033[K\033[s%s\033[u", &buffer[pos]); fflush(stdout); } @@ -414,10 +464,9 @@ seq_nomatch: default: if (pos < BUFFER_SIZE - 1) { - inschar(buffer, pos, c); - printf("\033[K\033[s%s\033[u\033[1C", &buffer[pos]); - pos++; - size++; + int old_pos = pos; + inschar(buffer, &pos, &size, c); + printf("\033[K\033[s%s\033[u\033[1C", &buffer[old_pos]); fflush(stdout); } break; -- 1.6.0.6 From toni at tyndur.org Sat Apr 25 17:43:23 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:43:23 +0200 Subject: [tyndur-devel] [PATCH 5/5] libc: POSIX: uname() In-Reply-To: <1240424297-4863-6-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> <1240424297-4863-6-git-send-email-kevin@tyndur.org> Message-ID: <20090425154323.GA14585@einstein.produktiv.lan> On Wed, Apr 22 20:18, Kevin Wolf wrote: > + libc: POSIX: uname() > --- > src/include/lost/config.h | 9 ++++++ > src/modules/include/sys/utsname.h | 52 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 61 insertions(+), 0 deletions(-) > create mode 100644 src/modules/include/sys/utsname.h > > diff --git a/src/include/lost/config.h b/src/include/lost/config.h > index 67cf7cc..25794af 100644 > --- a/src/include/lost/config.h > +++ b/src/include/lost/config.h > @@ -74,5 +74,14 @@ > #define CONFIG_LIBC_NO_STUBS > > > +#define TYNDUR_VERSION "0.2.1" > +#if CONFIG_ARCH == ARCH_I386 > + #define TYNDUR_ARCH "i386" > +#elif CONFIG_ARCH == ARCH_AMD64 > + #define TYNDUR_ARCH "amd64" > +#else > + #error Unbekannte Architektur > +#endif > + > #endif // _CONFIG_H_ > > diff --git a/src/modules/include/sys/utsname.h b/src/modules/include/sys/utsname.h > new file mode 100644 > index 0000000..7b53d53 > --- /dev/null > +++ b/src/modules/include/sys/utsname.h > @@ -0,0 +1,52 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > +#ifndef _SYS_UTSNAME_H_ > +#define _SYS_UTSNAME_H_ > + > +#include > + > +struct utsname { > + char sysname[32]; > + char nodename[32]; > + char release[32]; > + char version[32]; > + char machine[32]; > +}; > + > +static int uname(struct utsname* utsname) > +{ > + strcpy(utsname->sysname, "tyndur"); > + strcpy(utsname->nodename, "tyndur"); > + strcpy(utsname->release, "Gothmog"); Packen wir den vielleicht nich besser auch in ein Config-Makro? Sonst vergessen wir das garantiert bei weiteren Releases. ;-) > + strcpy(utsname->version, TYNDUR_VERSION); > + strcpy(utsname->machine, TYNDUR_ARCH); > + > + return 0; > +} > + > +#endif Sieht sonst gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 25 17:54:24 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:54:24 +0200 Subject: [tyndur-devel] [PATCH 4/5] libc: POSIX: Mehr Signale In-Reply-To: <1240424297-4863-5-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> <1240424297-4863-5-git-send-email-kevin@tyndur.org> Message-ID: <20090425155424.GB14585@einstein.produktiv.lan> On Wed, Apr 22 20:18, Kevin Wolf wrote: > + libc: POSIX: Signale blockieren mit sigprocmask() > ! libc: POSIX: raise() setzt errno, wenn es -1 zurueckgibt > --- > src/modules/include/signal.h | 20 +++++++++++++- > src/modules/lib/posix/signal.c | 59 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 78 insertions(+), 1 deletions(-) > > diff --git a/src/modules/include/signal.h b/src/modules/include/signal.h > index 364cd67..ab67d88 100644 > --- a/src/modules/include/signal.h > +++ b/src/modules/include/signal.h > @@ -146,6 +146,12 @@ struct sigaction { > int sa_flags; > }; > > +enum { > + SIG_BLOCK, > + SIG_UNBLOCK, > + SIG_SETMASK, > +}; > + > > /** > * Aendert die auszufuehrende Aktion fuer ein Signal und gibt die alte Aktion > @@ -158,9 +164,21 @@ struct sigaction { > */ > int sigaction(int sig, const struct sigaction* action, struct sigaction* old); > > -/// Einen Signal-Hander aendern > +/// Einen Signal-Handler aendern > sighandler_t signal(int signum, sighandler_t handler); > > +/** > + * Verwaltung von blockierten Signalen > + * > + * @param mode SIG_BLOCK: Alle Signale aus sigset blockieren > + * SIG_UNBLOCK: Alle Signale aus sigset wieder aktivieren > + * SIG_SETMASK: sigset als neue Signal-Maske benutzen > + * > + * @return 0 bei Erfolg. -1 und errno = EINVAL, wenn mode einen unerlaubten > + * Wert hat. > + */ > +int sigprocmask(int mode, const sigset_t* sigset, sigset_t* oldset); > + > /// Ein Signal zum aktuellen Prozess senden > int raise(int signal); > > diff --git a/src/modules/lib/posix/signal.c b/src/modules/lib/posix/signal.c > index 03cfb56..e35064d 100644 > --- a/src/modules/lib/posix/signal.c > +++ b/src/modules/lib/posix/signal.c > @@ -38,6 +38,7 @@ > > /// Array mit Pointern auf die Signal-Handler > static struct sigaction sigactions[_SIGNO_MAX]; > +static sigset_t sigmask; > static bool initialized = FALSE; > > /** > @@ -46,7 +47,10 @@ static bool initialized = FALSE; > static void init_signals(void) > { > int i; > + > memset(sigactions, 0, sizeof(sigactions)); > + memset(&sigmask, 0, sizeof(sigmask)); > + > for (i = 0; i < _SIGNO_MAX; i++) { > sigactions[i].sa_handler = SIG_DFL; > } > @@ -71,9 +75,16 @@ int raise(int signum) > // Wenn das Signal Groesser ist als die Groesste gueltige wird sofort > // abgebrochen. > if (signum >= _SIGNO_MAX) { > + errno = EINVAL; > return -1; > } > > + // Pruefen, ob das Signal nicht blockiert ist > + if (sigismember(&sigmask, signum)) { > + return 0; > + } > + > + // Handler aufrufen > sighandler_t handler = sigactions[signum].sa_handler; > if (handler != NULL) { > handler(signum); > @@ -290,6 +301,54 @@ int sigismember(const sigset_t *sigset, int signum) > } > > /** > + * Verwaltung von blockierten Signalen > + * > + * @param mode SIG_BLOCK: Alle Signale aus sigset blockieren > + * SIG_UNBLOCK: Alle Signale aus sigset wieder aktivieren > + * SIG_SETMASK: sigset als neue Signal-Maske benutzen Mit ein bisschen Einrückung wäre das doch viel lesbarer. ;-) > + * > + * @return 0 bei Erfolg. -1 und errno = EINVAL, wenn mode einen unerlaubten > + * Wert hat. > + */ > +int sigprocmask(int mode, const sigset_t* sigset, sigset_t* oldset) > +{ > + int i; > + > + if (oldset != NULL) { > + memcpy(oldset, &sigmask, sizeof(sigset_t)); Hm könnte man da nicht direkt zuweisen? > + } > + > + switch (mode) { > + case SIG_BLOCK: > + for (i = 0; i < _SIGNO_MAX; i++) { > + if (sigismember(sigset, i)) { > + sigaddset(&sigmask, i); > + } > + } > + break; > + > + case SIG_UNBLOCK: > + for (i = 0; i < _SIGNO_MAX; i++) { > + if (sigismember(sigset, i)) { > + sigdelset(&sigmask, i); > + } > + } > + break; > + > + case SIG_SETMASK: > + memcpy(&sigmask, sigset, sizeof(sigset_t)); > + break; > + > + default: > + errno = EINVAL; > + return -1; > + } > + > + return 0; > +} > + > + > +/** > * Callbackfunktion fuer alarm() > */ > static void do_alarm(void) Sieht sonst vernünftig aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 25 17:55:56 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 17:55:56 +0200 Subject: [tyndur-devel] [PATCH 3/5] libc: netinet/in.h zieht arpa/inet.h nach In-Reply-To: <1240424297-4863-4-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> <1240424297-4863-4-git-send-email-kevin@tyndur.org> Message-ID: <20090425155556.GC14585@einstein.produktiv.lan> On Wed, Apr 22 20:18, Kevin Wolf wrote: > * libc: Funktionen wie htons() gehoeren zwar eigentlich nach > arpa/inet.h, werden aber laut Manpage gelegentlich auch in > netinet/in.h erwartet - und mutt bestaetigt das. Klingt mal wieder nach gut durchdachtem Design. ;-) Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Sat Apr 25 17:57:35 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 17:57:35 +0200 Subject: [tyndur-devel] [PATCH] config: Terminalbezeichnung anpassen In-Reply-To: <1240672269-18604-1-git-send-email-toni@tyndur.org> References: <1240672269-18604-1-git-send-email-toni@tyndur.org> Message-ID: <200904251757.35984@kevin-wolf.de> Am Samstag, 25. April 2009 17:11 schrieb Antoine Kaufmann: > * config: Terminalbezeichnung von lost auf tyndur aendern Ack From mail at kevin-wolf.de Sat Apr 25 18:07:05 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 18:07:05 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: Interrupthandlern die Int-Nummer uebergeben In-Reply-To: <1240672054-18390-2-git-send-email-toni@tyndur.org> References: <1240672054-18390-1-git-send-email-toni@tyndur.org> <1240672054-18390-2-git-send-email-toni@tyndur.org> Message-ID: <200904251807.05862@kevin-wolf.de> Am Samstag, 25. April 2009 17:07 schrieb Antoine Kaufmann: > * libc: Interrupthandler kriegen jetzt die Interruptnummer als Parameter > uebergeben. > * floppy, kbc, cdi/core: Notwendige Aenderungen damit das kompiliert uint8_t statt byte wäre schöner. Sonst Ack. From toni at tyndur.org Sat Apr 25 18:07:41 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 18:07:41 +0200 Subject: [tyndur-devel] [PATCH 2/5] libc: POSIX: getservbyname() In-Reply-To: <1240424297-4863-3-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> <1240424297-4863-3-git-send-email-kevin@tyndur.org> Message-ID: <20090425160741.GD14585@einstein.produktiv.lan> On Wed, Apr 22 20:18, Kevin Wolf wrote: > + libc: POSIX: getservbyname(). Die Service-Datenbank ist vorerst in der > libc hartkodiert. Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Apr 25 18:12:30 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Apr 2009 18:12:30 +0200 Subject: [tyndur-devel] [PATCH 1/5] libc: POSIX: sigaction In-Reply-To: <1240424297-4863-2-git-send-email-kevin@tyndur.org> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> <1240424297-4863-2-git-send-email-kevin@tyndur.org> Message-ID: <20090425161230.GE14585@einstein.produktiv.lan> On Wed, Apr 22 20:18, Kevin Wolf wrote: > + libc: POSIX: Signale von reinen Handler auf sigactions umgestellt (die > aber alles ausser dem Handler ignorieren). sigaction() hinzugefuegt. > --- > diff --git a/src/modules/lib/posix/signal.c b/src/modules/lib/posix/signal.c > index 4d70a61..03cfb56 100644 > --- a/src/modules/lib/posix/signal.c > +++ b/src/modules/lib/posix/signal.c > @@ -37,7 +37,7 @@ > #include > > /// Array mit Pointern auf die Signal-Handler > -static sighandler_t signal_handlers [_SIGNO_MAX]; > +static struct sigaction sigactions[_SIGNO_MAX]; > static bool initialized = FALSE; > > /** > @@ -46,8 +46,9 @@ static bool initialized = FALSE; > static void init_signals(void) > { > int i; > + memset(sigactions, 0, sizeof(sigactions)); > for (i = 0; i < _SIGNO_MAX; i++) { > - signal_handlers[i] = SIG_DFL; > + sigactions[i].sa_handler = SIG_DFL; > } > > initialized = TRUE; > @@ -73,7 +74,7 @@ int raise(int signum) > return -1; > } > > - sighandler_t handler = signal_handlers[signum]; > + sighandler_t handler = sigactions[signum].sa_handler; > if (handler != NULL) { > handler(signum); > } > @@ -150,14 +151,50 @@ sighandler_t signal(int signum, sighandler_t handler) > } > > // Alter Handler Speichern, weil er zurueck gegeben wird > - sighandler_t old_handler = signal_handlers[signum]; > + sighandler_t old_handler = sigactions[signum].sa_handler; > > // Neuer setzen > - signal_handlers[signum] = handler; > + sigactions[signum].sa_handler = handler; > > return old_handler; > } > > +/** > + * Aendert die auszufuehrende Aktion fuer ein Signal und gibt die alte Aktion > + * zurueck. > + * TODO Momentan nur Handler, POSIX sieht da mehr vor > + * > + * @param sig Nummer des Signals, fuer das die Aktion geaendert wird > + * @param action Neue Aktion. Wenn NULL, wird nur die aktuelle Aktion > + * zurueckgegeben, aber keine Aenderung vorgenommen > + * @param old Wenn nicht NULL, wird hier die alte Aktion gespeichert > + */ > +int sigaction(int sig, const struct sigaction* action, struct sigaction* old) > +{ > + // Initialisieren falls das noch nicht gemacht ist > + if (initialized == FALSE) { > + init_signals(); > + } > + > + // Ungueltige Signale und SIGKILL koennen nicht gesetzt werden > + if ((sig >= _SIGNO_MAX) || (sig == SIGKILL)) { > + errno = EINVAL; > + return -1; > + } > + > + // Alte Werte zurueckgeben > + if (old != NULL) { > + memcpy(old, &sigactions[sig], sizeof(*old)); > + } > + > + // Neue Werte setzen > + if (action != NULL) { > + memcpy(&sigactions[sig], action, sizeof(*action)); > + } Hier wäre jeweils auch kein memcpy nötig, oder irre ich mich? > + > + return 0; > +} Sonst Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Sat Apr 25 18:37:48 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 18:37:48 +0200 Subject: [tyndur-devel] [PATCH 2/3] cdi/core: Mehrere IRQ-Handler pro Treiber In-Reply-To: <1240672054-18390-3-git-send-email-toni@tyndur.org> References: <1240672054-18390-1-git-send-email-toni@tyndur.org> <1240672054-18390-3-git-send-email-toni@tyndur.org> Message-ID: <200904251837.48529@kevin-wolf.de> Am Samstag, 25. April 2009 17:07 schrieb Antoine Kaufmann: > ! cdi/core: Jetzt funktioniert das mit den IRQs auch, wenn man mal auf > absurde Idee kommt, mehrere IRQs in einem Treiber benutzen > zu wollen. ;-) > --- > src/modules/cdi/lib/misc.c | 34 +++++++++++++++++++++++++--------- > 1 files changed, 25 insertions(+), 9 deletions(-) > > diff --git a/src/modules/cdi/lib/misc.c b/src/modules/cdi/lib/misc.c > index 4a22f78..ae66a9e 100644 > --- a/src/modules/cdi/lib/misc.c > +++ b/src/modules/cdi/lib/misc.c > @@ -16,16 +16,26 @@ > #include "cdi.h" > #include "cdi/misc.h" > > -// TODO Bei mehr als einem registrierten IRQ geht das so nicht mehr > -static void (*driver_irq_handler)(struct cdi_device*) = NULL; > -static struct cdi_device* driver_irq_device = NULL; > +#define LOST_IRQ_OFFSET 0x20 > +#define IRQ_COUNT 0x10 Fehlende Kommentare. > + > +static void (*driver_irq_handler[IRQ_COUNT])(struct cdi_device*) = { NULL > }; +static struct cdi_device* driver_irq_device[IRQ_COUNT] = { NULL }; > > /** > * Interner IRQ-Handler, der den IRQ-Handler des Treibers aufruft > */ > -static void irq_handler(byte irq) > +static void irq_handler(uint8_t irq) > { > - driver_irq_handler(driver_irq_device); > + // Oops, das war wohl kein IRQ, den wollen wir nicht. s/Oops/Ups/ ;-) > + if ((irq < LOST_IRQ_OFFSET) || (irq > LOST_IRQ_OFFSET + IRQ_COUNT)) { Das sollte ein >= sein, glaube ich. Auf jeden Fall off by one. > + return; > + } > + > + irq -= LOST_IRQ_OFFSET; > + if (driver_irq_handler[irq]) { > + driver_irq_handler[irq](driver_irq_device[irq]); > + } > } > > /** > @@ -35,13 +45,19 @@ static void irq_handler(byte irq) > * @param handler Handlerfunktion > * @param device Geraet, das dem Handler als Parameter uebergeben werden > soll */ > -void cdi_register_irq(uint8_t irq, void (*handler)(struct cdi_device*), > +void cdi_register_irq(uint8_t irq, void (*handler)(struct cdi_device*), > struct cdi_device* device) > { > - driver_irq_handler = handler; > - driver_irq_device = device; > + if (irq > IRQ_COUNT) { > + // FIXME: Eigentlich sollte diese Funktion etwas weniger > optimistisch + // sein, und einen Rueckgabewert haben. > + return; > + } > + > + driver_irq_handler[irq] = handler; > + driver_irq_device[irq] = device; Eine Prüfung, ob der IRQ schon registriert ist, wäre noch ganz nett. Wobei das Verhalten in dem Fall eh undefiniert ist. Vielleicht ein fprintf(stderr) in diesem Fall. From mail at kevin-wolf.de Sat Apr 25 18:41:49 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 18:41:49 +0200 Subject: [tyndur-devel] [PATCH 3/3] cdi/core: Funktionen um auf IRQs zu warten In-Reply-To: <1240672054-18390-4-git-send-email-toni@tyndur.org> References: <1240672054-18390-1-git-send-email-toni@tyndur.org> <1240672054-18390-4-git-send-email-toni@tyndur.org> Message-ID: <200904251841.50098@kevin-wolf.de> Am Samstag, 25. April 2009 17:07 schrieb Antoine Kaufmann: > + cdi/core: Zwei neue Funktionen um effizient auf IRQs zu warten Sieht gut aus. From mail at kevin-wolf.de Sat Apr 25 18:42:45 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 18:42:45 +0200 Subject: [tyndur-devel] [PATCH] Buildsystem: make clean macht jetzt etwas cleaner In-Reply-To: <1240673149-19887-1-git-send-email-toni@tyndur.org> References: <1240673149-19887-1-git-send-email-toni@tyndur.org> Message-ID: <200904251842.45430@kevin-wolf.de> Am Samstag, 25. April 2009 17:25 schrieb Antoine Kaufmann: > * buildmk.sh: Bei make clean auch *.ppu und den anderen Kram vom fpc > loeschen. Auch versuchen eine Datei zu loeschen die gleich > heisst wie das Verzeichnis, um auch bei Applikationen ohne > .mod sauber zu machen. Ack From mail at kevin-wolf.de Sat Apr 25 18:43:40 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 18:43:40 +0200 Subject: [tyndur-devel] [PATCH] servmgr: Fix fuer uninitialisierte Variable In-Reply-To: <1240673209-20058-1-git-send-email-toni@tyndur.org> References: <1240673209-20058-1-git-send-email-toni@tyndur.org> Message-ID: <200904251843.40471@kevin-wolf.de> Am Samstag, 25. April 2009 17:26 schrieb Antoine Kaufmann: > ! servmgr: Wenn man in buffer_replace die Variable len initialisiert, > laesst sich das dann auch mit -O2 kompilieren. > > Signed-off-by: Antoine Kaufmann > --- > src/modules/servmgr/config.c | 1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/src/modules/servmgr/config.c b/src/modules/servmgr/config.c > index 0ca4f73..c722e41 100644 > --- a/src/modules/servmgr/config.c > +++ b/src/modules/servmgr/config.c > @@ -62,6 +62,7 @@ static void buffer_replace(char** buf, const char* > search, const char* replace) char* new; > int found = 0; > > + len = 0; > for (i = 0; i < strlen(old); i++) { > if (!strncmp(old + i, search, search_len)) { > len += replace_len; Man hätte die Initialisierung auch gleich zur Deklaration packen können... Aber ok, wegen mir auch so. From mail at kevin-wolf.de Sat Apr 25 18:49:29 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 18:49:29 +0200 Subject: [tyndur-devel] [PATCH 1/2] vterm: EOF gescheit setzen In-Reply-To: <1240672591-18954-2-git-send-email-toni@tyndur.org> References: <1240672591-18954-1-git-send-email-toni@tyndur.org> <1240672591-18954-2-git-send-email-toni@tyndur.org> Message-ID: <200904251849.29230@kevin-wolf.de> Am Samstag, 25. April 2009 17:16 schrieb Antoine Kaufmann: > * vtem: EOF nur nach Betaetigen von Strg+D setzen Sieht halbwegs einleuchtend aus. Aber könnte man in_node->size = 1 nicht einmal bei der Initialisierung setzen anstatt immer wieder beim read? From mail at kevin-wolf.de Sat Apr 25 18:52:53 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 18:52:53 +0200 Subject: [tyndur-devel] [PATCH 2/2] libc: EOF-Workarounds entfernen aus readline() In-Reply-To: <1240672591-18954-3-git-send-email-toni@tyndur.org> References: <1240672591-18954-1-git-send-email-toni@tyndur.org> <1240672591-18954-3-git-send-email-toni@tyndur.org> Message-ID: <200904251852.54047@kevin-wolf.de> Am Samstag, 25. April 2009 17:16 schrieb Antoine Kaufmann: > - libc: EOF-Workarounds entfernen aus readline(), da vterm das jetzt > sauber macht. Ack From mail at kevin-wolf.de Sat Apr 25 19:07:44 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 19:07:44 +0200 Subject: [tyndur-devel] [PATCH] libc: Synchrones Lesen in LIO In-Reply-To: <1240672684-19126-1-git-send-email-toni@tyndur.org> References: <1240672684-19126-1-git-send-email-toni@tyndur.org> Message-ID: <200904251907.44553@kevin-wolf.de> Am Samstag, 25. April 2009 17:18 schrieb Antoine Kaufmann: > * libc: Anfaenge von Synchronem Lesen in LostIO brauchbar gemacht. > ! vterm: lostio_dispatch() nur aufrufen wenn neue Eingaben da sind, und > nicht nach jedem rpc. > --- > src/modules/lib/lostio/handler.c | 18 +++++--- > src/modules/lib/lostio/include/lostio_internal.h | 9 ++++ > src/modules/lib/lostio/sync.c | 49 > +++++++++++----------- src/modules/lib/stdlibc/file.c | > 4 ++ > src/modules/vterm/input.c | 3 + > src/modules/vterm/vterm.c | 1 - > 6 files changed, 53 insertions(+), 31 deletions(-) > > diff --git a/src/modules/lib/lostio/handler.c > b/src/modules/lib/lostio/handler.c index 0c9c1b6..5e8f361 100644 > --- a/src/modules/lib/lostio/handler.c > +++ b/src/modules/lib/lostio/handler.c > @@ -191,7 +191,12 @@ void rpc_io_read(pid_t pid, dword correlation_id, > size_t data_size, void* data) size_t size = typehandle->read(filehandle, > buf, > read_request->blocksize, read_request->blockcount); > > - rpc_send_response(pid, correlation_id, size, (char*) buf); > + if (!size && (filehandle->flags & IO_OPEN_MODE_SYNC)) { > + // Synchrones lesen > + lostio_sync_read_wait(pid, correlation_id, read_request); > + } else { > + rpc_send_response(pid, correlation_id, size, (char*) buf); > + } > return; > } > > @@ -200,11 +205,12 @@ void rpc_io_read(pid_t pid, dword correlation_id, > size_t data_size, void* data) size_t size = typehandle->read(filehandle, > shm_ptr, > read_request->blocksize, read_request->blockcount); > close_shared_memory(read_request->shared_mem_id); > - > -/* printf("size = %d, ptr = %p, value = %d\n", > - sizeof(reply.size), &reply.size, reply.size); > - fflush(stdout);*/ > - rpc_send_dword_response(pid, correlation_id, size); > + if (!size && (filehandle->flags & IO_OPEN_MODE_SYNC)) { > + // Synchrones lesen > + lostio_sync_read_wait(pid, correlation_id, read_request); > + } else { > + rpc_send_dword_response(pid, correlation_id, size); > + } > //v(); > } > > diff --git a/src/modules/lib/lostio/include/lostio_internal.h > b/src/modules/lib/lostio/include/lostio_internal.h index ba7a691..49fa280 > 100644 > --- a/src/modules/lib/lostio/include/lostio_internal.h > +++ b/src/modules/lib/lostio/include/lostio_internal.h > @@ -76,6 +76,15 @@ void rpc_io_unlink(pid_t pid, dword correlation_id, > size_t data_size, void* d //bool vfstree_delete_node(char* path); > > > +/** > + * Schiebt eine Anfrage fuer synchrones Lesen auf, falls keine Daten > vorhanden + * sind. > + * > + * @param read_request Gesendete anfrage > + */ > +void lostio_sync_read_wait(pid_t pid, dword correlation_id, > + io_read_request_t* read_request); > + > > ///Filehandle aus der Liste holen > lostio_filehandle_t* get_filehandle(pid_t pid, dword id); > diff --git a/src/modules/lib/lostio/sync.c b/src/modules/lib/lostio/sync.c > index d57e7bd..d6e126f 100644 > --- a/src/modules/lib/lostio/sync.c > +++ b/src/modules/lib/lostio/sync.c > @@ -36,11 +36,11 @@ > #include "stdlib.h" > #include "string.h" > #include "stdio.h" > +#include > > /// In dieser Struktur werden die Informationen zu aufgeschobenen reads > /// gespeichert > struct sync_read_s { > - lostio_filehandle_t* filehandle; > io_read_request_t read_request; > dword correlation_id; > pid_t pid; > @@ -48,32 +48,33 @@ struct sync_read_s { > > static list_t* sync_read_list = NULL; > > + > /** > * Verarbeitet eventuell vorhandene aufgeschobene Anfragen fuer synchrones > * Lesen. > */ > -void lostio_sync_dispatch() > +void lostio_sync_dispatch(void) > { > - int i = 0; > - struct sync_read_s* sync_read; > + int i; > + size_t sz; > > // Wenn noch keine Anfragen vorhanden sind, wird abgebrochen. > if (sync_read_list == NULL) { > return; > } > > - while ((sync_read = list_get_element_at(sync_read_list, i)) != NULL) { > - // Pruefen ob jetzt genug Daten vorhanden sind. > - if ((sync_read->filehandle->node->size - > sync_read->filehandle->pos) >= - > (sync_read->read_request.blocksize * sync_read->read_request. - > blockcount)) > - { > - rpc_io_read(sync_read->pid, sync_read->correlation_id, > - sizeof(io_read_request_t), &sync_read->read_request); > + p(); > + sz = list_size(sync_read_list); > + { > + struct sync_read_s* reads[sz]; > + i = 0; > + while ((reads[i++] = list_pop(sync_read_list))) { } > + v(); > > - list_remove(sync_read_list, i); > - } else { > - i++; > + for (i = 0; i < sz; i++) { > + rpc_io_read(reads[i]->pid, reads[i]->correlation_id, > + sizeof(reads[i]->read_request), &reads[i]->read_request); > + free(reads[i]); > } > } > } Solltest du reads[] nicht rückwärts abarbeiten, damit die Anfragen, die nicht erfüllt werden konnten, von rpc_io_read() wieder in der Originalreihenfolge eingefügt werden? Sonst könnte es passieren, dass neue Requests verarbeitet werden und alte ewig warten müssen. > @@ -82,27 +83,27 @@ void lostio_sync_dispatch() > * Schiebt eine Anfrage fuer synchrones Lesen auf, falls keine Daten > vorhanden * sind. > * > - * @param filehandle Filehandle von dem gelesen werden soll > * @param read_request Gesendete anfrage > */ > -void lostio_sync_read_wait(lostio_filehandle_t* filehandle, pid_t pid, > - dword correlation_id, io_read_request_t* read_request) > +void lostio_sync_read_wait(pid_t pid, dword correlation_id, > + io_read_request_t* read_request) > { > - struct sync_read_s* sync_read = malloc(sizeof(struct sync_read_s)); > + struct sync_read_s* sync_read = malloc(sizeof(*sync_read)); > > + p(); > if (sync_read_list == NULL) { > sync_read_list = list_create(); > } > > - sync_read->pid = pid; > - sync_read->correlation_id = correlation_id; > - > // Read-Request kopieren, da er beim zurueckspringen aus dem > rpc-Handler // zerstoert wird. > - memcpy(&sync_read->read_request, read_request, > sizeof(io_read_request_t)); + memcpy(&sync_read->read_request, > read_request, > + sizeof(sync_read->read_request)); > > - sync_read->filehandle = filehandle; > + sync_read->pid = pid; > + sync_read->correlation_id = correlation_id; > > sync_read_list = list_push(sync_read_list, sync_read); > + v(); > } > > diff --git a/src/modules/lib/stdlibc/file.c > b/src/modules/lib/stdlibc/file.c index 6441fcd..4b1fdbe 100644 > --- a/src/modules/lib/stdlibc/file.c > +++ b/src/modules/lib/stdlibc/file.c > @@ -116,6 +116,10 @@ FILE* fopen (const char* filename, const char* mode) > *attr |= IO_OPEN_MODE_LINK; > break; > > + case 's': > + *attr |= IO_OPEN_MODE_SYNC; > + break; > + Ich hab gehört, unter anderen Systemen ist blockierendes Lesen der Default. ;-) From mail at kevin-wolf.de Sat Apr 25 19:16:29 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 25 Apr 2009 19:16:29 +0200 Subject: [tyndur-devel] [PATCH] libc: Fix fuer die Schreibpuffer in stdio In-Reply-To: <1240670877-17506-3-git-send-email-toni@tyndur.org> References: <1240670877-17506-1-git-send-email-toni@tyndur.org> <1240670877-17506-3-git-send-email-toni@tyndur.org> Message-ID: <200904251916.29588@kevin-wolf.de> Am Samstag, 25. April 2009 16:47 schrieb Antoine Kaufmann: > ! libc: Fehler behoben, der verhindert, dass gepuffert wird, und zu > einem Buffer overflow führen kann. > ! libc: Puffer in fclose und fseek flushen > ! libc: Fix fuers Befuellen der Blockpuffer, damit dabei nichts > ueberschrieben wird. > --- > src/modules/lib/stdlibc/file.c | 12 ++++++++---- > 1 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/src/modules/lib/stdlibc/file.c > b/src/modules/lib/stdlibc/file.c index 34b8171..6441fcd 100644 > --- a/src/modules/lib/stdlibc/file.c > +++ b/src/modules/lib/stdlibc/file.c > @@ -201,6 +201,7 @@ int fclose (FILE* io_res) > return EOF; > } > > + fflush(io_res); > setvbuf(io_res, NULL, _IONBF, 0); > > result = rpc_get_dword(io_res->pid, "IO_CLOSE", > sizeof(io_resource_id_t), @@ -489,10 +490,11 @@ size_t fwrite(const void* > data, size_t blocksize, size_t blockcount, //Ueberpruefen, ob genug Platz > im Buffer ist, dann werden die Daten // in den Buffer kopiert, sonst wird > der Buffer geleert, und die // Daten werden direkt geschrieben. > - if (io_res->buffer_size < (io_res->buffer_pos + data_size)) > + if (io_res->buffer_size >= (io_res->buffer_pos + data_size)) > { > //Daten in den Buffer kopieren. > - memcpy(io_res->buffer_ptr, data, data_size); > + memcpy(io_res->buffer_ptr + io_res->buffer_pos, data, > + data_size); Tab-Damage. Aber schon im Original. :-/ > io_res->buffer_pos += data_size; > return data_size; > } else { > @@ -508,7 +510,7 @@ size_t fwrite(const void* data, size_t blocksize, > size_t blockcount, // geleert, und die Daten werden auch direkt > geschrieben. Auch wenn // die Daten mindestens einen Zeilenumbruch > enthalten, wird der // Buffer geleert. > - if ((io_res->buffer_size < (io_res->buffer_pos + data_size)) || > + if ((io_res->buffer_size >= (io_res->buffer_pos + data_size)) || > (memchr(data, '\n', data_size) != NULL)) Ist die Logik hier nicht umgekehrt und die aktuelle Variante die richtige? Wer auch immer diesen Code ursprünglich verbrochen hat, sollte sich schämen. ;-) From mail at kevin-wolf.de Sun Apr 26 11:35:57 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 26 Apr 2009 11:35:57 +0200 Subject: [tyndur-devel] [PATCH 1/5] libc: POSIX: sigaction In-Reply-To: <20090425161230.GE14585@einstein.produktiv.lan> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> <1240424297-4863-2-git-send-email-kevin@tyndur.org> <20090425161230.GE14585@einstein.produktiv.lan> Message-ID: <200904261135.58021@kevin-wolf.de> Am Samstag, 25. April 2009 18:12 schrieb Antoine Kaufmann: > On Wed, Apr 22 20:18, Kevin Wolf wrote: > > + libc: POSIX: Signale von reinen Handler auf sigactions umgestellt (die > > aber alles ausser dem Handler ignorieren). sigaction() hinzugefuegt. > > --- > > diff --git a/src/modules/lib/posix/signal.c > > b/src/modules/lib/posix/signal.c index 4d70a61..03cfb56 100644 > > --- a/src/modules/lib/posix/signal.c > > +++ b/src/modules/lib/posix/signal.c > > @@ -37,7 +37,7 @@ > > #include > > > > /// Array mit Pointern auf die Signal-Handler > > -static sighandler_t signal_handlers [_SIGNO_MAX]; > > +static struct sigaction sigactions[_SIGNO_MAX]; > > static bool initialized = FALSE; > > > > /** > > @@ -46,8 +46,9 @@ static bool initialized = FALSE; > > static void init_signals(void) > > { > > int i; > > + memset(sigactions, 0, sizeof(sigactions)); > > for (i = 0; i < _SIGNO_MAX; i++) { > > - signal_handlers[i] = SIG_DFL; > > + sigactions[i].sa_handler = SIG_DFL; > > } > > > > initialized = TRUE; > > @@ -73,7 +74,7 @@ int raise(int signum) > > return -1; > > } > > > > - sighandler_t handler = signal_handlers[signum]; > > + sighandler_t handler = sigactions[signum].sa_handler; > > if (handler != NULL) { > > handler(signum); > > } > > @@ -150,14 +151,50 @@ sighandler_t signal(int signum, sighandler_t > > handler) } > > > > // Alter Handler Speichern, weil er zurueck gegeben wird > > - sighandler_t old_handler = signal_handlers[signum]; > > + sighandler_t old_handler = sigactions[signum].sa_handler; > > > > // Neuer setzen > > - signal_handlers[signum] = handler; > > + sigactions[signum].sa_handler = handler; > > > > return old_handler; > > } > > > > +/** > > + * Aendert die auszufuehrende Aktion fuer ein Signal und gibt die alte > > Aktion + * zurueck. > > + * TODO Momentan nur Handler, POSIX sieht da mehr vor > > + * > > + * @param sig Nummer des Signals, fuer das die Aktion geaendert wird > > + * @param action Neue Aktion. Wenn NULL, wird nur die aktuelle Aktion > > + * zurueckgegeben, aber keine Aenderung vorgenommen > > + * @param old Wenn nicht NULL, wird hier die alte Aktion gespeichert > > + */ > > +int sigaction(int sig, const struct sigaction* action, struct sigaction* > > old) +{ > > + // Initialisieren falls das noch nicht gemacht ist > > + if (initialized == FALSE) { > > + init_signals(); > > + } > > + > > + // Ungueltige Signale und SIGKILL koennen nicht gesetzt werden > > + if ((sig >= _SIGNO_MAX) || (sig == SIGKILL)) { > > + errno = EINVAL; > > + return -1; > > + } > > + > > + // Alte Werte zurueckgeben > > + if (old != NULL) { > > + memcpy(old, &sigactions[sig], sizeof(*old)); > > + } > > + > > + // Neue Werte setzen > > + if (action != NULL) { > > + memcpy(&sigactions[sig], action, sizeof(*action)); > > + } > > Hier wäre jeweils auch kein memcpy nötig, oder irre ich mich? Du meinst sigactions[sig] = *action? Könnte man wohl auch machen, am Ende packt dann halt gcc das memcpy rein. ;-) From toni at tyndur.org Sun Apr 26 11:38:19 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 26 Apr 2009 11:38:19 +0200 Subject: [tyndur-devel] [PATCH 1/5] libc: POSIX: sigaction In-Reply-To: <200904261135.58021@kevin-wolf.de> References: <1240424297-4863-1-git-send-email-kevin@tyndur.org> <1240424297-4863-2-git-send-email-kevin@tyndur.org> <20090425161230.GE14585@einstein.produktiv.lan> <200904261135.58021@kevin-wolf.de> Message-ID: <20090426093819.GA20889@einstein.produktiv.lan> On Sun, Apr 26 11:35, Kevin Wolf wrote: > Am Samstag, 25. April 2009 18:12 schrieb Antoine Kaufmann: > > On Wed, Apr 22 20:18, Kevin Wolf wrote: > > > + // Neue Werte setzen > > > + if (action != NULL) { > > > + memcpy(&sigactions[sig], action, sizeof(*action)); > > > + } > > > > Hier wäre jeweils auch kein memcpy nötig, oder irre ich mich? > > Du meinst sigactions[sig] = *action? Könnte man wohl auch machen, am Ende > packt dann halt gcc das memcpy rein. ;-) Jo, aber der gcc macht sicher keinen Fehler beim sizeof wenn man mal was ändert. *g* -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Sun Apr 26 14:02:29 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 26 Apr 2009 14:02:29 +0200 Subject: [tyndur-devel] [PATCH] libc: Pufferung fuer stdout In-Reply-To: <1240671224-17708-1-git-send-email-toni@tyndur.org> References: <1240670877-17506-1-git-send-email-toni@tyndur.org> <1240671224-17708-1-git-send-email-toni@tyndur.org> Message-ID: <200904261402.29931@kevin-wolf.de> Am Samstag, 25. April 2009 16:53 schrieb Antoine Kaufmann: > * libc: Code fuer Pufferung von stdout aus crt0 nach stdio_init() > verschoben, damit er auch von der pascal rtl benutzt werden > kann. > * libc: Puffer fuer stdin deaktivieren, das spart etwas speicher. Sieht gut aus. From mail at kevin-wolf.de Sun Apr 26 14:22:22 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 26 Apr 2009 14:22:22 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: fgetwc, fputwc und verwandte Funktionen In-Reply-To: <1240673039-19706-2-git-send-email-toni@tyndur.org> References: <1240673039-19706-1-git-send-email-toni@tyndur.org> <1240673039-19706-2-git-send-email-toni@tyndur.org> Message-ID: <200904261422.22415@kevin-wolf.de> Am Samstag, 25. April 2009 17:23 schrieb Antoine Kaufmann: > * libc: wchar.h nach modules/include verschoben, da sie stdio.h > inkludieren muss. > + libc: fgetwc, getwc, getchar: Breite Zeichen aus Datei lesen > + libc: fputwc, putwc, putwchar: Breite Zeichen in Datei schreiben > --- > src/include/wchar.h | 37 ---------- > src/modules/include/wchar.h | 96 +++++++++++++++++++++++++ > src/modules/lib/stdlibc/wstdio.c | 142 > ++++++++++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+), > 37 deletions(-) > delete mode 100644 src/include/wchar.h > create mode 100644 src/modules/include/wchar.h > create mode 100644 src/modules/lib/stdlibc/wstdio.c > > diff --git a/src/include/wchar.h b/src/include/wchar.h > deleted file mode 100644 > index f9cd89b..0000000 > --- a/src/include/wchar.h > +++ /dev/null > @@ -1,37 +0,0 @@ > -/* > - * Copyright (c) 2008 The tyndur Project. All rights reserved. > - * > - * This code is derived from software contributed to the tyndur Project > - * by Antoine Kaufmann. > - * > - * Redistribution and use in source and binary forms, with or without > - * modification, are permitted provided that the following conditions > - * are met: > - * 1. Redistributions of source code must retain the above copyright > - * notice, this list of conditions and the following disclaimer. > - * 2. Redistributions in binary form must reproduce the above copyright > - * notice, this list of conditions and the following disclaimer in the > - * documentation and/or other materials provided with the distribution. > - * > - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A > PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > - */ > - > -#ifndef _WCHAR_H_ > -#define _WCHAR_H_ > - > -#include > - > -typedef wchar_t wint_t; > - > -#endif //ifndef _WCHAR_H_ > - > diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h > new file mode 100644 > index 0000000..d173bce > --- /dev/null > +++ b/src/modules/include/wchar.h > @@ -0,0 +1,96 @@ > +/* > + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Antoine Kaufmann. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A > PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#ifndef _WCHAR_H_ > +#define _WCHAR_H_ > + > +#include > +#include > + > +#define WEOF ((wint_t) -1) > + > +typedef wchar_t wint_t; > + > +/* WSTDIO */ > + > +/** > + * Breites Zeichen aus einer Datei lesen. > + * > + * @param stream Die geoeffnete Datei > + * > + * @return Das gelesene Zeichen oder WEOF im Fehlerfall. > + */ > +wint_t fgetwc(FILE* stream); > + > +/** > + * Wie fgetwc, mit dem Unterschied, dass getwc als Makro implementiert > werden + * darf, das den Parameter mehrmals auswertet > + * > + * @see fgetwc > + */ > +wint_t getwc(FILE* stream); Blöde Frage: Wenn du das extra so schön im Kommentar erwähnst, warum nicht #define getwc(s) fgetwc(s)? Analoges gilt für noch ein paar Funktionen. Ansonsten sieht das vernünftig aus. From mail at kevin-wolf.de Sun Apr 26 14:48:55 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 26 Apr 2009 14:48:55 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: Ein bisschen mehr wchar.h In-Reply-To: <1240673039-19706-3-git-send-email-toni@tyndur.org> References: <1240673039-19706-1-git-send-email-toni@tyndur.org> <1240673039-19706-3-git-send-email-toni@tyndur.org> Message-ID: <200904261448.56019@kevin-wolf.de> Am Samstag, 25. April 2009 17:23 schrieb Antoine Kaufmann: > + libc: Die Funktionen mbrtowc, wcrtomb, wcwidth und wcswidth, damit > kommt curses schon weiter beim Kompilieren mit UTF-8-Support > --- > src/include/limits.h | 3 + > src/modules/include/wchar.h | 52 +++++++++++++++++ > src/modules/lib/posix/regex/regex2.h | 8 --- > src/modules/lib/stdlibc/wchar.c | 101 > ++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 8 > deletions(-) > create mode 100644 src/modules/lib/stdlibc/wchar.c > > diff --git a/src/include/limits.h b/src/include/limits.h > index 1ea8cc5..62f8399 100644 > --- a/src/include/limits.h > +++ b/src/include/limits.h > @@ -57,4 +57,7 @@ > > #define _POSIX_PATH_MAX 4096 > > +/** Maximale laenge eines Multibyte-Zeichens in Bytes */ > +#define MB_LEN_MAX 4 > + > #endif > diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h > index d173bce..6ed1d51 100644 > --- a/src/modules/include/wchar.h > +++ b/src/modules/include/wchar.h > @@ -34,8 +34,60 @@ > > #define WEOF ((wint_t) -1) > > +/** > + * Sollte theoretisch alle Werte von wchar_t und zusaetzlich WEOF annehmen > + * koennen. > + */ > typedef wchar_t wint_t; > > +/** > + * Repraesentiert den internen Shift-Status einer Funktion, brauchen wir > mit + * UTF-8 nicht. > + */ > +typedef int mbstate_t; > + > + > + > +/* WSTRINGS */ > + > +/** > + * Reentrante Variante von mbtowc, bei uns mit UTF-8 aber identisch. > + * @see mbtowc > + */ > +size_t mbrtowc(wchar_t* wc, const char* s, size_t len, mbstate_t* ps); > + > +/** > + * Reentrante Variante von wctomb, bei uns mit UTF-8 aber identisch. > + * @see wctomb > + */ > +size_t wcrtomb(char* buf, wchar_t wc, mbstate_t* ps); > + > + > +/** > + * Anzahl der Spalten, die ein Zeichen in Anspruch nimmt, errechnen. Fuer > c = 0 + * wird 0 zuruekgegeben. Falls es sich nicht um ein druckbares > Zeichen handelt, + * wird -1 zurueckgegeben. > + * > + * @param wc Das breite Zeichen > + * > + * @return Anzahl Spalten, oder -1 wenn das Zeichen nicht druckbar ist. > + */ > +int wcwidth(wchar_t wc); > + > +/** > + * Anzahl der Spalten, die ein String aus breiten Zeichen in Anspruch > nimmt, + * errechnen. Wird ein nicht druckbares Zeichen erkannt, wird > abgebrochen. + * > + * @see wcwidth > + * @param wcs Zeiger auf das erste Zeichen > + * @param len Anzahl der Zeichen > + * > + * @return Anzahl der Zeichen oder -1 im Fehlerfall. > + */ > +int wcswidth(const wchar_t* wcs, size_t len); > + > + > + > /* WSTDIO */ > > /** > diff --git a/src/modules/lib/posix/regex/regex2.h > b/src/modules/lib/posix/regex/regex2.h index 38855e8..294b4c4 100644 > --- a/src/modules/lib/posix/regex/regex2.h > +++ b/src/modules/lib/posix/regex/regex2.h > @@ -159,11 +159,3 @@ struct re_guts { > #define OUT (CHAR_MAX+1) /* a non-character value */ > #define ISWORD(c) (isalnum((uch)(c)) || (c) == '_') > > - > - > -#include > -typedef union { > - int64_t __mbstateL; /* for alignment */ > - char __mbstate8[128]; > -} mbstate_t; > - > diff --git a/src/modules/lib/stdlibc/wchar.c > b/src/modules/lib/stdlibc/wchar.c new file mode 100644 > index 0000000..79bb27e > --- /dev/null > +++ b/src/modules/lib/stdlibc/wchar.c > @@ -0,0 +1,101 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Antoine Kaufmann. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A > PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +/** > + * Reentrante Variante von mbtowc, bei uns mit UTF-8 aber identisch. > + * @see mbtowc > + */ > +size_t mbrtowc(wchar_t* wc, const char* s, size_t len, mbstate_t* ps) > +{ > + return mbtowc(wc, s, len); > +} > + > +/** > + * Reentrante Variante von wctomb, bei uns mit UTF-8 aber identisch. > + * @see wctomb > + */ > +size_t wcrtomb(char* buf, wchar_t wc, mbstate_t* ps) > +{ > + return wctomb(buf, wc); > +} > + > +/** > + * Anzahl der Spalten, die ein Zeichen in Anspruch nimmt, errechnen. Fuer > c = 0 + * wird 0 zuruekgegeben. Falls es sich nicht um ein druckbares > Zeichen handelt, + * wird -1 zurueckgegeben. > + * > + * @param wc Das breite Zeichen > + * > + * @return Anzahl Spalten, oder -1 wenn das Zeichen nicht druckbar ist. > + */ > +int wcwidth(wchar_t wc) > +{ > + // Muss nach Spezifikation so sein > + if (!wc) { > + return 0; > + } > + > + // Steuerzeichen sind nicht druckbar > + if (wc < 32) { > + return -1; > + } > + > + // Das ist so sicher noch etwas rudimentaer, doch im Moment reicht das > so + // fuer uns. > + return 1; > +} > + > +/** > + * Anzahl der Spalten, die ein String aus breiten Zeichen in Anspruch > nimmt, + * errechnen. Wird ein nicht druckbares Zeichen erkannt, wird > abgebrochen. + * > + * @see wcwidth > + * @param wcs Zeiger auf das erste Zeichen > + * @param len Anzahl der Zeichen > + * > + * @return Anzahl der Zeichen oder -1 im Fehlerfall. > + */ > +int wcswidth(const wchar_t* wcs, size_t len) > +{ > + int cols = 0; > + int cur; > + size_t i; > + > + for (i = 0; i < len; i++) { > + if ((cur = wcwidth(wcs[i])) == -1) { > + return -1; > + } Hier fehlt die Abbruchbedingung cur == L'\0', sonst wird über den String rausgelesen. Ansonsten Ack. From mail at kevin-wolf.de Sun Apr 26 15:40:18 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 26 Apr 2009 15:40:18 +0200 Subject: [tyndur-devel] [PATCH 3/3] libc: Ein paar wchar.h-Stringfunktionen In-Reply-To: <1240673039-19706-4-git-send-email-toni@tyndur.org> References: <1240673039-19706-1-git-send-email-toni@tyndur.org> <1240673039-19706-4-git-send-email-toni@tyndur.org> Message-ID: <200904261540.18964@kevin-wolf.de> Am Samstag, 25. April 2009 17:23 schrieb Antoine Kaufmann: > + libc: Ein paar Stringfunktionen in der wchar.h aus freebsd portiert > + libc: Noch ein bisschen wctype.h damit die BSD-Funktionen kompilieren Wenn das aus BSD kommt, glaube ich dir einfach mal, daß das so funktioniert. Reviewen will ich das nicht unbedingt. ;-) From mail at kevin-wolf.de Sun Apr 26 15:57:14 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 26 Apr 2009 15:57:14 +0200 Subject: [tyndur-devel] [PATCH] libc: readline() multibyte-kompatibel machen In-Reply-To: <1240673286-20223-1-git-send-email-toni@tyndur.org> References: <1240673286-20223-1-git-send-email-toni@tyndur.org> Message-ID: <200904261557.14445@kevin-wolf.de> Am Samstag, 25. April 2009 17:28 schrieb Antoine Kaufmann: > * libc: readline() kommt jetzt auch mit Zeichen klar, die mehr als ein > Byte in Anspruch nehmen (z.B. UTF-8). > --- > src/modules/lib/readline.c | 111 > +++++++++++++++++++++++++++++++------------ 1 files changed, 80 > insertions(+), 31 deletions(-) > > diff --git a/src/modules/lib/readline.c b/src/modules/lib/readline.c > index 5c7fab0..97242d5 100644 > --- a/src/modules/lib/readline.c > +++ b/src/modules/lib/readline.c > @@ -31,6 +31,7 @@ > #include > #include > #include > +#include > > #include > > @@ -53,13 +54,13 @@ char* rl_line_buffer; > * @return Das eingelesene Zeichen oder NULL, wenn das Ende der > Eingabedatei * erreicht ist. > */ Der Kommentar haut nicht mehr ganz hin. Abgesehen davon, daß es auch vorher schon 0 und nicht NULL war.. Angenommen du hast hast alle Stellen erwischt, wo an der Cursorposition rumgebastelt wird, sieht das sonst gut aus. From mail at kevin-wolf.de Sun Apr 26 16:25:20 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 26 Apr 2009 16:25:20 +0200 Subject: [tyndur-devel] [PATCH] libc: Blockpuffer auf allen Dateien aktivieren In-Reply-To: <1240670877-17506-2-git-send-email-toni@tyndur.org> References: <1240670877-17506-1-git-send-email-toni@tyndur.org> <1240670877-17506-2-git-send-email-toni@tyndur.org> Message-ID: <200904261625.21077@kevin-wolf.de> Am Samstag, 25. April 2009 16:47 schrieb Antoine Kaufmann: > * libc: Blockpuffer auf allen Dateien aktivieren > * libc: Buffer fuer stderr deaktivieren > --- > src/modules/include/lostio.h | 6 ++++++ > src/modules/lib/lostio/handler.c | 12 +++++++++--- > src/modules/lib/stdlibc/file.c | 30 ++++++++++++++++++++++++++++-- > src/modules/lib/stdlibc/stdio.c | 4 ++++ > 4 files changed, 47 insertions(+), 5 deletions(-) > > diff --git a/src/modules/include/lostio.h b/src/modules/include/lostio.h > index 60cddf1..57e3cf7 100644 > --- a/src/modules/include/lostio.h > +++ b/src/modules/include/lostio.h > @@ -117,6 +117,12 @@ typedef struct > } typehandle_t; > > > +/// Geoeffnete Datei auf Clientseite (Wrapper fuer FILE) > +struct lostio_internal_file { > + io_resource_t res; > + bool free_buffer; > +}; > + Sollte FILE nicht auch noch umdefiniert werden? Oder würde das zwangsläufig was kaputtmachen? Falls nicht, brauchen auf jeden Fall die Sockets noch eine Änderung, damit sie eine lostio_internal_file statt FILE durch die Gegend kopieren. > ///LostIO-Schnittstelle initialisieren > void lostio_init(void); > diff --git a/src/modules/lib/lostio/handler.c > b/src/modules/lib/lostio/handler.c index ce61485..0c9c1b6 100644 > --- a/src/modules/lib/lostio/handler.c > +++ b/src/modules/lib/lostio/handler.c > @@ -63,6 +63,12 @@ void rpc_io_open(pid_t pid, dword correlation_id, size_t > data_size, void* data) > > //Wird bei pipes als quelle verwendet > io_resource_t* io_source = (io_resource_t*) ((dword)data + 1 + > sizeof(pid_t)); + > + // FIXME > + struct lostio_internal_file* int_source = malloc(sizeof(*int_source)); > + int_source->res = *io_source; > + int_source->free_buffer = FALSE; > + io_source = &int_source->res; > > byte* attr = (byte*) data; > pid_t* caller_pid = (pid_t*) ((dword)data + 1 ); > @@ -79,6 +85,7 @@ void rpc_io_open(pid_t pid, dword correlation_id, size_t > data_size, void* data) { > io_res.pid = 0; > rpc_send_response(pid, correlation_id, sizeof(io_resource_t), > (char*) &io_res); + free(io_source); Das sollte free(int_source); heißen > } > else > { > @@ -120,6 +127,7 @@ void rpc_io_open(pid_t pid, dword correlation_id, > size_t data_size, void* data) if(io_res.id == 0) > { > io_res.pid = 0; > + free(io_source); Nochmal. From kevin at tyndur.org Sun Apr 26 23:19:32 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 26 Apr 2009 23:19:32 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Dokumentation der i386-Interrupt-Stubs Message-ID: <1240780772-17544-1-git-send-email-kevin@tyndur.org> + kernel2: Viel tollerer lesbarer Code weil Kommentare und so --- src/kernel2/src/arch/i386/interrupts/int_stubs.S | 68 ++++++++++++++++++--- 1 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/kernel2/src/arch/i386/interrupts/int_stubs.S b/src/kernel2/src/arch/i386/interrupts/int_stubs.S index 2672f3e..69caef5 100644 --- a/src/kernel2/src/arch/i386/interrupts/int_stubs.S +++ b/src/kernel2/src/arch/i386/interrupts/int_stubs.S @@ -35,6 +35,16 @@ .code32 + +// Fuer jeden Interrupt wird ein eigener Einsprungspunkt definiert. Dabei +// existieren zwei verschiedene Arten von Handlern: Solche fuer Exceptions, +// die einen Fehlercode auf dem Stack haben, und solche fuer die uebrigen. +// Die Stubs bringen den Stack in einen einheitlichen Zustand, speichern die +// Interruptnummer auf den Stack und springen dann zu einem gemeinsamen +// Handler. + +// Dieser Stub ist fuer Interrupts ohne Fehlercode. Als Fehlercode wird in +// diesem Fall 0 auf den Stack gelegt. .macro INT_STUB nr .globl im_int_stub_\nr im_int_stub_\nr: @@ -43,6 +53,8 @@ jmp im_int_stub_all .endm +// Dieser Stub ist fuer Interrupts, die bereits einen Fehlercode auf demStack +// haben. In diesem Fall wird nur die Interruptnummer gespeichert. .macro INT_STUB_ERROR_CODE nr .globl im_int_stub_\nr im_int_stub_\nr: @@ -50,6 +62,7 @@ jmp im_int_stub_all .endm +// Definition der Stubs fuer jeden Interrupt INT_STUB 0 INT_STUB 1 INT_STUB 2 @@ -307,27 +320,47 @@ INT_STUB 253 INT_STUB 254 INT_STUB 255 +// Hier ist der Beginn des gemeinsamen Handlercodes fuer alle Interrupts. +// +// Wir haben an dieser Stelle im grossen und ganzen noch den Prozessorzustand +// des Prozesses, der durch den Interrupt unterbrochen wurde. Der Stackpointer +// des Prozesses wurde vom Prozessor ins TSS gespeichert und dafuer der dort +// gespeicherte Kernelstack geladen. +// +// Auf dem Kernelstack liegen jetzt die Ruecksprungdaten (vom Prozessor beim +// Interrupt dort abgelegt), der Fehlercode und die Interruptnummer. +// +// Der unterbrochene Task weiss nicht, dass ein Interrupt stattgefunden hat, +// deswegen muss beim Ruecksprung der gesamte Prozessorzustand +// wiederhergestellt werden. Bevor wir den Kernel oder andere Tasks Register +// veraendern lassen, muessen wir also erst einmal den aktuellen Zustand +// speichern. Wir benutzen dazu den Stack, der ja schon dem Kernel gehoert. + im_int_stub_all: // Das rax-Register wird benoetigt, um ds und es Pushen zu koennen pushl %eax - + + // Segmentregister auf den Stack pushen push %gs push %fs xorl %eax, %eax movw %es, %ax pushl %eax - + movw %ds, %ax pushl %eax - + + // Allzweckregister auf den Stack pushl %ebp pushl %edi pushl %esi pushl %edx pushl %ecx pushl %ebx - + + // Der Task-Zustand ist hier fertig gespeichert. + // Ring 0 Segment-Register laden cld mov $0x10, %ax @@ -335,38 +368,53 @@ im_int_stub_all: mov %ax, %es + // Der aktuelle Stackpointer wird dem C-Interrupt-Handler als Parameter + // uebergeben. Wir haben gerade den Zustand des Gasts im Format des C-Typs + // interrupt_stack_frame_t auf den Stack gepusht, so dass der C-Handler + // bequem auf die einzelnen Register des Tasks zugreifen kann. pushl %esp .extern im_handler call im_handler - - // Den neuen Stackpointer laden + + // Der C-Handler gibt einen neuen Stackpointer fuer den Kernelstack des + // aktuellen Tasks zurueck (der aktuelle Task kann sich geaendert haben, + // wenn wir gerade einen Timer-Interrupt oder einen Syscall verarbeiten). + // + // Den neuen Stackpointer laden. Anschliessend liegt der Zustand des jetzt + // aktuellen Tasks auf dem Stack, den wir auslesen koennen. Anschliessend + // koennen wir in den Task zurueckspringen. movl %eax, %esp + // Allzweckregister wiederherstellen popl %ebx popl %ecx popl %edx popl %esi popl %edi popl %ebp - - + + // Segmentregister wiederherstellen popl %eax movw %ax, %ds - + popl %eax movw %ax, %es pop %fs pop %gs - + + // eax wiederherstellen popl %eax // Fehler- und Interruptnummer von Stack loeschen addl $8, %esp + + // Ruecksprung in den Task iret + // Double Fault .globl im_int_stub_8 .extern double_fault_tss -- 1.6.0.2 From toni at tyndur.org Sun Apr 26 23:27:25 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 26 Apr 2009 23:27:25 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Dokumentation der i386-Interrupt-Stubs In-Reply-To: <1240780772-17544-1-git-send-email-kevin@tyndur.org> References: <1240780772-17544-1-git-send-email-kevin@tyndur.org> Message-ID: <20090426212724.GA9913@einstein.produktiv.lan> On Sun, Apr 26 23:19, Kevin Wolf wrote: > + kernel2: Viel tollerer lesbarer Code weil Kommentare und so > --- > src/kernel2/src/arch/i386/interrupts/int_stubs.S | 68 ++++++++++++++++++--- > 1 files changed, 58 insertions(+), 10 deletions(-) > > diff --git a/src/kernel2/src/arch/i386/interrupts/int_stubs.S b/src/kernel2/src/arch/i386/interrupts/int_stubs.S > index 2672f3e..69caef5 100644 > --- a/src/kernel2/src/arch/i386/interrupts/int_stubs.S > +++ b/src/kernel2/src/arch/i386/interrupts/int_stubs.S > @@ -35,6 +35,16 @@ > > .code32 > > + > +// Fuer jeden Interrupt wird ein eigener Einsprungspunkt definiert. Dabei > +// existieren zwei verschiedene Arten von Handlern: Solche fuer Exceptions, > +// die einen Fehlercode auf dem Stack haben, und solche fuer die uebrigen. > +// Die Stubs bringen den Stack in einen einheitlichen Zustand, speichern die > +// Interruptnummer auf den Stack und springen dann zu einem gemeinsamen > +// Handler. > + > +// Dieser Stub ist fuer Interrupts ohne Fehlercode. Als Fehlercode wird in > +// diesem Fall 0 auf den Stack gelegt. > .macro INT_STUB nr > .globl im_int_stub_\nr > im_int_stub_\nr: > @@ -43,6 +53,8 @@ > jmp im_int_stub_all > .endm > > +// Dieser Stub ist fuer Interrupts, die bereits einen Fehlercode auf demStack Typo "demStack" ;-) > +// haben. In diesem Fall wird nur die Interruptnummer gespeichert. > .macro INT_STUB_ERROR_CODE nr > .globl im_int_stub_\nr > im_int_stub_\nr: > @@ -50,6 +62,7 @@ > jmp im_int_stub_all > .endm > > +// Definition der Stubs fuer jeden Interrupt > INT_STUB 0 > INT_STUB 1 > INT_STUB 2 > @@ -307,27 +320,47 @@ INT_STUB 253 > INT_STUB 254 > INT_STUB 255 > > +// Hier ist der Beginn des gemeinsamen Handlercodes fuer alle Interrupts. > +// > +// Wir haben an dieser Stelle im grossen und ganzen noch den Prozessorzustand > +// des Prozesses, der durch den Interrupt unterbrochen wurde. Der Stackpointer > +// des Prozesses wurde vom Prozessor ins TSS gespeichert und dafuer der dort > +// gespeicherte Kernelstack geladen. > +// > +// Auf dem Kernelstack liegen jetzt die Ruecksprungdaten (vom Prozessor beim Hier könntest du eventuell noch erwähnen was da so auf dem Stack rumfliegt vom Interrupt... > +// Interrupt dort abgelegt), der Fehlercode und die Interruptnummer. > +// > +// Der unterbrochene Task weiss nicht, dass ein Interrupt stattgefunden hat, > +// deswegen muss beim Ruecksprung der gesamte Prozessorzustand > +// wiederhergestellt werden. Bevor wir den Kernel oder andere Tasks Register > +// veraendern lassen, muessen wir also erst einmal den aktuellen Zustand > +// speichern. Wir benutzen dazu den Stack, der ja schon dem Kernel gehoert. > + > im_int_stub_all: > // Das rax-Register wird benoetigt, um ds und es Pushen zu koennen > pushl %eax > - > + > + // Segmentregister auf den Stack pushen > push %gs > push %fs > > xorl %eax, %eax > movw %es, %ax > pushl %eax > - > + > movw %ds, %ax > pushl %eax > - > + > + // Allzweckregister auf den Stack > pushl %ebp > pushl %edi > pushl %esi > pushl %edx > pushl %ecx > pushl %ebx > - > + > + // Der Task-Zustand ist hier fertig gespeichert. > + > // Ring 0 Segment-Register laden > cld > mov $0x10, %ax > @@ -335,38 +368,53 @@ im_int_stub_all: > mov %ax, %es > > > + // Der aktuelle Stackpointer wird dem C-Interrupt-Handler als Parameter > + // uebergeben. Wir haben gerade den Zustand des Gasts im Format des C-Typs > + // interrupt_stack_frame_t auf den Stack gepusht, so dass der C-Handler > + // bequem auf die einzelnen Register des Tasks zugreifen kann. > pushl %esp > > .extern im_handler > call im_handler > - > - // Den neuen Stackpointer laden > + > + // Der C-Handler gibt einen neuen Stackpointer fuer den Kernelstack des > + // aktuellen Tasks zurueck (der aktuelle Task kann sich geaendert haben, > + // wenn wir gerade einen Timer-Interrupt oder einen Syscall verarbeiten). > + // > + // Den neuen Stackpointer laden. Anschliessend liegt der Zustand des jetzt > + // aktuellen Tasks auf dem Stack, den wir auslesen koennen. Anschliessend > + // koennen wir in den Task zurueckspringen. > movl %eax, %esp > > + // Allzweckregister wiederherstellen > popl %ebx > popl %ecx > popl %edx > popl %esi > popl %edi > popl %ebp > - > - > + > + // Segmentregister wiederherstellen > popl %eax > movw %ax, %ds > - > + > popl %eax > movw %ax, %es > > pop %fs > pop %gs > - > + > + // eax wiederherstellen > popl %eax > > // Fehler- und Interruptnummer von Stack loeschen > addl $8, %esp > + > + // Ruecksprung in den Task > iret > > > + > // Double Fault > .globl im_int_stub_8 > .extern double_fault_tss Sonst fällt mir da eigentlich nichts auf. Also rein damit. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Mon Apr 27 23:18:35 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 27 Apr 2009 23:18:35 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Schreibvorgaenge auf mehrere TCP-Pakete aufteilen Message-ID: <1240867115-10532-1-git-send-email-kevin@tyndur.org> ! tcpip: Beim Senden von TCP-Paketen sollte man die MSS nicht ueberschreiten, sonst spielt der Netzwerktreiber nicht mehr mit und man kann keine Foreneintraege abschicken. Daher werden in der LostIO-Schnittstelle jetzt die Daten auf mehrere Pakete verteilt. --- src/modules/tcpip/include/tcp.h | 7 +++++++ src/modules/tcpip/lostio_if.c | 24 ++++++++++++++++++------ src/modules/tcpip/tcp.c | 10 ++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/modules/tcpip/include/tcp.h b/src/modules/tcpip/include/tcp.h index e325ae7..42b5699 100644 --- a/src/modules/tcpip/include/tcp.h +++ b/src/modules/tcpip/include/tcp.h @@ -121,4 +121,11 @@ void tcp_update_checksum void tcp_receive(dword source_ip, void* data, dword data_size); void tcp_send_ack(struct tcp_connection* conn); // TODO Ersetzen +/** + * Gibt die MSS (Maximum Segment Size) fuer eine TCP-Verbindung zurueck, d.h. + * die maximale Anzahl Bytes, die als Nutzdaten in einem TCP-Paket uebertragen + * werden koennen + */ +size_t tcp_get_mss(struct tcp_connection* conn); + #endif diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c index 5b4037b..410d221 100644 --- a/src/modules/tcpip/lostio_if.c +++ b/src/modules/tcpip/lostio_if.c @@ -293,13 +293,25 @@ size_t lostio_tcp_write return 0; } - struct tcp_out_buffer* out_buffer = malloc(sizeof(*out_buffer)); - out_buffer->data = data; - out_buffer->size = blocksize * count; + // Zu schreibende Teile auf passende Paketgroessen zusammenhacken und in + // den ausgehenden Puffer speichern + struct tcp_out_buffer* out_buffer; + size_t size = blocksize * count; + size_t mss = tcp_get_mss(conn); + while (size > 0) { + size_t packet_size = size > mss ? mss : size; - list_insert(conn->out_buffer, list_size(conn->out_buffer), out_buffer); - //list_push(conn->out_buffer, "GET / HTTP/1.0\r\n\r\n"); - + out_buffer = malloc(packet_size); + out_buffer->data = data; + out_buffer->size = packet_size; + + list_insert(conn->out_buffer, list_size(conn->out_buffer), out_buffer); + + data += packet_size; + size -= packet_size; + } + + // Ausgehenden Puffer senden while (!list_is_empty(conn->out_buffer)) { tcp_send_ack(conn); } diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c index 7e63c9e..7eac8b2 100644 --- a/src/modules/tcpip/tcp.c +++ b/src/modules/tcpip/tcp.c @@ -81,6 +81,16 @@ static word tcp_get_free_port(void) return source_port++; } +/** + * Gibt die MSS (Maximum Segment Size) fuer eine TCP-Verbindung zurueck, d.h. + * die maximale Anzahl Bytes, die als Nutzdaten in einem TCP-Paket uebertragen + * werden koennen + */ +size_t tcp_get_mss(struct tcp_connection* conn) +{ + return 1500 - sizeof(struct ip_header) - sizeof(struct tcp_header); +} + static void tcp_send_packet(struct tcp_connection* conn, void* data, dword data_size, byte flags) { -- 1.6.0.2 From toni at tyndur.org Tue Apr 28 12:18:12 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Tue, 28 Apr 2009 12:18:12 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Schreibvorgaenge auf mehrere TCP-Pakete aufteilen In-Reply-To: <1240867115-10532-1-git-send-email-kevin@tyndur.org> References: <1240867115-10532-1-git-send-email-kevin@tyndur.org> Message-ID: <20090428101811.GA13437@thales.produktiv.lan> On Mon, Apr 27 23:18, Kevin Wolf wrote: > ! tcpip: Beim Senden von TCP-Paketen sollte man die MSS nicht > ueberschreiten, sonst spielt der Netzwerktreiber nicht mehr mit und > man kann keine Foreneintraege abschicken. Daher werden in der > LostIO-Schnittstelle jetzt die Daten auf mehrere Pakete verteilt. > --- > src/modules/tcpip/include/tcp.h | 7 +++++++ > src/modules/tcpip/lostio_if.c | 24 ++++++++++++++++++------ > src/modules/tcpip/tcp.c | 10 ++++++++++ > 3 files changed, 35 insertions(+), 6 deletions(-) > > diff --git a/src/modules/tcpip/include/tcp.h b/src/modules/tcpip/include/tcp.h > index e325ae7..42b5699 100644 > --- a/src/modules/tcpip/include/tcp.h > +++ b/src/modules/tcpip/include/tcp.h > @@ -121,4 +121,11 @@ void tcp_update_checksum > void tcp_receive(dword source_ip, void* data, dword data_size); > void tcp_send_ack(struct tcp_connection* conn); // TODO Ersetzen > > +/** > + * Gibt die MSS (Maximum Segment Size) fuer eine TCP-Verbindung zurueck, d.h. > + * die maximale Anzahl Bytes, die als Nutzdaten in einem TCP-Paket uebertragen > + * werden koennen > + */ > +size_t tcp_get_mss(struct tcp_connection* conn); > + > #endif > diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c > index 5b4037b..410d221 100644 > --- a/src/modules/tcpip/lostio_if.c > +++ b/src/modules/tcpip/lostio_if.c > @@ -293,13 +293,25 @@ size_t lostio_tcp_write > return 0; > } > > - struct tcp_out_buffer* out_buffer = malloc(sizeof(*out_buffer)); > - out_buffer->data = data; > - out_buffer->size = blocksize * count; > + // Zu schreibende Teile auf passende Paketgroessen zusammenhacken und in > + // den ausgehenden Puffer speichern > + struct tcp_out_buffer* out_buffer; > + size_t size = blocksize * count; > + size_t mss = tcp_get_mss(conn); > + while (size > 0) { > + size_t packet_size = size > mss ? mss : size; > > - list_insert(conn->out_buffer, list_size(conn->out_buffer), out_buffer); > - //list_push(conn->out_buffer, "GET / HTTP/1.0\r\n\r\n"); > - > + out_buffer = malloc(packet_size); Hm, was hat packet_size mit der Groesse der Struktur zu tun? :-/ > + out_buffer->data = data; > + out_buffer->size = packet_size; > + > + list_insert(conn->out_buffer, list_size(conn->out_buffer), out_buffer); > + > + data += packet_size; > + size -= packet_size; > + } > + > + // Ausgehenden Puffer senden > while (!list_is_empty(conn->out_buffer)) { > tcp_send_ack(conn); > } Ich glaube abgesehen davon sieht das, soweit ich es beurteilen kann, vernuenftig aus. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From alex at tyndur.org Tue Apr 28 17:11:02 2009 From: alex at tyndur.org (Alexander Siol) Date: Tue, 28 Apr 2009 17:11:02 +0200 Subject: [tyndur-devel] [PATCH] ElTorito-CD-Images In-Reply-To: <200904112146.01521@kevin-wolf.de> References: <20090407204620.GA4582@alex.local.siol> <200904112146.01521@kevin-wolf.de> Message-ID: <20090428151102.GA9207@alex.local.siol> So, alles im neuen Patch (Anhang) gefixt. -- Alexander Siol alex at tyndur.org dunklermeuchler at gmail.com -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : cdrom_eltorito_images.patch Dateityp : text/x-diff Dateigröße : 2023 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From alex at tyndur.org Tue Apr 28 17:29:05 2009 From: alex at tyndur.org (Alexander Siol) Date: Tue, 28 Apr 2009 17:29:05 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_Fix_f=FCr_=5FSVN-Verzei?= =?iso-8859-1?q?chnisse_auf_CD-Images?= Message-ID: <20090428152905.GB9207@alex.local.siol> Momentan enthalten die Images unschöne _SVN (ursprünglich .svn)-Dirs, die für nichts gut sind. Der Patch sorgt dafür das sie nicht entstehen. -- Alexander Siol alex at tyndur.org dunklermeuchler at gmail.com -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : cdrom_svndir_fix.patch Dateityp : text/x-diff Dateigröße : 1644 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From alex at tyndur.org Tue Apr 28 17:31:10 2009 From: alex at tyndur.org (Alexander Siol) Date: Tue, 28 Apr 2009 17:31:10 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_Fix_f=FCr_=5FSVN-Verzei?= =?iso-8859-1?q?chnisse_auf_CD-Images?= In-Reply-To: <20090428152905.GB9207@alex.local.siol> References: <20090428152905.GB9207@alex.local.siol> Message-ID: <20090428153110.GC9207@alex.local.siol> Grade gesehen das der Patch dummerweise auch die ElTorito-Sachen enthält, liegt an SVN ;) -- Alexander Siol alex at tyndur.org dunklermeuchler at gmail.com -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From mail at kevin-wolf.de Tue Apr 28 22:47:57 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Tue, 28 Apr 2009 22:47:57 +0200 Subject: [tyndur-devel] [PATCH] ElTorito-CD-Images In-Reply-To: <20090428151102.GA9207@alex.local.siol> References: <20090407204620.GA4582@alex.local.siol> <200904112146.01521@kevin-wolf.de> <20090428151102.GA9207@alex.local.siol> Message-ID: <200904282247.57820@kevin-wolf.de> Am Dienstag, 28. April 2009 17:11 schrieb Alexander Siol: > So, alles im neuen Patch (Anhang) gefixt. Sieht vernünftig aus. From mail at kevin-wolf.de Tue Apr 28 22:49:50 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Tue, 28 Apr 2009 22:49:50 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_Fix_f=C3=BCr_=5FSVN-Verzeich?= =?utf-8?q?nisse_auf_CD-Images?= In-Reply-To: <20090428152905.GB9207@alex.local.siol> References: <20090428152905.GB9207@alex.local.siol> Message-ID: <200904282249.50551@kevin-wolf.de> Am Dienstag, 28. April 2009 17:29 schrieb Alexander Siol: > Momentan enthalten die Images unschöne _SVN (ursprünglich .svn)-Dirs, die > für nichts gut sind. Der Patch sorgt dafür das sie nicht entstehen. Wenn du die Patches sauber trennst, darfst du auch das committen.