@@ -88,14 +88,14 @@ just in case, it'd be a good idea to map inputs to variables.
#include "string.h"
#include "stdio.h"
-int main() {
- // Don't do this
- printf("%d\n", strcspn("Hello", "Hi"));
-
- // Do this
- char *first = "Hello";
- char *second = "Hi";
- printf("%d\n", strcspn(first, second));
+int main(void) {
+ // Don't do this
+ printf("%d\n", strcspn("Hello", "Hi"));
+
+ // Do this
+ char *first = "Hello";
+ char *second = "Hi";
+ printf("%d\n", strcspn(first, second));
}
```
@@ -120,4 +120,4 @@ You can test against verified correct output with `make verify` in the tests
directory. You will need to manually create the correct output and put it in the
tests/expected directory. Running any `make` commands in the tests directory
will ***not*** rebuild relibc, so you'll need to go back to the root directory
-if you need to rebuild relibc.
+if you need to rebuild relibc.
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <string.h>
-int main(int argc, char ** argv) {
char *str = (char *) alloca(17);
memset(str, 'A', 16);
@@ -1,7 +1,7 @@
#include <unistd.h>
+int main(int argc, char *argv[]) {
int i;
for(i = 0; i < argc; i++) {
write(STDOUT_FILENO, argv[i], strlen(argv[i]));
@@ -3,7 +3,7 @@
#include <stdlib.h>
-int main(int argc, char** argv) {
uint32_t hl = 0xBADFACED;
uint32_t nl = htonl(hl);
assert(nl == 0xEDACDFBA);
assert(1 == 1);
assert(1 + 1 == 2);
puts("yay!");
@@ -16,6 +16,6 @@ TEST(102)
TEST(103)
TEST(104)
-int main(int argc, char *argv[]) {
puts("main");
@@ -293,7 +293,7 @@ size_t num_test_cases = sizeof(test_cases) / sizeof(struct test_case);
printf("Unexpected result: " #fn "('%c') != %d // Char value: %d\n", tc.c, tc.fn, tc.c); \
-int main(int argc, char* argv[]) {
int retval = 0;
for(int i = 0; i < num_test_cases; ++i) {
#include <errno.h>
printf("%lu\n", sizeof(struct dirent));
DIR* dir = opendir("example_dir/");
@@ -7,7 +7,7 @@ int filter(const struct dirent* dirent) {
return strstr(dirent->d_name, "3") == NULL;
struct dirent** array;
int len = scandir("example_dir/", &array, filter, alphasort);
if (len < 0) {
chdir("nonexistent");
printf("errno: %d = %s\n", errno, strerror(errno));
perror("perror");
#include <fcntl.h>
int fd = creat("create.out", 0755);
if (fd >= 0) {
write(fd, "Hello World!\n", 13);
//Lose our fd and pull it again
creat("fcntl.out", 0777);
int newfd = open("fcntl.out", 0);
@@ -9,7 +9,7 @@ void test(char* pattern, char* input, int flags) {
puts("Should succeed:");
test("*World", "Hello World", 0);
test("*World", "World", 0);
@@ -18,7 +18,7 @@ char * get_mutable_string(char *str) {
return copy;
-void test_basename() {
+void test_basename(void) {
test_case test_cases[] =
{ {"/usr/lib", "lib"},
{"//usr//lib//", "lib"},
@@ -44,7 +44,7 @@ void test_basename() {
return;
-void test_dirname() {
+void test_dirname(void) {
{ {"/usr/lib", "/usr"},
{"//usr//lib//", "//usr"},
@@ -73,7 +73,7 @@ void test_dirname() {
printf("Testing libgen.h\n");
test_basename();
test_dirname();
// TODO: Implement locale properly and test it here
char* val = setlocale(LC_ALL, NULL);
if (strcmp(val, "C") == 0) {
#include <math.h>
double pi = 3.14;
float c = cos(pi);
printf("cos(%f) = %f\n", pi, c);
@@ -225,6 +225,6 @@ do_test (void)
return (error_count != 0);
do_test();
@@ -13,7 +13,7 @@ void print(struct passwd *pwd) {
printf("pw_shell: %s\n", pwd->pw_shell);
puts("--- Checking getpwuid ---");
errno = 0;
struct passwd *pwd = getpwuid(0);
#include <regex.h>
regex_t regex;
char error_buf[256];
@@ -6,7 +6,7 @@ void ptimeval(struct timeval* val) {
printf("{ tv_sec: %ld, tv_usec: %ld }\n", val->tv_sec, val->tv_usec);
struct rusage r_usage;
if (getrusage(RUSAGE_SELF, &r_usage) < 0) {
perror("getrusage");
#include <sys/select.h>
int fd = open("select.c", 0, 0);
fd_set read;
#include <setjmp.h>
jmp_buf buf;
if (setjmp(buf)) {
puts("hi from jump");
@@ -7,7 +7,7 @@ void handler(int sig) {
puts("Signal handler called!");
if (signal(SIGUSR1, &handler) == SIG_ERR) {
puts("Signal error!");
printf("%d\n", errno);
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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1, 999, stdout);
fwrite("Test\n", 1, 5, stdout);
//FILE *f = fopen("/etc/ssl/certs/ca-certificates.crt", "r");
char line[256];
FILE *f = fopen("stdio/fputs.out", "w");
char *in = "Hello World!";
fputs(in, f); // calls fwrite, helpers::fwritex, internal::to_write and internal::stdio_write
FILE *fp = fopen("stdio/fread.in", "rb");
char buf[33] = { 0 };
freopen("stdio/stdio.in", "r", stdin);
char in[6];
fgets(in, 6, stdin);
if (fseek(f, 14, SEEK_CUR) < 0) {
puts("fseek error");
FILE *f = fopen("stdio/fwrite.out", "w");
const char ptr[] = "Hello World!";
ungetc('h', stdin);
char c;
if ((c = getchar()) == 'h') {
FILE* f = fopen("stdio/stdio.in", "r");
flockfile(f);
-int main(int argc, char **argv) {
FILE *fp;
int status;
char path[256];
int sofar = 0;
int len = printf(
"percent: %%\nstring: %s\nchar: %c\nchar: %c\nint: %d\n%nuint: %u\nhex: %x\nHEX: %X\nstring: %s\n",
@@ -8,7 +8,7 @@ static char newpath[] = "new-name.out";
static char str[] = "Hello, World!";
int str_len = 13;
char buf[14];
buf[13] = 0x00;
int fd = creat(oldpath, 0777);
@@ -25,7 +25,7 @@ void test(char* fmt_in, char* input, struct params *p, ...) {
);
struct params p = { .c = 'a' };
test("%hhd %d", "12 345", &p, &p.sa, &p.ia);
setvbuf(stdout, 0, _IONBF, 0);
setvbuf(f, 0, _IONBF, 0);
char buffer[72];
int ret = sprintf(
char * s = "azAZ9."; // test boundaries
long l = a64l(s);
if (l != 194301926) {
char * ptr = (char *)malloc(256);
printf("malloc %p\n", ptr);
double d = atof("-3.14");
printf("%f\n", d);
return 0;
printf("%d\n", atoi(" -42"));
printf("%d\n", atoi(" +555"));
printf("%d\n", atoi(" 1234567890 "));
@@ -19,7 +19,7 @@ int int_cmp(const void* a, const void* b) {
int x = 0;
int y = 1024;
@@ -3,10 +3,9 @@
volatile long double ld;
volatile unsigned long long ll;
lldiv_t mydivt;
-int
-main ()
-{
-char* tmp;
+ char* tmp;
f = strtof("gnu", &tmp);
ld = strtold("gnu", &tmp);
ll = strtoll("gnu", &tmp, 10);
//puts(getenv("SHELL"));
//puts(getenv("CC"));
char* file_name = (char*) calloc(18, sizeof(char));
strcpy(file_name, "tempXXXXXX.suffix");
int fd = mkostemps(file_name, 7, 0);
char* string = (char*) calloc(20, sizeof(char));
strcpy(string, "tempXXXXXX");
mktemp(string);
printf("%d\n", rand());
srand(259);
@@ -4,7 +4,7 @@
char* path = realpath("stdlib/realpath.c", NULL);
if (!path) {
perror("realpath");
char* endptr = 0;
double d;
printf("%ld\n", strtol(" -42", NULL, 0));
printf("%ld\n", strtol(" +555", NULL, 0));
printf("%ld\n", strtol(" 1234567890 ", NULL, 0));
printf("%ld\n", strtoul(" -42", NULL, 0));
printf("%ld\n", strtoul(" +555", NULL, 0));
printf("%ld\n", strtoul(" 1234567890 ", NULL, 0));
system("echo test of system");
puts("# mem #");
char arr[100];
memset(arr, 0, 100); // Compiler builtin, should work
char dest1[12] = "hello";
printf("%s\n", strcat(dest1, " world")); // should be hello world
printf("%s\n", strchr("hello", 'e')); // should be ello
printf("%s\n", strchr("world", 'l')); // should be ld
printf("%i\n", strchr("world", 0) == NULL); // should be 1
char dst[20];
strcpy(dst, "strcpy works!");
char *world = "world";
printf("%ld\n", strcspn("hello", world)); // should be 2
printf("%ld\n", strcspn("banana", world)); // should be 6
printf("%d\n", strncmp("a", "aa", 2));
printf("%d\n", strncmp("a", "aä", 2));
printf("%d\n", strncmp("\xFF", "\xFE", 2));
char* source = "The quick drawn fix jumps over the lazy bug";
// should be "The quick drawn fix jumps over the lazy bug"
@@ -1,8 +1,7 @@
char s0[] = "hello, world";
char* ptr = strrchr(s0, 'l');
if (ptr != &s0[10]) {
char *hello = "hello";
char *banana = "banana";
printf("%s\n", strstr("In relibc we trust", "rust"));
printf("%s\n", strstr("In relibc we trust", "libc"));
printf("%s\n", strstr("In relibc we trust", "bugs"));
char source[] = "I'd just like to interject for a moment. What you're referring to as Linux, "
"is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux.\n";
char* sp;
#include <strings.h>
assert(!bcmp("hello", "hehe", 2));
assert(bcmp("hello", "haha", 2));
#include <sys/utsname.h>
struct utsname system_info;
int result = uname(&system_info);
time_t a = 0;
struct tm *time_info = gmtime(&a);
#include <sys/time.h>
struct timeval tv;
gettimeofday(&tv, NULL);
printf("%ld: %ld\n", tv.tv_sec, tv.tv_usec);
struct tm expected = { .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, .tm_year = 70,
.tm_wday = 4, .tm_yday = 0, .tm_isdst = 0, .tm_gmtoff = 0, .tm_zone = "UTC" };
#include <time.h>
int day = 60 * 60 * 24;
time_t inputs[] = { -(day * 33), -day, -1, -500, 0, 1, 1531454950 };
for (int i = 0; i < (sizeof(inputs) / sizeof(time_t)); i += 1) {
#include <assert.h>
struct timeval x = { .tv_usec = 15 };
struct timeval y = { 0 };
struct timeval z = { 0 };
@@ -18,7 +18,8 @@ int check(time_t input) {
struct tm t = { 0 };
t.tm_year = 71;
@@ -8,7 +8,8 @@ void print(time_t timestamp, char* fmt) {
printf("%zu: %s\n", n, out);
free(out);
print(1531808742, "%a %A %b %B");
print(1531808742, "The %Cst century");
print(1531808742, "%I:%M:%S %p");
struct timespec tm = {0, 0};
int cgt = clock_gettime(CLOCK_REALTIME, &tm);
#include <sys/times.h>
struct tms tms;
printf("return: %ld\n", times(&tms));
if (access("example_dir/1-never-gonna-give-you-up", R_OK | W_OK)) {
perror("access");
return 1;
int status = brk((void*)100);
printf("brk exited with status code %d\n", status);
char* cwd1 = malloc(4096*sizeof(char));//(char*) calloc(4096 + 1, sizeof(char));
getcwd(cwd1, 4096);
printf("initial cwd: %s\n", cwd1);
creat("dup.out", 0777);
int fd1 = open("dup.out", 0);
int fd2 = dup(fd1);
char* args[] = {"sh", "-c", "echo 'exec works :D'", NULL};
execv("/bin/sh", args);
perror("execv");
-int main (int argc, char** argv) {
int fd = open("..", 0, 0);
status = fchdir(fd);
int fd = open(".", 0, 0);
status = fsync(fd);
int fd = creat("ftruncate.out", 0777);
status = ftruncate(fd, 100);
char first[PATH_MAX];
getcwd(first, PATH_MAX);
puts(first);
char* hostname = malloc(256);
if (gethostname(hostname, 256) == 0) {
printf("Hostname: %s\n", hostname);
gid_t egid = getegid();
uid_t euid = geteuid();
gid_t gid = getgid();
// 1 is stdout
if (isatty(1)) {
puts("'Tis a tty :D");
#include <sys/stat.h>
printf("%ld\n", sizeof(struct stat));
struct stat buf;
@@ -7,7 +7,7 @@
printf("%s (%d): %ld (%d)\n", #N, _PC_ ## N, fpathconf(0, _PC_ ## N), errno); \
-int main(){
PC(LINK_MAX);
PC(MAX_CANON);
PC(MAX_INPUT);
@@ -3,9 +3,7 @@
-int main()
int pid, pip[2];
char instring[20];
char * outstring = "Hello World!";
mkdir("foo", 0);
int status = rmdir("foo");
printf("rmdir exited with status code %d\n", status);
@@ -6,8 +6,7 @@
-int main( void )
- {
if( setpgid( getpid(), 0 ) == -1 ) {
perror( "setpgid" );
@@ -24,4 +23,4 @@ int main( void )
printf("%d has euid %d and uid %d\n", getpid(), geteuid(), getuid());
- }
+}
sleep(2);
perror("sleep");
usleep(1000);
printf("%s (%d): %ld (%d)\n", #N, _SC_ ## N, sysconf(_SC_ ## N), errno); \
SC(ARG_MAX);
SC(CHILD_MAX);
SC(CLK_TCK);
write(STDOUT_FILENO, "Hello World!\n", 13);
pid_t pid = fork();
if (pid == 0) {
// child