Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdio/perror.c
2 views
1
/* perror( const char * )
2
3
This file is part of the Public Domain C Library (PDCLib).
4
Permission is granted to use, modify, and / or redistribute at will.
5
*/
6
7
#include <stdio.h>
8
9
#ifndef REGTEST
10
#include <errno.h>
11
#include "_PDCLIB_locale.h"
12
13
/* TODO: Doing this via a static array is not the way to do it. */
14
void perror( const char * s )
15
{
16
if ( ( s != NULL ) && ( s[0] != '\n' ) )
17
{
18
fprintf( stderr, "%s: ", s );
19
}
20
if ( errno >= _PDCLIB_ERRNO_MAX )
21
{
22
fprintf( stderr, "Unknown error\n" );
23
}
24
else
25
{
26
fprintf( stderr, "%s\n", _PDCLIB_threadlocale()->_ErrnoStr[errno] );
27
}
28
return;
29
}
30
31
#endif
32
33
#ifdef TEST
34
#include "_PDCLIB_test.h"
35
#include <stdlib.h>
36
#include <string.h>
37
#include <limits.h>
38
39
int main( void )
40
{
41
FILE * fh;
42
unsigned long long max = ULLONG_MAX;
43
char buffer[100];
44
sprintf( buffer, "%llu", max );
45
TESTCASE( ( fh = freopen( testfile, "wb+", stderr ) ) != NULL );
46
TESTCASE( strtol( buffer, NULL, 10 ) == LONG_MAX );
47
perror( "Test" );
48
rewind( fh );
49
TESTCASE( fread( buffer, 1, 7, fh ) == 7 );
50
TESTCASE( memcmp( buffer, "Test: ", 6 ) == 0 );
51
TESTCASE( fclose( fh ) == 0 );
52
TESTCASE( remove( testfile ) == 0 );
53
return TEST_RESULTS;
54
}
55
56
#endif
57
58