mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-03 11:29:17 +00:00
userspace: Rewrite everything
Everything. Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2
Userspace/apps/test/cross_test/.gitignore
vendored
Normal file
2
Userspace/apps/test/cross_test/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
utest_linux
|
||||
utest_win.exe
|
30
Userspace/apps/test/cross_test/Makefile
Normal file
30
Userspace/apps/test/cross_test/Makefile
Normal file
@ -0,0 +1,30 @@
|
||||
default:
|
||||
$(error Do not run this Makefile directly!)
|
||||
|
||||
FILENAME = utest_
|
||||
|
||||
CFLAGS = -static -g -ggdb3 -O0 -w
|
||||
UNAME_OS := $(shell uname -s)
|
||||
|
||||
$(FILENAME)linux:
|
||||
ifneq ($(shell uname -s), Linux)
|
||||
$(info Only Linux is supported)
|
||||
exit 0
|
||||
endif
|
||||
$(info Compiling $(FILENAME)linux)
|
||||
gcc linux_glibc.c $(CFLAGS) -o $(FILENAME)linux
|
||||
cp $(FILENAME)linux $(WORKSPACE_DIR)/out/bin/$(FILENAME)linux
|
||||
|
||||
$(FILENAME)win.exe:
|
||||
ifneq ($(shell uname -s), Linux)
|
||||
$(info Only Linux is supported)
|
||||
exit 0
|
||||
endif
|
||||
$(info Compiling $(FILENAME)win)
|
||||
x86_64-w64-mingw32-gcc win_mingw.c $(CFLAGS) -o $(FILENAME)win.exe
|
||||
cp $(FILENAME)win.exe $(WORKSPACE_DIR)/out/bin/$(FILENAME)win.exe
|
||||
|
||||
build: $(FILENAME)linux $(FILENAME)win.exe
|
||||
|
||||
clean:
|
||||
rm -f $(FILENAME)linux $(FILENAME)win.exe
|
97
Userspace/apps/test/cross_test/linux_glibc.c
Normal file
97
Userspace/apps/test/cross_test/linux_glibc.c
Normal file
@ -0,0 +1,97 @@
|
||||
#define _POSIX_SOURCE
|
||||
#define _DEFAULT_SOURCE
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <pty.h>
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifndef __GLIBC__
|
||||
#define __GLIBC__ 0
|
||||
#endif
|
||||
|
||||
#ifndef __GLIBC_MINOR__
|
||||
#define __GLIBC_MINOR__ 0
|
||||
#endif
|
||||
|
||||
int ptmx_test()
|
||||
{
|
||||
int masterFD;
|
||||
int slaveFD;
|
||||
char slaveName[100];
|
||||
|
||||
masterFD = open("/dev/ptmx", O_RDWR | O_NOCTTY);
|
||||
if (masterFD < 0)
|
||||
{
|
||||
perror("Failed to open /dev/ptmx");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (grantpt(masterFD) < 0)
|
||||
{
|
||||
perror("Failed to grantpt");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unlockpt(masterFD) < 0)
|
||||
{
|
||||
perror("Failed to unlockpt");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ptsname_r(masterFD, slaveName, sizeof(slaveName)) != 0)
|
||||
{
|
||||
perror("Failed to get slave name");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Slave terminal: %s\n", slaveName);
|
||||
|
||||
slaveFD = open(slaveName, O_RDWR | O_NOCTTY);
|
||||
if (slaveFD < 0)
|
||||
{
|
||||
perror("Failed to open slave terminal");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct termios t;
|
||||
tcgetattr(slaveFD, &t);
|
||||
cfmakeraw(&t);
|
||||
tcsetattr(slaveFD, TCSANOW, &t);
|
||||
|
||||
char *message = "Hello from master!\n";
|
||||
write(masterFD, message, strlen(message));
|
||||
|
||||
char buffer[100];
|
||||
int len = read(slaveFD, buffer, sizeof(buffer) - 1);
|
||||
if (len > 0)
|
||||
{
|
||||
buffer[len] = '\0';
|
||||
printf("Received from slave: %s\n", buffer);
|
||||
}
|
||||
|
||||
close(masterFD);
|
||||
close(slaveFD);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
printf("glibc %d.%d: Hello, World!\n", __GLIBC__, __GLIBC_MINOR__);
|
||||
fflush(stdout);
|
||||
ptmx_test();
|
||||
return 0;
|
||||
}
|
9
Userspace/apps/test/cross_test/win_mingw.c
Normal file
9
Userspace/apps/test/cross_test/win_mingw.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
printf("mingw: Hello, World!\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user