psx.wiki

Standard C Library (libc and libc2)

Provides a subset of the standard C library for the PlayStation.

Standard C Library (libc and libc2)
Librarylibc.lib, libc2.lib
Header FileSee the header file table
SDKPsy-Q

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.12

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.2

This library is part of the run-time library that Sony distributed with the Psy-Q development tools.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:2

Table 1: 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 avoid it.45

Functions

In the tables below, Introduced is the run-time library version that added the item.6

The standard C library has the following functions:6

Table 2: 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


  1. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page x.

  2. ^ a b c Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 3-3.

  3. ^ Sony Computer Entertainment Inc. Programmer Tools CD (DTL-S2002), README.TXT. 11/26/96. Section "CD-ROM Contents - Highlights", directories \PSX and \PSYQ.

  4. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 2-21.

  5. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 2-22.

  6. ^ a b Sony Computer Entertainment Inc. Run-Time Library Reference. Run-Time Library 4.4. January 1999. Pages 2-2 to 2-52.

Categories: Psy-Q