Files
RedBear-OS/tests/stdio/rename.c
T
Tibor Nagy d1a424c002 tests: Replace returns with exits in the main functions
This will allow us to redefine the exit function.

For example:
```
#define exit(code) { \
    fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
        __FILE__, __LINE__, #code, __func__); \
    _exit(code); \
}
```
2019-02-21 12:15:06 +01:00

29 lines
607 B
C

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static char oldpath[] = "old-name.out";
static char newpath[] = "new-name.out";
static char str[] = "Hello, World!";
int str_len = 13;
int main(void) {
char buf[14];
buf[13] = 0x00;
int fd = creat(oldpath, 0777);
write(fd, str, str_len);
close(fd);
rename(oldpath, newpath);
fd = open(newpath, O_RDONLY);
read(fd, buf, str_len);
close(fd);
remove(newpath);
if (strcmp(str, buf) == 0) {
exit(EXIT_SUCCESS);
} else {
exit(EXIT_FAILURE);
}
}