Split gnu_error(3) and perror(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-07-19 16:04:32 +02:00
parent 0c43765bbf
commit d79808f85f
4 changed files with 44 additions and 16 deletions

View File

@ -182,7 +182,7 @@ $(CPUDIR)/syscall.o \
dirent/fddir-sortix.o \ dirent/fddir-sortix.o \
dirent/scandir.o \ dirent/scandir.o \
dlfcn/dlfcn.o \ dlfcn/dlfcn.o \
error/errorprint.o \ error/gnu_error.o \
fcntl/creat.o \ fcntl/creat.o \
fcntl/fcntl.o \ fcntl/fcntl.o \
fcntl/openat.o \ fcntl/openat.o \
@ -244,6 +244,7 @@ stdio/fpipe.o \
stdio/freopen.o \ stdio/freopen.o \
stdio/fsetpos.o \ stdio/fsetpos.o \
stdio/getc.o \ stdio/getc.o \
stdio/perror.o \
stdio/popen.o \ stdio/popen.o \
stdio/print.o \ stdio/print.o \
stdio/putc.o \ stdio/putc.o \

View File

@ -17,17 +17,17 @@
You should have received a copy of the GNU Lesser General Public License 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/>. along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
error/errorprint.cpp error/gnu_error.cpp
Functions for printing error messages to the terminal. Prints an error message to stderr and optionally exits the process.
*******************************************************************************/ *******************************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <error.h> #include <error.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern "C" void gnu_error(int status, int errnum, const char *format, ...) extern "C" void gnu_error(int status, int errnum, const char *format, ...)
{ {
@ -44,8 +44,3 @@ extern "C" void gnu_error(int status, int errnum, const char *format, ...)
if ( status ) if ( status )
exit(status); exit(status);
} }
extern "C" void perror(const char* s)
{
error(0, errno, "%s", s);
}

View File

@ -22,16 +22,16 @@
*******************************************************************************/ *******************************************************************************/
#ifndef _ERROR_H #ifndef INCLUDE_ERROR_H
#define _ERROR_H 1 #define INCLUDE_ERROR_H
#include <features.h> #include <features.h>
__BEGIN_DECLS __BEGIN_DECLS
void gnu_error(int status, int errnum, const char *format, ...); void gnu_error(int status, int errnum, const char* format, ...);
#if __SORTIX_STDLIB_REDIRECTS #if __SORTIX_STDLIB_REDIRECTS
void error(int status, int errnum, const char *format, ...) asm("gnu_error"); void error(int status, int errnum, const char* format, ...) asm("gnu_error");
#endif #endif
__END_DECLS __END_DECLS

32
libc/stdio/perror.cpp Normal file
View File

@ -0,0 +1,32 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
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/perror.cpp
Prints a error messages to the terminal.
*******************************************************************************/
#include <errno.h>
#include <error.h>
#include <stdio.h>
extern "C" void perror(const char* s)
{
error(0, errno, "%s", s);
}