Files
mango/libc/ctype/ctype.c

95 lines
2.4 KiB
C

/*
* asbestOS: The best operating system ever made.
* Copyright (C) 2017 Max Wash
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
static unsigned int random_seed = 53455346;
int isupper(int c) { return (c >= 65 && c <= 90); }
int islower(int c) { return (c >= 97 && c <= 122); }
int toupper(int c) {
if (!islower(c)) {
return c;
}
return c - 32;
}
int tolower(int c) {
if (!isupper(c)) {
return c;
}
return c + 32;
}
int isdigit(int c) { return (c >= 48 && c <= 57); }
int isalpha(int c) { return (c >= 65 && c <= 90) || (c >= 97 && c <= 122); }
int isalnum(int c) { return isalpha(c) | isdigit(c); }
int iscntrl(int c) { return (c <= 31) || (c == 127); }
int isprint(int c) { return (c >= 32 && c <= 126) || (c >= 128 && c <= 254); }
int isgraph(int c) { return isprint(c) && c != 32; }
int ispunct(int c) { return isgraph(c) && !isalnum(c); }
int isspace(int c) {
return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\v') ||
(c == '\f') || (c == '\r');
}
int isxdigit(int c) {
return isdigit(c) || (c >= 65 && c <= 70) || (c >= 97 && c <= 102);
}
bool fill_random(unsigned char *buffer, unsigned int size) {
if (!buffer || !size) {
return false;
}
for (uint32_t i = 0; i < size; i++) {
uint32_t next = random_seed;
uint32_t result;
next *= 1103515245;
next += 12345;
result = (uint32_t)(next / 65536) % 2048;
next *= 1103515245;
next += 12345;
result <<= 10;
result ^= (uint32_t)(next / 65536) % 1024;
next *= 1103515245;
next += 12345;
result <<= 10;
result ^= (uint32_t)(next / 65536) % 1024;
random_seed = next;
buffer[i] = (uint8_t)(result % 256);
}
return true;
}