-
Notifications
You must be signed in to change notification settings - Fork 0
/
libc.c
68 lines (60 loc) · 2.49 KB
/
libc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**************************************************************************/
/* This file is part of the Codex semantics library. */
/* */
/* Copyright (C) 2013-2024 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
/* 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, version 2.1. */
/* */
/* It 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. */
/* */
/* See the GNU Lesser General Public License version 2.1 */
/* for more details (enclosed in the file LICENSE). */
/* */
/**************************************************************************/
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
int rand_int(void);
unsigned char rand_char(void);
int tcsetattr(int fd, int optional_actions,
struct termios *termios_p){
unsigned char *ptr;
for(ptr=termios_p;ptr < termios_p + 1; ptr++)
*ptr = rand_char();
return rand_int();
}
int tcgetattr(int ft, struct termios *termios_p){
unsigned char *ptr;
for(ptr=termios_p;ptr < termios_p + 1; ptr++)
*ptr = rand_char();
return rand_int();
}
int snprintf(char *str, size_t size, const char *format, ...){
unsigned char *ptr;
for(ptr = str; ptr < str + size; ptr++) {
*ptr = rand_char();
};
int v = rand_int();
if(0 <= v && v < size) return v;
else while(1);
}
void *memcpy(void *dst, void *source, size_t n){
int i;
char *dest = dst;
char *src = source;
for(i = 0; i < n; i++) dest[i] = src[i];
return dest;
}
void *memset(void *dst, int c, size_t n){
int i;
char *dest = dst;
for(i = 0; i < n; i ++) dest[i] = c;
return dest;
}