ITADN

Replace `libaaio` which is incompatible with the license

#32Openenkvadrat 创建于 2026-01-09
E
enkvadratcommented
The `aaio` dir inside `dev` seems to contaion the same source code as the tar file inside `libaaio` Why do we need that tar file? I can build the project fine even if it is deleted. The cmake file is missleading. We will only ever use aaio2.c ```cmake # CMakeLists.txt for libaaio.a. NB NOT on Windows! set(CMAKE_C_FLAGS "-O -Wall ") include_directories(../newinclude) # original distribution just uses aaio.c. # but also provides aaio1.c and aaio2.c as alternatives. # this will itself include aaio1.c set(AAIOLIB_SRCS aaio.c) add_library(aaio ${AAIOLIB_SRCS}) ``` aaio.c ```c #ifdef OLD_STYLE #define _L_AAIO1_ #else #define _L_AAIO2_ #endif #ifdef _L_AAIO1_ #include "aaio1.c" #endif #ifdef _L_AAIO2_ #include "aaio2.c" // here it is #endif ``` ```sh # we never set OLD_STYLE on the project ➜ rg "OLD_STYLE" aaio/aaio.c 74:#ifdef OLD_STYLE ``` aaio2.c has 7 functions the rest are no-op ```c int aaio_flush(void); int aaio_hard_reset(void); int kbhit(void); int getche(void); int getch(void); static int set_stty_raw(struct termios *old, int echo); static void make_raw(struct termios *termios_p, int echo); ``` Around 200 lines of code in total. Of them we use `getch` and `kbhit` which depend on `make_raw` and `set_stty_raw` all in all 85 lines of code. ```c #include "aaio.h" #include <stdio.h> #include <unistd.h> #include <termios.h> #include <sys/ioctl.h> static const int NOECHO = 0; static void make_raw(struct termios *termios_p, int echo) { int e = echo == ECHO ? 0 : ECHO; termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR|IGNCR|ICRNL|IXON); termios_p->c_oflag &= ~OPOST; termios_p->c_lflag &= ~(ECHONL|ICANON|ISIG|IEXTEN|e); termios_p->c_cflag &= ~(CSIZE|PARENB); termios_p->c_cflag |= CS8; } static int set_stty_raw(struct termios *old, int echo) { struct termios nxt; //Store old terminal setting if(tcgetattr(STDIN_FILENO, old)) return -1; //Create a raw terminal setting with "echo" nxt = *old; make_raw(&nxt, echo); //Set the termianal mode if(tcsetattr(STDIN_FILENO, 0, &nxt)) return -1; return 0; } int getch(void) { struct termios old; int c; //set raw, no-echo mode if(set_stty_raw(&old, NOECHO)) return -1; //read a char c = getchar(); //Reset terminal to old mode if(tcsetattr(STDIN_FILENO, 0, &old)) return -1; return c; } int kbhit(void) { struct termios old; int i; //set raw, echo mode if(set_stty_raw(&old, NOECHO)) return -1; //Get number of tokens if(-1 == ioctl(STDIN_FILENO, FIONREAD, &i)) { //Reset terminal to old mode tcsetattr(STDIN_FILENO, 0, &old); return -1; } //Reset terminal to old mode if(tcsetattr(STDIN_FILENO, 0, &old)) return -1; return i; } ``` Additionally reading the header of the library is it really compatible with this project, since the LGPLv2 forbids "further restrictions" while the AAL requires a mandatory attribution banner. You cannot satisfy both. Since this is so little code and it basically only uses `termios.h` I think the best course of action is to replace aaio. We could use something like ncurses library but that would require changing a lot of code so instead lets rewrite the functions.
3 条评论