clib2 Proprietary Functions and Features

Overview

clib2 is an ISO 'C' (1994) compliant runtime library for AmigaOS, written by Olaf Barthel. It is designed to work with GCC and provides comprehensive POSIX and C standard library support.

Compiler Compatibility

clib2 is GCC-only and cannot be used with other Amiga compilers:

- SAS/C: Not compatible - has its own standard library

- DICE: Not compatible - has its own standard library

- VBCC: Not compatible - has its own standard library

- GCC: Fully compatible - designed specifically for GCC

Startup Code Options

clib2 provides several startup code options:

Standard Startup Files

- ncrt0.o: Non-baserelative startup code for GCC 2.3.3+

- nbcrt0.o: Baserelative startup code for GCC 2.3.3+

- nr32crt0.o: 32-bit non-baserelative startup code

- nb32crt0.o: 32-bit baserelative startup code

Startup Features

- CLI/Workbench Detection: Automatically detects startup method

- Workbench Message Handling: SAS-compatible WB startup message handling

- Auto-detach: Automatic process detachment

- Auto stack-extend: Automatic stack extension

- Library Auto-opening: Automatic library opening

- Constructor/Destructor Support: GCC constructor/destructor lists

- BSS Clearing: Automatic uninitialized data clearing (baserelative)

- Stack Management: Proper stack pointer management

Compiler Integration

- GCC-specific symbols: Uses ___INIT_LIST__, ___EXIT_LIST__

- GCC calling conventions: Follows GCC register usage

- GCC linker integration: Requires GCC linker for initialization lists

- GCC assembly syntax: Uses GCC-specific assembly directives

Proprietary Functions

Memory Management Extensions

- __allocate_memory(): Internal memory allocation with debug support

- __free_memory_node(): Internal memory deallocation

- __memory_lock(): Memory management synchronization

- __memory_unlock(): Memory management synchronization release

File Descriptor Extensions

- __find_vacant_fd_entry(): Find available file descriptor slot

- __grow_fd_table(): Expand file descriptor table

- __get_file_descriptor(): Get file descriptor structure

- __initialize_fd(): Initialize file descriptor

- __fd_lock(): File descriptor synchronization

- __fd_unlock(): File descriptor synchronization release

Debug and Profiling

- __check_abort_enabled: Abort checking control

- __set_errno(): Set error number

- __stdio_lock(): Standard I/O synchronization

- __stdio_unlock(): Standard I/O synchronization release

- PROFILE_OFF(): Disable profiling

- PROFILE_ON(): Enable profiling

Amiga-specific Extensions

- __WBenchMsg: Workbench startup message pointer

- __lib_startup: Library startup flag

- __check_daemon_startup: Daemon startup checking

- __nocommandline: Disable command line parsing

- __detach: Process detachment control

GCC Integration Functions

- __clzsi2(): Count leading zeros (GCC builtin)

- __ctzsi2(): Count trailing zeros (GCC builtin)

- __divsi3(): Signed integer division (GCC builtin)

- __modsi3(): Signed integer modulo (GCC builtin)

- __mulsi3(): Signed integer multiplication (GCC builtin)

- __udivsi3(): Unsigned integer division (GCC builtin)

- __umodsi3(): Unsigned integer modulo (GCC builtin)

Math Library Extensions

- __math_errhandling: Math error handling control

- __math_check_uflow: Underflow checking

- __math_check_oflow: Overflow checking

- __math_check_zerodiv: Division by zero checking

String Extensions

- strlcpy(): BSD-style safe string copy

- strlcat(): BSD-style safe string concatenation

- strerror_r(): Thread-safe error message (when available)

System Extensions

- getopt_long(): Extended command line option parsing

- readv(): Vector read operation

- writev(): Vector write operation

- ulimit(): Resource limits

- lockf(): File locking

- realpath(): Path resolution

- fdopen(): File descriptor to stream conversion

- fileno(): Stream to file descriptor conversion

Network Extensions

- getaddrinfo(): Address information lookup

- freeaddrinfo(): Free address information

- inet_pton(): IP address string to binary (IPv6)

- inet_ntop(): IP address binary to string (IPv6)

Time Extensions

- asctime_r(): Thread-safe ASCII time conversion

- ctime_r(): Thread-safe time string conversion

- gmtime_r(): Thread-safe GMT time conversion

- localtime_r(): Thread-safe local time conversion

Environment Extensions

- setenv(): Set environment variable

- unsetenv(): Remove environment variable

File System Extensions

- fchmod(): Change file mode by descriptor

- fchown(): Change file owner by descriptor

- lchown(): Change symbolic link owner

- futimes(): Change file times by descriptor

- ftruncate(): Truncate file by descriptor

| fdatasync(): Synchronize file data

- fchdir(): Change directory by descriptor

- link(): Create hard link

- symlink(): Create symbolic link

- readlink(): Read symbolic link

- realpath(): Resolve pathname

Process Extensions

- getuid(): Get real user ID

- geteuid(): Get effective user ID

- getgid(): Get real group ID

- getegid(): Get effective group ID

- setuid(): Set user ID

- setgid(): Set group ID

- setreuid(): Set real and effective user IDs

- setregid(): Set real and effective group IDs

- seteuid(): Set effective user ID

- setegid(): Set effective group ID

- getgroups(): Get supplementary group IDs

- setgroups(): Set supplementary group IDs

- initgroups(): Initialize supplementary group access

- getrusage(): Get resource usage

- times(): Get process times

- raise(): Send signal to current process

- sleep(): Sleep for specified seconds

- usleep(): Sleep for specified microseconds

Directory Extensions

- opendir(): Open directory stream

- readdir(): Read directory entry

- closedir(): Close directory stream

- rewinddir(): Reset directory stream position

Error Handling Extensions

- strerror(): Get error message string

- perror(): Print error message

- errno: Error number

System Information Extensions

- uname(): Get system information

- gethostname(): Get host name

- sethostname(): Set host name

- getdomainname(): Get domain name

Configuration Options

Compile-time Options

- UNIX_PATH_SEMANTICS: Enable Unix-style path handling

- CHECK_FOR_NULL_POINTERS: Enable null pointer checking

- __THREAD_SAFE: Enable thread safety

- __MEM_DEBUG: Enable memory debugging

- __USE_MEM_TREES: Use memory tree debugging

- GCC_HELP_SUPPORT: Enable GCC compilation support

Runtime Options

- GCC_STACK_SIZE: Set stack size for GCC compilation

- __nocommandline: Disable command line parsing

- __detach: Enable process detachment

- __check_daemon_startup: Enable daemon startup checking

Library Structure

clib2 is organized into several libraries:

- libc.a: Standard C library functions

- libunix.a: POSIX and Unix compatibility functions

- libmath.a: Mathematical functions

- libnet.a: Network functions

- libdebug.a: Debugging functions

- libamiga.a: Amiga-specific functions

Summary

clib2 provides comprehensive POSIX and C standard library support for GCC on AmigaOS, with extensive Amiga-specific extensions and optimizations. It is the most complete and modern C library available for AmigaOS GCC development, offering excellent compatibility with Unix/Linux code while maintaining Amiga-specific features.