psx.wiki

libraries/libc: Difference between revisions

Revision as of 02:58, 23 October 2026
RemmyLee
(Run-time library pages: 20 libraries from the Library Overview and Reference 4.4)
Revision as of 03:05, 23 October 2026
RemmyLee
(File libraries under their SDK: /sdk/psy-q/; Psy-Q page; sidebar SDKs and System software)
Line 1:Line 1:
−---
−title: Standard C Library (libc and libc2)
−type: component
−summary: Provides a subset of the standard C library for the PlayStation.
−category: Libraries
−info: Library = libc.lib, libc2.lib
−info: Header File = See the header file table
−---
−
−## Overview
−
−The Standard C Library is a subset of the K & R based standard C library. It includes character functions, memory operation functions, character class tests, non-local jumps and utility functions.[^ox][^o3-3]
−
−There are two versions of the library. libc calls the library routines in the kernel ROM, which saves size because no extra code is linked with the application. However, ROM code is not cacheable, so libc routines are slower than libc2 routines. libc2 is linked with the application and is faster because its code is cacheable.[^o3-3]
−
−## Library and Header Files
−
−A program that uses the standard C routines links with libc.lib or libc2.lib. The routines are declared in the following header files, and the Run-Time Library Reference gives the header file of each function:[^o3-3]
−
−Table: Header files
−
−| Header file |
−| --- |
−| abs.h |
−| assert.h |
−| convert.h |
−| ctype.h |
−| malloc.h |
−| memory.h |
−| rand.h |
−| setjmp.h |
−| stdarg.h |
−| stddef.h |
−| stdlib.h |
−| strings.h |
−| qsort.h |
−| sys/types.h |
−
−## Memory Allocation
−
−The malloc(), calloc(), realloc() and free() of the standard C library call the ROM routines of the kernel. This malloc system has a bug in which free() cannot release the whole area, and since it is in ROM it cannot be corrected. The RAM-based malloc2 system and the faster malloc3 system of [libapi](/libraries/libapi/) avoid it.[^o2-21][^o2-22]
−
−## Functions
−
−In the tables below, Introduced is the run-time library version that added the item.[^reff22]
−
−The standard C library has the following functions:[^reff22]
−
−Table: The standard C library functions
−
−| Function | Header File | Introduced | Purpose |
−| --- | --- | --- | --- |
−| `abs` | abs.h | 2.x | Calculate absolute value. |
−| `atoi` | convert.h | 2.x | Convert a string to an integer. |
−| `atol` | convert.h | 2.x | Convert a character string to a long. |
−| `bcmp` | memory.h | 2.x | Compare memory blocks. |
−| `bcopy` | memory.h | 2.x | Copy a memory block. |
−| `bsearch` | stdlib.h | 2.x | Perform a binary search. |
−| `bzero` | memory.h | 2.x | Fill a memory block with zeros. |
−| `calloc` | malloc.h | 2.x | Allocate main memory. |
−| `exit` | stdlib.h | 2.x | Terminate a program normally. |
−| `free` | malloc.h | 2.x | Release an allocated memory block. |
−| `getc` | stdio.h | 2.x | Get one character from a stream. |
−| `getchar` | stdio.h | 2.x | Get one character from the standard input stream. |
−| `gets` | stdio.h | 2.x | Read a character string from standard input. |
−| `isXXXX...` | ctype.h | 2.x | Test characters. |
−| `labs` | convert.h | 2.x | Calculate absolute value. |
−| `longjmp` | setjmp.h | 2.x | Non-local jump. |
−| `malloc` | malloc.h | 2.x | Allocate main memory. |
−| `memchr` | memory.h | 2.x | Search a memory block for a character. |
−| `memcmp` | memory.h | 2.x | Compare memory blocks. |
−| `memcpy` | memory.h | 2.x | Copy a memory block. |
−| `memmove` | memory.h | 2.x | Copy a memory block. |
−| `memset` | memory.h | 2.x | Write a character to a memory block. |
−| `printf` | stdio.h | 2.x | Print formatted output. |
−| `putc` | stdio.h | 2.x | Output one character to a stream. |
−| `putchar` | stdio.h | 2.x | Output one character to the standard output stream. |
−| `puts` | stdio.h | 2.x | Output a character string to the standard output stream. |
−| `qsort` | qsort.h | 2.x | Perform a quick sort. |
−| `rand` | rand.h | 2.x | Generate a random number. |
−| `realloc` | malloc.h | 2.x | Change heap memory allocations. |
−| `setjmp` | setjmp.h | 2.x | Defines non-local jump destination. |
−| `sprintf` | stdio.h | 2.x | Write formatted output to a string. |
−| `srand` | rand.h | 2.x | Initialize the random number generator. |
−| `strcat` | strings.h | 2.x | Concatenate character strings. |
−| `strchr` | strings.h | 2.x | Search for the first location at which a character appears in a string. |
−| `strcmp` | strings.h | 2.x | Compare character strings. |
−| `strcpy` | strings.h | 2.x | Copy a character string. |
−| `strcspn` | strings.h | 2.x | Search for a string of characters not included in the a character set. |
−| `strlen` | strings.h | 2.x | Count characters in a string. |
−| `strncat` | strings.h | 2.x | Concatenate character strings. |
−| `strncmp` | strings.h | 2.x | Compare character strings. |
−| `strncpy` | strings.h | 2.x | Copy a character string. |
−| `strpbrk` | strings.h | 2.x | Search for the first occurrence of a character in a character set. |
−| `strrchr` | strings.h | 2.x | Search for the last location of a character in a character string. |
−| `strspn` | strings.h | 2.x | Search for the part of a string consisting solely of characters in a character set. |
−| `strstr` | strings.h | 2.x | Search for the location of a partial character string. |
−| `strtok` | strings.h | 2.x | Search for a string demarcated by characters in a character set. |
−| `strtol` | convert.h | 2.x | Convert a character string to a long. |
−| `strtoul` | convert.h | 2.x | Convert a character string to an unsigned long. |
−| `toascii` | ctype.h | 2.x | Mask bit 7 of the input value. |
−| `tolower` | ctype.h | 2.x | Convert a letter to lower-case. |
−| `toupper` | ctype.h | 2.x | Converts a character to upper case. |
−
−## References
−
−[^ox]: Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page x.
−[^o2-21]: Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 2-21.
−[^o2-22]: Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 2-22.
−[^o3-3]: Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 3-3.
−[^reff22]: Sony Computer Entertainment Inc. Run-Time Library Reference. Run-Time Library 4.4. January 1999. Pages 2-2 to 2-52.