clib2 – An ISO 'C' (1994) compliant runtime library for AmigaOS (fork for use in vscode-amiga-debug)
This fork is based on the outstanding clib2 written by Olaf Barthel. It is intented to be run in vscode-amiga-debug version 1.7.5 or higher (using gcc 13.2)
The below functions are provided:
- In
libc
: isalnum, isalpha, isascii, isblank, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit, tolower, toupper, closedir, opendir, readdir, rewinddir, close, creat, fcntl, lseek, open, read, write, ftw, nftw, imaxdiv, imaxabs, strtoimax, strtoumax, basename, dirname, localeconv, setlocale, fstatfs, statfs, kill, raise, sigaddset, sigblock, sigemptyset, sigmask, signal, sigprocmask, sigsetmask, chmod, fchmod, fstat, lstat, mkdir, rmdir, stat, umask, asprintf, clearerr, fclose, feof, ferror, fflush, fgetc, fgetpos, fgets, flockfile, fopen, fprintf, fputc, fread, freopen, fscanf, fseek, fseeko, fsetpos, ftell, ftello, ftrylockfile, funlockfile, fwrite, getc, getc_unlocked, getchar, getchar_unlocked, gets, perror, popen, printf, putc, putc_unlocked, putchar, putchar_unlocked, puts, remove, rename, rewind, scanf, setbuf, setvbuf, snprintf, sprintf, sscanf, tmpfile, tmpnam, ungetc, vasprintf, vfprintf, vfscanf, vprintf, vsnprintf, vsprintf, vsscanf, vscanf, abort, abs, alloca, atexit, atoi, atol, bsearch, calloc, __clzsi2, __ctzsi2, div, __divsi3, exit, free, getenv, labs, llabs, ldiv, malloc, mkdtemp, mkstemp, mktemp, __modsi3, __mulsi3, putenv, qsort, rand, rand_r, realloc, setenv, srand, strtol, strtoul, system, __udivsi3, __umodsi3, unsetenv, ffs, strcasecmp, strncasecmp, bcmp, bcopy, bzero, index, memchr, memcmp, memcpy, memmove, memset, rindex, strcat, strchr, strcmp, strcoll, strcpy, strcspn, strdup, strerror, strerror_r, strlcat, strlcpy, strlen, strncat, strncmp, strncpy, strpbrk, strrchr, strspn, strstr, strtok, strtok_r, strxfrm, asctime, asctime_r, clock, ctime, ctime_r, gettimeofday, gmtime, gmtime_r, localtime, localtime_r, mktime, strftime, time, tzset, readv, writev, ulimit, access, chdir, chown, dup, dup2, fchown, fdatasync, fdopen, fileno, fsync, ftruncate, getcwd, getopt, getpid, isatty, lchown, link, lockf, readlink, realpath, sleep, symlink, truncate, unlink, usleep, utime, uname, setjmp, longjmp - In
libunix
: closedir, rewinddir, opendir, readdir, creat, fcntl, open, getopt_long, statfs, getrlimit, setrlimit, chmod, fstat, lstat, mkdir, rmdir, stat, ctermid, fflush, fopen, popen, remove, rename, alloca, mkdtemp, mkstemp, mktemp, malloc, realloc, system, sysinfo, cfgetispeed, cfgetospeed, cfmakeraw, cfsetispeed, cfsetospeed, tcdrain, tcflow, tcflush, tcgetattr, tcsendbreak, tcsetattr, ftime, readv, writev, access, chdir, chown, execl, execle, execlp, execv, execve, execvp, fpathconf, getcwd, lchown, link, lockf, pathconf, readlink, realpath, symlink, truncate, ttyname, ttyname_r, unlink, utime - In
libm
: carg, cargf, cargl, cimag, cimagf, cimagl, conj, conjf, conjl, creal, crealf, creall, feclearexcept, fegetenv, fegetexceptflag, fegetround, feholdexcept, feraiseexcept, fesetenv, fesetexceptflag, fetestexcept, fetestround, feupdateenv, acos, acosf, acosh, acoshf, asin, asinf, asinh, asinhf, atan, atan2, atan2f, atanf, atanh, atanhf, cbrt, cbrtf, ceil, ceilf, copysign, copysignf, cos, cosf, cosh, coshf, erf, erfc, erfcf, erff, exp, exp2, exp2f, expf, expm1, expm1f, fabs, fabsf, fdim, fdimf, floor, floorf, fma, fmaf, fmax, fmaxf, fmin, fminf, fmod, fmodf, frexp, frexpf, hypot, hypotf, ilogb, ilogbf, ldexp, ldexpf, lgamma, lgammaf, llrint, log, log10, log10f, log1p, log1pf, log2, log2f, logb, logbf, logf, lrint, lrintf, lround, lroundf, modf, modff, nan, nanf, nearbyint, nearbyintf, nextafter, nextafterf, pow powf, remainder, remainderf, remquo, remquof, rint, rintf, round, roundf, scalbn, scalbnf, sin, sinf, sinh, sinhf, sqrt, sqrtf, tan, tanf, tanh, tanhf, tgamma, tgammaf, trunc, truncf, asprintf, fprintf, fscanf, printf, scanf, snprintf, sprintf, sscanf, vasprintf, vfprintf, vfscanf, vsscanf, vscanf, vprintf, vsnprintf, vsprintf, atof, strtod, strtof, difftime, __adddf3, __addsf3, __ashldi3,__divdf3, __divsf3, __eqdf2, __eqsf2, __extendsfdf2, __fixdfsi, __fixsfsi, __fixunsdfsi, __fixunssfsi, __floatsidf, __floatsisf, __gedf2, __gesf2, __gtdf2, __gtsf2, __ledf2, __lesf2, __ltdf2, __ltsf2, __muldf3, __mulsf3, __nedf2, __negdf2, __negsf2, __nesf2, __subdf3, __subsf3, __truncdfsf2, __floatunsisf, __floatunsidf, __divdi3, __moddi3, __muldi3 - In
libm881
: carg, cargf, cargl, cimag, cimagf, cimagl, conj, conjf, conjl, creal, crealf, creall, feclearexcept, fegetenv, fegetexceptflag, fegetround, feholdexcept, feraiseexcept, fesetenv, fesetexceptflag, fetestexcept, fetestround, feupdateenv, acos, acosf, acosh, acoshf, asin, asinf, asinh, asinhf, atan, atan2, atan2f, atanf, atanh, atanhf, cbrt, cbrtf, ceil, ceilf, copysign, copysignf, cos, cosf, cosh, coshf, erf, erfc, erfcf, erff, exp, exp2, exp2f, expf, expm1, expm1f, fabs, fabsf, fdim, fdimf, floor, floorf, fma, fmaf, fmax, fmaxf, fmin, fminf, fmod, fmodf, frexp, frexpf, hypot, hypotf, ilogb, ilogbf, ldexp, ldexpf, lgamma, lgammaf, llrint, log, log10, log10f, log1p, log1pf, log2, log2f, logb, logbf, logf, lrint, lrintf, lround, lroundf, __lshrdi3, modf, modff, nan, nanf, nearbyint, nearbyintf, nextafter, nextafterf, pow powf, remainder, remainderf, remquo, remquof, rint, rintf, round, roundf, scalbn, scalbnf, sin, sinf, sinh, sinhf, sqrt, sqrtf, tan, tanf, tanh, tanhf, tgamma, tgammaf, trunc, truncf, asprintf, fprintf, fscanf, printf, scanf, snprintf, sprintf, sscanf, vasprintf, vfprintf, vfscanf, vsscanf, vscanf, vprintf, vsnprintf, vsprintf, atof, strtod, strtof, difftime - In
libnet
: accept, bind, connect, getaddrinfo, gethostbyaddr, gethostbyname, gethostid, gethostname, getnetbyaddr, getnetbyname, getpeername, getprotobyname, getprotobynumber, getservbyname, getservbyport, getsockname, getsockopt, inet_addr, inet_aton, inet_lnaof, inet_makeaddr, inet_netof, inet_network, inet_ntoa, ioctl, listen, recv, recvfrom, recvmsg, select, waitselect, send, sendmsg, sendto, setsockopt, shutdown, socket, hstrerror, umask, sysinfo, crypt, endgrent, endpwent, getegid, geteuid, getgid, getgrent, getgrgid, getgrnam, getgroups, getpass, getpwent, getpwnam, getpwuid, getuid, initgroups, setegid, seteuid, setgid, setgrent, setgroups, setpwent, setregid, setreuid, setsid, setuid, uname - In
libdebug
: KCmpStr, KDoFmt, kgetc, kgetch, KGetCh, kgetchar, KGetChar, kgetnum, KGetNum, KMayGetCh, KMayGetChar, kprintf, KPrintF, kputc, kputch, KPutCh, kputchar, KPutChar, KPutFmt, KPutS, kputs, kputstr, KPutStr, kvprintf, KVPrintF - In
libamiga
: ACrypt, AddTOF, ArgArrayDone, ArgArrayInit, ArgInt, ArgString, BeginIO, CallHook, CallHookA, CoerceMethod, CoerceMethodA, CreateExtIO, CreatePort, CreateStdIO, CreateTask, DeleteExtIO, DeletePort, DeleteStdIO, DeleteTask, DoMethod, DoMethodA, DoSuperMethod, DoSuperMethodA, DoTimer, FastRand, afp, arnd, dbf, fpa, fpbcd, FreeIEvents, HotKey, InvertString, LibAllocPooled, LibCreatePool, LibDeletePool, LibFreePooled, NewList, RangeRand, RemTOF, CheckRexxMsg, GetRexxVar, SetRexxVar, SetSuperAttrs, TimeDelay, waitbeam
- You need to have the
"ar"
command in your search path. This is normally the case for Linux and MacOS. For Windows, you can for example install MSYS2 / MinGW and update your search path to include their "bin" directory - Install amiga-debug Visual Studio Code Extension (fork with libraries support) version 1.7.5 or higher
- Choose the menu "File->Open Folder..." and select the directory of this github repository
- Open
.vscode/launch.json
and make"kickstart"
point to your Kickstart 3.1 ROM and"workbench"
to your Workbench 3.1 floppy (.adf) - Hit F5 to build the libraries (they wil appear in the
libs
directory, overwriting the existing ones)
In order to test the libraries, you can uncomment in main.c
the lines after "Printf("Testing clib2...\n");" and Hit F5. You will however have to follow some rules :
libc
,libm
,libnet
andlibamiga
can be tested together and the corresponding lines can be uncommented accordinglylibdebug
should be tested alone as you will have to follow the below specific procedure:
a. The first time, once the program asks you to press Ctrl-C, do so
b. Open UAE configuration window by pressing F12 and go to IO ports
c. Under Serial Port, choose TCP://0.0.0.0:1234, select Direct and press OK
d. Open a Telnet session on port 1234 by typing "telnet localhost 1234". For Windows, if needed, activate Telnet following the instructions on page https://www.makeuseof.com/enable-telnet-windows/. For MacOS, you can install it through Homebrew (see https://osxdaily.com/2018/07/18/get-telnet-macos/). For Linux, it should natively come with your distribution
e. Go back to UAE and in the shell type a.exe to restart the program: you should see all chars and messages in the Telnet window. You will then be asked to type some chars and numbers in the Telnet window
f. At the end, close the UAE window
Note: after the test, UAE may signal a (false) read error on the Workench disk. This is due to the fact that we modified its configuration while runninglibunix
should be tested after you changed the definition of the static libs order in theMakefile
to put -lunix before -lc (see the commented static_libs lines in theMakefile
and don't forget to put back the original lines after the test!)
If you want to use the libraries in your own project, your code will have to follow the skeleton of the included main.c
file.
It is also mandatory:
- To declare the static libs in your
Makefile
:
a. static_libs := -lc -lm -ldebug -lnet -lunix -lc -lamiga, to use Amiga style paths
b. static_libs := -lm -ldebug -lnet -lunix -lc -lamiga, to use UNIX style paths (e.g. "/RAM/myfile" instead of "RAM:myfile") - To call SetPatch in your startup-sequence
- To increase the stack size, especially if you use
libunix
(see line below) - To mount the PIPE: device if you intend to use pipe functions (popen, pclose, etc.); this is done in
.vscode/launch.json
file through the instruction "cmdList":"C:Mount PIPE:,C:stack 16384,C:SetPatch QUIET" (which also increases the stack size) - To have the bsdsocket.library library installed in your system (it is required by
libnet
); this is done in.vscode/launch.json
file through the instruction "bsdSocket":true - To have at least the usergroup.library installed in your system (it is required by
libnet
for the usergroup functions); vscode-amiga-debug version 1.7.5 comes with the usergroup.library embedded in DH0:Libs - To have AmiTCP installed in your system if you want to take full advantage of the usergroup functions (like
setuid
,setgroups
, etc.) - To NOT use
libnet
functions and native bsdsocket.library functions together, as they are incompatible; in order to avoid this, do not include "<inline/bsdsocket.h>" in your code if your intention is to uselibnet
libm881
has not been tested and is provided as-is- The function
hstrerror
is currently crashing the program when used - ARexx functions
GetRexxVar
andSetRexxVar
are not yet working in the current version oflibamiga
- Neither 64 bits integers nor long double are supported
- The following functions are currently do-nothing: feclearexcept, fegetenv, fegetexceptflag, fegetround, feholdexcept, feraiseexcept, fesetenv, fesetexceptflag, fetestexcept, fetestround, feupdateenv
- First version
- Better support of inf and NaN by math functions
- Added functions __ashldi3, __lshrdi3, getaddrinfo, __clzsi2 and __ctzsi2
- __time_delay made reentrant
- Clean in Makefile improved
- clib compiled to handle floats
- Fixed code in main to distinguish correctly between start from CLI or Workbench
- atan2 fixed