mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add dprintf(3) and vdprintf(3).
This commit is contained in:
parent
91eb5f3af9
commit
bb2a1b3e73
4 changed files with 79 additions and 4 deletions
|
@ -37,6 +37,7 @@ signal/sigemptyset.o \
|
|||
signal/sigfillset.o \
|
||||
signal/sigismember.o \
|
||||
stdio/clearerr.o \
|
||||
stdio/dprintf.o \
|
||||
stdio/fbufsize.o \
|
||||
stdio/fclose.o \
|
||||
stdio/fdeletefile.o \
|
||||
|
@ -84,6 +85,7 @@ stdio/snprintf.o \
|
|||
stdio/sprintf.o \
|
||||
stdio/sscanf.o \
|
||||
stdio/ungetc.o \
|
||||
stdio/vdprintf.o \
|
||||
stdio/vfscanf.o \
|
||||
stdio/vsnprintf.o \
|
||||
stdio/vsprintf.o \
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _STDIO_H
|
||||
#define _STDIO_H 1
|
||||
#ifndef INCLUDE_STDIO_H
|
||||
#define INCLUDE_STDIO_H
|
||||
|
||||
#include <features.h>
|
||||
#include <sortix/seek.h>
|
||||
|
@ -72,6 +72,7 @@ extern FILE* stderr;
|
|||
#define stderr stderr
|
||||
|
||||
extern void clearerr(FILE* stream);
|
||||
extern int dprintf(int fildes, const char* __restrict format, ...);
|
||||
extern int fclose(FILE* stream);
|
||||
extern FILE* fdopen(int fildes, const char* mode);
|
||||
extern int feof(FILE* stream);
|
||||
|
@ -123,6 +124,7 @@ extern int scanf(const char* __restrict format, ...);
|
|||
extern int sscanf(const char* __restrict s, const char* __restrict format, ...);
|
||||
extern FILE* tmpfile(void);
|
||||
extern int ungetc(int c, FILE* stream);
|
||||
extern int vdprintf(int fildes, const char* __restrict format, __gnuc_va_list ap);
|
||||
extern int vfprintf(FILE* __restrict stream, const char* __restrict format, __gnuc_va_list ap);
|
||||
extern int vfscanf(FILE* __restrict stream, const char* __restrict format, __gnuc_va_list arg);
|
||||
extern int vprintf(const char* __restrict format, __gnuc_va_list ap);
|
||||
|
@ -140,12 +142,10 @@ extern char* tmpnam(char* s);
|
|||
extern char* ctermid(char* s);
|
||||
extern FILE *fmemopen(void* __restrict buf, size_t size, const char* __restrict mode);
|
||||
extern FILE* open_memstream(char** bufp, size_t* sizep);
|
||||
extern int dprintf(int fildes, const char* __restrict format, ...);
|
||||
extern int getchar_unlocked(void);
|
||||
extern int getc_unlocked(FILE* stream);
|
||||
extern int putchar_unlocked(int c);
|
||||
extern int putc_unlocked(int c, FILE* steam);
|
||||
extern int vdprintf(int fildes, const char* __restrict format, __gnuc_va_list ap);
|
||||
|
||||
#if __POSIX_OBSOLETE <= 200801
|
||||
extern char* tempnam(const char* dir, const char* pfx);
|
||||
|
|
35
libc/stdio/dprintf.cpp
Normal file
35
libc/stdio/dprintf.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library 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.
|
||||
|
||||
The Sortix C Library 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 the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
stdio/dprintf.cpp
|
||||
Prints a formatted string to a file descriptor.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" int dprintf(int fd, const char* restrict format, ...)
|
||||
{
|
||||
va_list list;
|
||||
va_start(list, format);
|
||||
int result = vdprintf(fd, format, list);
|
||||
va_end(list);
|
||||
return result;
|
||||
}
|
38
libc/stdio/vdprintf.cpp
Normal file
38
libc/stdio/vdprintf.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library 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.
|
||||
|
||||
The Sortix C Library 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 the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
stdio/vdprintf.cpp
|
||||
Prints a formatted string to a file descriptor.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static size_t write_callback(void* user, const char* string, size_t stringlen)
|
||||
{
|
||||
return writeall((int) (uintptr_t) user, string, stringlen * sizeof(char));
|
||||
}
|
||||
|
||||
extern "C" int vdprintf(int fd, const char* restrict format, va_list list)
|
||||
{
|
||||
return vprintf_callback(write_callback, (void*) (uintptr_t) fd, format, list);
|
||||
}
|
Loading…
Add table
Reference in a new issue