diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile index a2334125..ea9a751a 100644 --- a/libmaxsi/Makefile +++ b/libmaxsi/Makefile @@ -42,7 +42,6 @@ sortix-sound.o \ readparamstring.o \ process.o \ thread.o \ -io.o \ ioleast.o \ winsize.o \ terminal.o \ @@ -66,6 +65,34 @@ sort.o \ string.o \ error.o \ format.o \ +access.o \ +chdir.o \ +chmod.o \ +close.o \ +dup.o \ +errorprint.o \ +fchmod.o \ +fcntl.o \ +fstat.o \ +ftruncate.o \ +getcwd.o \ +getdtablesize.o \ +lseek.o \ +mbtowc.o \ +mkdir.o \ +mktemp.o \ +open.o \ +pipe.o \ +print.o \ +read.o \ +readdirents.o \ +rmdir.o \ +scan.o \ +stat.o \ +truncate.o \ +umask.o \ +unlink.o \ +write.o \ UNPROCHEADERDIRS:=$(shell find include -type d) UNPROCHEADERS:=$(shell find include -type f) diff --git a/libmaxsi/access.cpp b/libmaxsi/access.cpp new file mode 100644 index 00000000..54957b60 --- /dev/null +++ b/libmaxsi/access.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + access.cpp + Check real user's permissions for a file + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL2(int, SysAccess, SYSCALL_ACCESS, const char*, int); + +extern "C" int access(const char* pathname, int mode) +{ + return SysAccess(pathname, mode); +} + +} // namespace Maxsi diff --git a/libmaxsi/chdir.cpp b/libmaxsi/chdir.cpp new file mode 100644 index 00000000..ea514ec8 --- /dev/null +++ b/libmaxsi/chdir.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + chdir.cpp + Changes the current working directory. + +*******************************************************************************/ + +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL1(int, SysChDir, SYSCALL_CHDIR, const char*); + +extern "C" int chdir(const char* path) +{ + return SysChDir(path); +} + +} // namespace Maxsi diff --git a/libmaxsi/chmod.cpp b/libmaxsi/chmod.cpp new file mode 100644 index 00000000..e13b33d2 --- /dev/null +++ b/libmaxsi/chmod.cpp @@ -0,0 +1,39 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + chmod.cpp + Changes the mode bits of a file. + +*******************************************************************************/ + +#include +#include +#include +#include + +namespace Maxsi { + +// TODO: Implement this in the kernel. +extern "C" int chmod(const char* path, mode_t mode) +{ + errno = ENOSYS; + return -1; +} + +} // namespace Maxsi diff --git a/libmaxsi/close.cpp b/libmaxsi/close.cpp new file mode 100644 index 00000000..d18bbdf7 --- /dev/null +++ b/libmaxsi/close.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + close.cpp + Closes a file descriptor. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL1(int, SysClose, SYSCALL_CLOSE, int); + +extern "C" int close(int fd) +{ + return SysClose(fd); +} + +} // namespace Maxsi diff --git a/libmaxsi/dup.cpp b/libmaxsi/dup.cpp new file mode 100644 index 00000000..65484a16 --- /dev/null +++ b/libmaxsi/dup.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + dup.cpp + Duplicates a file descriptor. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL1(int, SysDup, SYSCALL_DUP, int); + +extern "C" int dup(int fd) +{ + return SysDup(fd); +} + +} // namespace Maxsi diff --git a/libmaxsi/errorprint.cpp b/libmaxsi/errorprint.cpp new file mode 100644 index 00000000..9b4be3ba --- /dev/null +++ b/libmaxsi/errorprint.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + errorprint.cpp + Functions for printing error messages to the terminal. + +*******************************************************************************/ + +#include +#include +#include +#include +#include +#include + +extern "C" void gnu_error(int status, int errnum, const char *format, ...) +{ + fprintf(stderr, "%s: ", program_invocation_name); + + va_list list; + va_start(list, format); + vfprintf(stderr, format, list); + va_end(list); + + if ( errnum ) + fprintf(stderr, ": %s", strerror(errnum)); + fprintf(stderr, "\n"); + if ( status ) + exit(status); +} + +extern "C" void perror(const char* s) +{ + error(0, errno, "%s", s); +} diff --git a/libmaxsi/fchmod.cpp b/libmaxsi/fchmod.cpp new file mode 100644 index 00000000..7319d8f0 --- /dev/null +++ b/libmaxsi/fchmod.cpp @@ -0,0 +1,39 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + fchmod.cpp + Changes the mode bits of an open file. + +*******************************************************************************/ + +#include +#include +#include +#include + +namespace Maxsi { + +// TODO: Implement this in the kernel. +extern "C" int fchmod(int fd, mode_t mode) +{ + errno = ENOSYS; + return -1; +} + +} // namespace Maxsi diff --git a/libmaxsi/fcntl.cpp b/libmaxsi/fcntl.cpp new file mode 100644 index 00000000..b5cb8fa3 --- /dev/null +++ b/libmaxsi/fcntl.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + fcntl.cpp + Manipulates a file descriptor. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL3(int, SysFCntl, SYSCALL_FCNTL, int, int, unsigned long); + +extern "C" int fcntl(int fd, int cmd, unsigned long arg) +{ + return SysFCntl(fd, cmd, arg); +} + +} // namespace Maxsi diff --git a/libmaxsi/fstat.cpp b/libmaxsi/fstat.cpp new file mode 100644 index 00000000..54f62d0e --- /dev/null +++ b/libmaxsi/fstat.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + fstat.cpp + Retrieves status of an open file. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*); + +extern "C" int fstat(int fd, struct stat* st) +{ + return SysFStat(fd, st); +} + +} // namespace Maxsi diff --git a/libmaxsi/ftruncate.cpp b/libmaxsi/ftruncate.cpp new file mode 100644 index 00000000..8aa2f6d6 --- /dev/null +++ b/libmaxsi/ftruncate.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + ftruncate.cpp + Truncates an open file to a specific size. + +*******************************************************************************/ + +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL2(int, SysFTruncate, SYSCALL_FTRUNCATE, int, off_t); + +extern "C" int ftruncate(int fd, off_t length) +{ + return SysFTruncate(fd, length); +} + +} // namespace Maxsi diff --git a/libmaxsi/getcwd.cpp b/libmaxsi/getcwd.cpp new file mode 100644 index 00000000..e5616ecb --- /dev/null +++ b/libmaxsi/getcwd.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + getcwd.cpp + Returns the current working directory. + +*******************************************************************************/ + +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL2(char*, SysGetCWD, SYSCALL_GETCWD, char*, size_t); + +extern "C" char* getcwd(char* buf, size_t size) +{ + return SysGetCWD(buf, size); +} + +} // namespace Maxsi diff --git a/libmaxsi/getdtablesize.cpp b/libmaxsi/getdtablesize.cpp new file mode 100644 index 00000000..d89f0714 --- /dev/null +++ b/libmaxsi/getdtablesize.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + getdtablesize.cpp + Get descriptor table size. + +*******************************************************************************/ + +#include + +// TODO: This has been replaced with sysconf(_SC_OPEN_MAX). This is only +// here for compatibility with gzip and should be removed as soon as sysconf +// is implemented. +extern "C" int getdtablesize(void) +{ + return 0x10000; +} diff --git a/libmaxsi/io.cpp b/libmaxsi/io.cpp deleted file mode 100644 index 02d74ec9..00000000 --- a/libmaxsi/io.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/******************************************************************************* - - COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012. - - This file is part of LibMaxsi. - - LibMaxsi is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License - along with LibMaxsi. If not, see . - - io.cpp - Functions for management of input and output. - -*******************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Maxsi -{ - DEFN_SYSCALL1(size_t, SysPrint, SYSCALL_PRINT_STRING, const char*); - DEFN_SYSCALL3(ssize_t, SysRead, SYSCALL_READ, int, void*, size_t); - DEFN_SYSCALL3(ssize_t, SysWrite, SYSCALL_WRITE, int, const void*, size_t); - DEFN_SYSCALL1(int, SysPipe, SYSCALL_PIPE, int*); - DEFN_SYSCALL1(int, SysClose, SYSCALL_CLOSE, int); - DEFN_SYSCALL1(int, SysDup, SYSCALL_DUP, int); - DEFN_SYSCALL3(int, SysOpen, SYSCALL_OPEN, const char*, int, mode_t); - DEFN_SYSCALL3(int, SysReadDirEnts, SYSCALL_READDIRENTS, int, struct sortix_dirent*, size_t); - DEFN_SYSCALL1(int, SysChDir, SYSCALL_CHDIR, const char*); - DEFN_SYSCALL2(char*, SysGetCWD, SYSCALL_GETCWD, char*, size_t); - DEFN_SYSCALL1(int, SysUnlink, SYSCALL_UNLINK, const char*); - DEFN_SYSCALL3_VOID(SysSeek, SYSCALL_SEEK, int, off_t*, int); - DEFN_SYSCALL2(int, SysMkDir, SYSCALL_MKDIR, const char*, mode_t); - DEFN_SYSCALL1(int, SysRmDir, SYSCALL_RMDIR, const char*); - DEFN_SYSCALL2(int, SysTruncate, SYSCALL_TRUNCATE, const char*, off_t); - DEFN_SYSCALL2(int, SysFTruncate, SYSCALL_FTRUNCATE, int, off_t); - DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*); - DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*); - DEFN_SYSCALL3(int, SysFCntl, SYSCALL_FCNTL, int, int, unsigned long); - DEFN_SYSCALL2(int, SysAccess, SYSCALL_ACCESS, const char*, int); - - size_t Print(const char* string) - { - size_t stringlen = String::Length(string); - return writeall(1, string, stringlen); - } - - size_t PrintCallback(void* user, const char* string, size_t stringlen) - { - return writeall(1, string, stringlen); - } - - size_t PrintF(const char* format, ...) - { - va_list list; - va_start(list, format); - size_t result = Maxsi::Format::Virtual(PrintCallback, NULL, format, list); - va_end(list); - return result; - } - -#ifdef LIBMAXSI_LIBC - size_t FileWriteCallback(void* user, const char* string, size_t stringlen) - { - FILE* fp = (FILE*) user; - return fwrite(string, 1, stringlen, fp); - } - - extern "C" int vfprintf(FILE* fp, const char* /*restrict*/ format, va_list list) - { - size_t result = Maxsi::Format::Virtual(FileWriteCallback, fp, format, list); - return (int) result; - } - - extern "C" int fprintf(FILE* fp, const char* /*restrict*/ format, ...) - { - va_list list; - va_start(list, format); - size_t result = vfprintf(fp, format, list); - va_end(list); - return (int) result; - } - - extern "C" int vprintf(const char* /*restrict*/ format, va_list list) - { - size_t result = vfprintf(stdout, format, list); - return (int) result; - } - - extern "C" int printf(const char* /*restrict*/ format, ...) - { - va_list list; - va_start(list, format); - size_t result = vprintf(format, list); - va_end(list); - return (int) result; - } - - // TODO: This is an ugly hack to help build binutils. - #warning Ugly sscanf hack to help build binutils - extern "C" int sscanf(const char* s, const char* format, ...) - { - if ( strcmp(format, "%x") != 0 ) - { - fprintf(stderr, "sscanf hack doesn't implement: '%s'\n", format); - abort(); - } - - va_list list; - va_start(list, format); - unsigned* dec = va_arg(list, unsigned*); - *dec = strtol(s, NULL, 16); - return strlen(s); - } - - typedef struct vsnprintf_struct - { - char* str; - size_t size; - size_t produced; - size_t written; - } vsnprintf_t; - - size_t StringPrintCallback(void* user, const char* string, size_t stringlen) - { - vsnprintf_t* info = (vsnprintf_t*) user; - if ( info->produced < info->size ) - { - size_t available = info->size - info->produced; - size_t possible = (stringlen < available) ? stringlen : available; - Memory::Copy(info->str + info->produced, string, possible); - info->written += possible; - } - info->produced += stringlen; - return stringlen; - } - - extern "C" int vsnprintf(char* restrict str, size_t size, const char* restrict format, va_list list) - { - vsnprintf_t info; - info.str = str; - info.size = (size) ? size-1 : 0; - info.produced = 0; - info.written = 0; - Maxsi::Format::Virtual(StringPrintCallback, &info, format, list); - if ( size ) { info.str[info.written] = '\0'; } - return (int) info.produced; - } - - extern "C" int snprintf(char* restrict str, size_t size, const char* restrict format, ...) - { - va_list list; - va_start(list, format); - int result = vsnprintf(str, size, format, list); - va_end(list); - return result; - } - - extern "C" int vsprintf(char* restrict str, const char* restrict format, va_list list) - { - return vsnprintf(str, SIZE_MAX, format, list); - } - - extern "C" int sprintf(char* restrict str, const char* restrict format, ...) - { - va_list list; - va_start(list, format); - int result = vsprintf(str, format, list); - va_end(list); - return result; - } - - extern "C" void gnu_error(int status, int errnum, const char *format, ...) - { - fprintf(stderr, "%s: ", program_invocation_name); - - va_list list; - va_start(list, format); - vfprintf(stderr, format, list); - va_end(list); - - if ( errnum ) { fprintf(stderr, ": %s", strerror(errnum)); } - fprintf(stderr, "\n"); - if ( status ) { exit(status); } - } - - extern "C" void perror(const char* s) - { - error(0, errno, "%s", s); - } - - extern "C" ssize_t read(int fd, void* buf, size_t count) - { -retry: - ssize_t result = SysRead(fd, buf, count); - if ( result < 0 && errno == EAGAIN ) { goto retry; } - return result; - } - - extern "C" ssize_t write(int fd, const void* buf, size_t count) - { -retry: - ssize_t result = SysWrite(fd, buf, count); - if ( result < 0 && errno == EAGAIN ) { goto retry; } - return result; - } - - extern "C" ssize_t pread(int, void*, size_t, off_t) - { - errno = ENOSYS; - return -1; - } - - extern "C" ssize_t pwrite(int, const void*, size_t, off_t) - { - errno = ENOSYS; - return -1; - } - - extern "C" off_t lseek(int fd, off_t offset, int whence) - { - SysSeek(fd, &offset, whence); - return offset; - } - - extern "C" int pipe(int pipefd[2]) - { - return SysPipe(pipefd); - } - - extern "C" int close(int fd) - { - return SysClose(fd); - } - - extern "C" int dup(int fd) - { - return SysDup(fd); - } - - extern "C" int open(const char* path, int flags, mode_t mode) - { - return SysOpen(path, flags, mode); - } - - extern "C" int readdirents(int fd, struct sortix_dirent* dirent, size_t size) - { - return SysReadDirEnts(fd, dirent, size); - } - - extern "C" int chdir(const char* path) - { - return SysChDir(path); - } - - extern "C" char* getcwd(char* buf, size_t size) - { - return SysGetCWD(buf, size); - } - - extern "C" int unlink(const char* pathname) - { - return SysUnlink(pathname); - } - - extern "C" int mkdir(const char* pathname, mode_t mode) - { - return SysMkDir(pathname, mode); - } - - extern "C" int rmdir(const char* pathname) - { - return SysRmDir(pathname); - } - - extern "C" int truncate(const char* pathname, off_t length) - { - return SysTruncate(pathname, length); - } - - extern "C" int ftruncate(int fd, off_t length) - { - return SysFTruncate(fd, length); - } - - extern "C" int stat(const char* path, struct stat* st) - { - return SysStat(path, st); - } - - extern "C" int lstat(const char* path, struct stat* st) - { - return SysStat(path, st); - } - - extern "C" int fstat(int fd, struct stat* st) - { - return SysFStat(fd, st); - } - - extern "C" int fcntl(int fd, int cmd, unsigned long arg) - { - return SysFCntl(fd, cmd, arg); - } - - extern "C" int access(const char* pathname, int mode) - { - return SysAccess(pathname, mode); - } - - // TODO: Implement these in the kernel. - extern "C" int chmod(const char* path, mode_t mode) - { - errno = ENOTSUP; - return -1; - } - - // TODO: Implement these in the kernel. - extern "C" int fchmod(int fd, mode_t mode) - { - errno = ENOTSUP; - return -1; - } - - // TODO: Implement these in the kernel. - extern "C" mode_t umask(mode_t mask) - { - return 0; - } - - // TODO: This is a hacky implementation of a stupid function. - extern "C" char* mktemp(char* templ) - { - size_t templlen = strlen(templ); - for ( size_t i = templlen-6UL; i < templlen; i++ ) - { - templ[i] = '0' + rand() % 10; - } - return templ; - } - - // TODO: This has been replaced with sysconf(_SC_OPEN_MAX). This is only - // here for compatibility with gzip and should be removed as soon as sysconf - // is implemented. - extern "C" int getdtablesize(void) - { - return 0x10000; - } - - extern "C" int fscanf(FILE* /*fp*/, const char* /*format*/, ...) - { - fprintf(stderr, "fscanf(3) is not implemented\n"); - abort(); - } - - extern "C" int mbtowc(wchar_t* /*pwd*/, const char* /*s*/, size_t /*n*/) - { - fprintf(stderr, "mbtowc(3) is not implemented\n"); - abort(); - } -#endif - -} diff --git a/libmaxsi/lseek.cpp b/libmaxsi/lseek.cpp new file mode 100644 index 00000000..025fc5c4 --- /dev/null +++ b/libmaxsi/lseek.cpp @@ -0,0 +1,39 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + lseek.cpp + Sets the offset on a file descriptor. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL3_VOID(SysSeek, SYSCALL_SEEK, int, off_t*, int); + +extern "C" off_t lseek(int fd, off_t offset, int whence) +{ + SysSeek(fd, &offset, whence); + return offset; +} + +} // namespace Maxsi diff --git a/libmaxsi/mbtowc.cpp b/libmaxsi/mbtowc.cpp new file mode 100644 index 00000000..856a142d --- /dev/null +++ b/libmaxsi/mbtowc.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + mbtowc.cpp + Convert a multibyte sequence to a wide character. + +*******************************************************************************/ + +#include +#include + +extern "C" int mbtowc(wchar_t* /*pwd*/, const char* /*s*/, size_t /*n*/) +{ + fprintf(stderr, "mbtowc(3) is not implemented\n"); + abort(); +} diff --git a/libmaxsi/mkdir.cpp b/libmaxsi/mkdir.cpp new file mode 100644 index 00000000..c56eaff9 --- /dev/null +++ b/libmaxsi/mkdir.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + mkdir.cpp + Creates a new directory. + +*******************************************************************************/ + +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL2(int, SysMkDir, SYSCALL_MKDIR, const char*, mode_t); + +extern "C" int mkdir(const char* pathname, mode_t mode) +{ + return SysMkDir(pathname, mode); +} + +} // namespace Maxsi diff --git a/libmaxsi/mktemp.cpp b/libmaxsi/mktemp.cpp new file mode 100644 index 00000000..d0a5d7ec --- /dev/null +++ b/libmaxsi/mktemp.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + mktemp.cpp + Make a unique temporary filename. + +*******************************************************************************/ + +#include +#include + +// TODO: This is a hacky implementation of a stupid function. +extern "C" char* mktemp(char* templ) +{ + size_t templlen = strlen(templ); + for ( size_t i = templlen-6UL; i < templlen; i++ ) + { + templ[i] = '0' + rand() % 10; + } + return templ; +} diff --git a/libmaxsi/open.cpp b/libmaxsi/open.cpp new file mode 100644 index 00000000..6b224e9c --- /dev/null +++ b/libmaxsi/open.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + dup.cpp + Duplicates a file descriptor. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL3(int, SysOpen, SYSCALL_OPEN, const char*, int, mode_t); + +extern "C" int open(const char* path, int flags, mode_t mode) +{ + return SysOpen(path, flags, mode); +} + +} // namespace Maxsi diff --git a/libmaxsi/pipe.cpp b/libmaxsi/pipe.cpp new file mode 100644 index 00000000..80733e14 --- /dev/null +++ b/libmaxsi/pipe.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + pipe.cpp + Creates a pair of file descriptors with a reading and writing end. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL1(int, SysPipe, SYSCALL_PIPE, int*); + +extern "C" int pipe(int pipefd[2]) +{ + return SysPipe(pipefd); +} + +} // namespace Maxsi diff --git a/libmaxsi/print.cpp b/libmaxsi/print.cpp new file mode 100644 index 00000000..fe5a391f --- /dev/null +++ b/libmaxsi/print.cpp @@ -0,0 +1,127 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + print.cpp + Provides the stubs for the printf family of functions. + +*******************************************************************************/ + +#include +#include +#include +#include +#include +#include + +namespace Maxsi { + +static size_t FileWriteCallback(void* user, const char* string, size_t stringlen) +{ + FILE* fp = (FILE*) user; + return fwrite(string, 1, stringlen, fp); +} + +extern "C" int vfprintf(FILE* fp, const char* /*restrict*/ format, va_list list) +{ + size_t result = Maxsi::Format::Virtual(FileWriteCallback, fp, format, list); + return (int) result; +} + +extern "C" int fprintf(FILE* fp, const char* /*restrict*/ format, ...) +{ + va_list list; + va_start(list, format); + size_t result = vfprintf(fp, format, list); + va_end(list); + return (int) result; +} + +extern "C" int vprintf(const char* /*restrict*/ format, va_list list) +{ + size_t result = vfprintf(stdout, format, list); + return (int) result; +} + +extern "C" int printf(const char* /*restrict*/ format, ...) +{ + va_list list; + va_start(list, format); + size_t result = vprintf(format, list); + va_end(list); + return (int) result; +} + +typedef struct vsnprintf_struct +{ + char* str; + size_t size; + size_t produced; + size_t written; +} vsnprintf_t; + +static size_t StringPrintCallback(void* user, const char* string, size_t stringlen) +{ + vsnprintf_t* info = (vsnprintf_t*) user; + if ( info->produced < info->size ) + { + size_t available = info->size - info->produced; + size_t possible = (stringlen < available) ? stringlen : available; + memcpy(info->str + info->produced, string, possible); + info->written += possible; + } + info->produced += stringlen; + return stringlen; +} + +extern "C" int vsnprintf(char* restrict str, size_t size, const char* restrict format, va_list list) +{ + vsnprintf_t info; + info.str = str; + info.size = (size) ? size-1 : 0; + info.produced = 0; + info.written = 0; + Maxsi::Format::Virtual(StringPrintCallback, &info, format, list); + if ( size ) { info.str[info.written] = '\0'; } + return (int) info.produced; +} + +extern "C" int snprintf(char* restrict str, size_t size, const char* restrict format, ...) +{ + va_list list; + va_start(list, format); + int result = vsnprintf(str, size, format, list); + va_end(list); + return result; +} + +extern "C" int vsprintf(char* restrict str, const char* restrict format, va_list list) +{ + return vsnprintf(str, SIZE_MAX, format, list); +} + +extern "C" int sprintf(char* restrict str, const char* restrict format, ...) +{ + va_list list; + va_start(list, format); + int result = vsprintf(str, format, list); + va_end(list); + return result; +} + +} // namespace Maxsi diff --git a/libmaxsi/read.cpp b/libmaxsi/read.cpp new file mode 100644 index 00000000..a138282d --- /dev/null +++ b/libmaxsi/read.cpp @@ -0,0 +1,48 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + read.cpp + Reads from a file descriptor. + +*******************************************************************************/ + +#include +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL3(ssize_t, SysRead, SYSCALL_READ, int, void*, size_t); + +extern "C" ssize_t read(int fd, void* buf, size_t count) +{ +retry: + ssize_t result = SysRead(fd, buf, count); + if ( result < 0 && errno == EAGAIN ) { goto retry; } + return result; +} + +extern "C" ssize_t pread(int, void*, size_t, off_t) +{ + errno = ENOSYS; + return -1; +} + +} // namespace Maxsi diff --git a/libmaxsi/readdirents.cpp b/libmaxsi/readdirents.cpp new file mode 100644 index 00000000..6ef29882 --- /dev/null +++ b/libmaxsi/readdirents.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + readdirents.cpp + Reads entries from a directory file descriptor. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL3(int, SysReadDirEnts, SYSCALL_READDIRENTS, int, struct sortix_dirent*, size_t); + +extern "C" int readdirents(int fd, struct sortix_dirent* dirent, size_t size) +{ + return SysReadDirEnts(fd, dirent, size); +} + +} // namespace Maxsi diff --git a/libmaxsi/rmdir.cpp b/libmaxsi/rmdir.cpp new file mode 100644 index 00000000..a9cbdc63 --- /dev/null +++ b/libmaxsi/rmdir.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + rmdir.cpp + Removes an empty directory. + +*******************************************************************************/ + +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL1(int, SysRmDir, SYSCALL_RMDIR, const char*); + +extern "C" int rmdir(const char* pathname) +{ + return SysRmDir(pathname); +} + +} // namespace Maxsi diff --git a/libmaxsi/scan.cpp b/libmaxsi/scan.cpp new file mode 100644 index 00000000..6d4076f7 --- /dev/null +++ b/libmaxsi/scan.cpp @@ -0,0 +1,58 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + scan.cpp + The scanf family of functions. + +*******************************************************************************/ + +#include +#include +#include +#include +#include +#include + +namespace Maxsi { + + +// TODO: This is an ugly hack to help build binutils. +#warning Ugly sscanf hack to help build binutils +extern "C" int sscanf(const char* s, const char* format, ...) +{ + if ( strcmp(format, "%x") != 0 ) + { + fprintf(stderr, "sscanf hack doesn't implement: '%s'\n", format); + abort(); + } + + va_list list; + va_start(list, format); + unsigned* dec = va_arg(list, unsigned*); + *dec = strtol(s, NULL, 16); + return strlen(s); +} + +extern "C" int fscanf(FILE* /*fp*/, const char* /*format*/, ...) +{ + fprintf(stderr, "fscanf(3) is not implemented\n"); + abort(); +} + +} // namespace Maxsi diff --git a/libmaxsi/stat.cpp b/libmaxsi/stat.cpp new file mode 100644 index 00000000..67ba8b03 --- /dev/null +++ b/libmaxsi/stat.cpp @@ -0,0 +1,44 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + stat.cpp + Retrieves status of a file. + +*******************************************************************************/ + +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*); + +extern "C" int stat(const char* path, struct stat* st) +{ + return SysStat(path, st); +} + +// TODO: Hack! +extern "C" int lstat(const char* path, struct stat* st) +{ + return SysStat(path, st); +} + +} // namespace Maxsi diff --git a/libmaxsi/truncate.cpp b/libmaxsi/truncate.cpp new file mode 100644 index 00000000..11dadcd7 --- /dev/null +++ b/libmaxsi/truncate.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + truncate.cpp + Truncates a file to a specific size. + +*******************************************************************************/ + +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL2(int, SysTruncate, SYSCALL_TRUNCATE, const char*, off_t); + +extern "C" int truncate(const char* pathname, off_t length) +{ + return SysTruncate(pathname, length); +} + +} // namespace Maxsi diff --git a/libmaxsi/umask.cpp b/libmaxsi/umask.cpp new file mode 100644 index 00000000..2d87a5e8 --- /dev/null +++ b/libmaxsi/umask.cpp @@ -0,0 +1,39 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + umask.cpp + Set file mode creation mask. + +*******************************************************************************/ + +#include +#include +#include +#include +#include + +namespace Maxsi { + +// TODO: Implement this in the kernel. +extern "C" mode_t umask(mode_t mask) +{ + return 0; +} + +} // namespace Maxsi diff --git a/libmaxsi/unlink.cpp b/libmaxsi/unlink.cpp new file mode 100644 index 00000000..3e911fb7 --- /dev/null +++ b/libmaxsi/unlink.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + unlink.cpp + Removes a directory entry. + +*******************************************************************************/ + +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL1(int, SysUnlink, SYSCALL_UNLINK, const char*); + +extern "C" int unlink(const char* pathname) +{ + return SysUnlink(pathname); +} + +} // namespace Maxsi diff --git a/libmaxsi/write.cpp b/libmaxsi/write.cpp new file mode 100644 index 00000000..c46c3f71 --- /dev/null +++ b/libmaxsi/write.cpp @@ -0,0 +1,48 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + write.cpp + Writes to a file descriptor. + +*******************************************************************************/ + +#include +#include +#include +#include + +namespace Maxsi { + +DEFN_SYSCALL3(ssize_t, SysWrite, SYSCALL_WRITE, int, const void*, size_t); + +extern "C" ssize_t write(int fd, const void* buf, size_t count) +{ +retry: + ssize_t result = SysWrite(fd, buf, count); + if ( result < 0 && errno == EAGAIN ) { goto retry; } + return result; +} + +extern "C" ssize_t pwrite(int, const void*, size_t, off_t) +{ + errno = ENOSYS; + return -1; +} + +} // namespace Maxsi