The solution is going to depend on a few things regarding how your UI works. Porting the Linux code directly isn't going to work unless you have a lower-level implementation which the ported code can use.
Do you have an offsite repo on, say, GitHub, GitLab, or Sourceforge, which would allow us to view your existing code? That would simplify things for us a great deal, because then we'd be able to address what's actually running.
EDIT: I found
this repo on GitHub, which I assume is the one in question based your earlier posts.
Speaking in broad terms, a 'clear screen' utility is going to require you to do two things: a) clear all the character cells in the screen buffer, and b) reset the cursor to the first text cell of the first line of text.
For a 'raw' text mode screen, this would usually mean a memset filling the current screen page with a blank space for the character byte and the current background value for the attribute byte. The details of this, and of writing to the text-mode screen in general, is covered in the wiki page
Printing To Screen. How large the fill would have to be would depend on the text mode being used; obviously, a 132x60 text mode buffer will be larger than an 80x30 one.
This would be followed by resetting the hardware cursor as described in the wiki pages on
Text UI and the
Text Mode Cursor.
However, that is a specific set of special cases; you generally want to abstract this in order to make it easier to write code which also works in, say, a text window in a GUI. This is what the Unix
Curses and
Termcap/
Terminfo libraries are meant to do (as are some newer ones which are specific to Linux, which I don't know as much about; and in the case of a desktop environment, still others specific to the GUI being used).
The
clear utility which you were trying to port relies on these - it is sending a series of escape codes which those libraries would then interpret (in this case, ones used by the
xterm terminal emulator and compatible terminal emulators, as Korona stated earlier). It is probably getting terminal capabilities information from
terminfo or something similar before deciding the specific sort of escape codes (or other facilities) to use for the specific text screen type.
In order to port that utility as-is, you would first need to implement the operation for the specific type of screen,
and then implement an equivalent set of abstract libraries (either by porting the Unix/Linux libraries, or writing similar ones yourself) which the utility can call upon.
It sounds as if you already have a screen-clearing routine; if so, then what you need is to get the
clear utility to talk to it.