ppc64: Don't set Kp bit on SLB
[openbios/afaerber.git] / libc / misc.c
blobe7cf4f4084895275e29c30ef486f29ba80094ec3
1 /*
2 * Creation Date: <2002/10/19 21:05:07 samuel>
3 * Time-stamp: <2002/10/22 22:29:18 samuel>
5 * <misc.c>
7 * Miscellaneous
9 * Copyright (C) 2002, 2003 Samuel Rydh (samuel@ibrium.se)
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation
17 #include "config.h"
18 #include "libc/string.h"
20 int errno_int;
22 void
23 qsort( void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void*) )
25 unsigned int worked, i, j;
27 /* even more inefficient than the glibc variant :-) */
28 do {
29 char *p = base;
30 worked = 0;
31 for( i=0; i<nmemb-1; i++, p+= size ) {
32 if( compar( p, p + size ) > 0 ) {
33 worked = 1;
34 for( j=0; j<size; j++ ) {
35 char ch = p[j];
36 p[j] = p[j+size];
37 p[j+size] = ch;
41 } while( worked );
45 long int
46 strtol( const char *nptr, char **endptr, int base )
48 int sum, n, sign=1;
49 while( isspace(*nptr) )
50 nptr++;
52 if( *nptr == '-' || *nptr == '+' )
53 sign = (*nptr++ == '-') ? -1 : 1;
55 if( base == 16 || base == 0) {
56 if( !base )
57 base = (nptr[0] == '0')? 8 : 10;
58 if( nptr[0] == '0' && nptr[1] == 'x' ) {
59 nptr += 2;
60 base = 16;
63 for( sum=0 ;; nptr++ ) {
64 char ch = *nptr;
65 if( !isalnum(ch) )
66 break;
67 n = isdigit(ch) ? ch - '0' : toupper(ch) - 'A' + 10;
68 if( n >= base || n < 0 )
69 break;
70 sum *= base;
71 sum += n;
73 if( endptr )
74 *endptr = (char*)nptr;
76 return sum * sign;
79 long long int
80 strtoll( const char *nptr, char **endptr, int base )
82 long long int sum;
83 int n, sign=1;
84 while( isspace(*nptr) )
85 nptr++;
87 if( *nptr == '-' || *nptr == '+' )
88 sign = (*nptr++ == '-') ? -1 : 1;
90 if( base == 16 || base == 0) {
91 if( !base )
92 base = (nptr[0] == '0')? 8 : 10;
93 if( nptr[0] == '0' && nptr[1] == 'x' ) {
94 nptr += 2;
95 base = 16;
98 for( sum=0 ;; nptr++ ) {
99 char ch = *nptr;
100 if( !isalnum(ch) )
101 break;
102 n = isdigit(ch) ? ch - '0' : toupper(ch) - 'A' + 10;
103 if( n >= base || n < 0 )
104 break;
105 sum *= base;
106 sum += n;
108 if( endptr )
109 *endptr = (char*)nptr;
111 return sum * sign;
114 // Propolice support
115 long __guard[8] = {
116 #ifdef CONFIG_BIG_ENDIAN
117 (0 << 24) | (0 << 16) | ('\n' << 8) | 255,
118 #else
119 (255 << 24) | ('\n' << 16) | (0 << 8) | 0,
120 #endif
121 0, 0, 0, 0, 0, 0, 0
124 static void freeze(void)
126 // Freeze
127 // XXX: Disable interrupts?
128 for(;;)
132 void __stack_smash_handler(const char *func, int damaged)
134 printk("Propolice detected a stack smashing attack %x at function %s,"
135 " freezing\n", damaged, func);
136 freeze();
139 void __stack_chk_fail(void)
141 printk("Propolice detected a stack smashing attack, freezing\n");
143 freeze();