-

Standard Library Functions

From HI-TECH C for CP/M Fan WIKI(EN)
Revision as of 15:28, 30 July 2017 by Kumokosi (talk | contribs)
Jump to: navigation, search

STANDARD I/O

fopen(name, mode)  
Open file for I/O
freopen(name, mode, stream)  
Re-open existing stream
fdopen(fd, mode)  
Associate a stream with a file descriptor
fclose(stream)  
Close open file
fflush(stream)  
Flush buffered data
getc(stream)  
Read byte from stream
fgetc(stream)  
Same as getc
ungetc(c, stream)  
Push char back onto stream
putc(c, stream)  
Write byte to stream
fputc(c, stream)  
Same as putc()
getchar()  
Read byte from standard input
putchar(c)  
Write byte to standard output
getw(stream)  
Read word from stream
putw(w, stream)  
Write word to stream
gets(s)  
Read line from standard input
fgets(s, n, stream)  
Read string from stream
puts(s)  
Write string to standard output
fputs(s, stream)  
Write string to stream
fread(buf, size, cnt, stream)  
Binary read from stream
fwrite(buf, size, cnt, stream)  
Binary write to stream
fseek(stream, offs, wh)  
Random access positioning
ftell(stream)  
Current file read/write position
rewind(stream)  
Reposition file pointer to start
setvbuf(stream, buf, mode, size)  
Enable/disable buffering of stream
fprintf(stream, fmt, args)  
Formatted output on stream
printf(fmt, args)  
Formatted standard output
sprintf(buf, fmt, args)  
Formatted output to a string
vfprintf(stream, fmt, va_ptr)  
Formatted output on stream
vprintf(fmt, va_ptr)  
Formatted standard output
vsprintf(buf, fmt, va_ptr)  
Formatted output to a string
fscanf(stream, fmt, args)  
Formatted input from stream
scanf(fmt, args)  
Formatted standard input
sscanf(buf, fmt, va_ptr)  
Formatted input from a string
vfscanf(stream, fmt, va_ptr)  
Formatted input from stream
vscanf(fmt, args)  
Formatted standard input
vsscanf(buf, fmt, va_ptr)  
Formatted input from a string
feof(stream)  
True if stream at EOF
ferror(stream)  
True if error on stream
clrerr(stream)  
Reset error status on stream
fileno(stream)  
Return fd from stream
remove(name)  
Remove (delete) file

STRING HANDLING

atoi(s)  
Convert ASCII decimal to integer
atol(s)  
Convert ASCII decimal to long integer
atof(s)  
Convert ASCII decimal to float
xtoi(s)  
Convert ASCII hexadecimal to integer
memchr(s, c, n)  
Find char in memory block
memcmp(s1, s2, n)  
Compare n bytes of memory
memcpy(s1, s2, n)  
Copy n bytes from s2 to s1
memmove(s1, s2, n)  
Copy n bytes from s2 to s1
memset(s, c, n)  
Set n bytes at s to c
strcat(s1, s2)  
Append string 2 to string 1
strncat(s1, s2, n)  
Append at most n chars to string 1
strcmp(s1, s2)  
Compare strings
strncmp(s1, s2, n)  
Compare n bytes of strings
strcpy(s1, s2)  
Copy s2 to s1
strncpy(s1, s2, n)  
Copy at most n bytes of s2
strerror(errnum)  
Map errnum to an error message string
strlen(s)  
Length of string
strchr(s, c)  
Find char in string
strrchr(s, c)  
Find rightmost char in string
strspn(s1, s2)  
Length of s1 composed of chars from s2
strcspn(s1, s2)  
Length of s2 composed of chars not from s2
strstr(s1, s2)  
Locate the first occurence of s2 in s1


LOW LEVEL I/O

open(name, mode)  
Open a file
close(fd)  
Close a file
creat(name)  
Create a file
dup(fd)  
Duplicate file descriptor
lseek(fd, offs, wh)  
Random access positioning
read(fd, buf, cnt)  
Read from file
rename(name1, name2)  
Rename file
unlink(name)  
Remove file from directory
write(fd, buf, cnt)  
Write to file
isatty(fd)  
True if fd refers to tty-like device
stat(name, buf)  
Get information about a file
chmod(name, mode)  
Set file attributes

CHARACTER TESTING

isalpha(c)  
True if c is a letter
isupper(c)  
Upper case letter
islower(c)  
Lower case letter
isdigit(c)  
Digit
isalnum(c)  
Alphnumeric character
isspace(c)  
Space, tab, newline, return or formfeed
ispunct(c)  
Punctuation character
isprint(c)  
Printable character
isgraph(c)  
Printable non-space character
iscntrl(c)  
Control character
isascii(c)  
Ascii character (0-127)

FLOATING POINT

cos(f)  
Cosine function
sin(f)  
Sine function
tan(f)  
Tangent function
acos(f)  
Arc cosine function
asin(f)  
Arc sine function
atan(f)  
Arc tangent function
exp(f)  
Exponential of f
log(f)  
Natural log of f
log10(f)  
Base 10 log of f
pow(x,y)  
X to the y'th power
sqrt(f)  
Square root
fabs(f)  
Floating absolute value
ceil(f)  
Smallest integral value >= f
floor(f)  
Largest integral value <= f
sinh(f)  
Hyperbolic sine
cosh(f)  
Hyperbolic cosine
tanh(f)  
Hyperbolic tangent
frexp(y, p)  
Split into mantissa and exponent
ldexp(y, i)  
Load new exponent

CONSOLE I/O

getch()  
Get single character
getche()  
Get single character with echo
putch(c)  
Put single character
ungetch(c)  
Push character back
kbhit()  
Test for key pressed
cgets(s)  
Get line from console
cputs(s)  
Put string to console

DATE AND TIME FUNCTIONS

time(p)  
Get current date/time
gmtime(p)  
Get broken down Universal time
localtime(p)  
Get broken down local time
asctime(t)  
Convert broken down time to ascii
ctime(p)  
Convert time to ascii

MISCELLANEOUS

execl(name, args)  
Execute another program
execv(name, argp)  
Execute another program
spawnl(name, arg, ...)  
Execute a subprogram
spawnv(name, argp)  
Execute a subprogram
system(s)  
Execute system command
atexit(func)  
Install func to be executed on termination
exit(status)  
Terminate execution
_exit(status)  
Terminate execution immediately
getuid()  
Get user id (CP/M)
setuid(uid)  
Set user id (CP/M)
chdir(s)  
Change directory (MS-DOS)
mkdir(s)  
Create directory (MS-DOS)
rmdir(s)  
Remove directory (MS-DOS)
getcwd(drive)  
Get current working directory (MS-DOS)
signal(sig, func)  
Set trap for interrupt condition
brk(addr)  
Set memory allocation
sbrk(incr)  
Adjust memory allocation
malloc(cnt)  
Dynamic memory allocation
free(ptr)  
Dynamic memory release
realloc(ptr, cnt)  
Dynamic memory reallocation
calloc(cnt, size)  
Dynamic memory allocation zeroed
perror(s)  
Print error message
qsort(base, nel, width, func)  
Quick sort
srand(seed)  
Initialize random number generator
rand()  
Get next random number
setjmp(buf)  
Setup for non-local goto
longjmp(buf, val)  
Non-local goto
_getargs(buf, name)  
Wild card expansion and i/o redirection
inp(port)  
Read port
outp(port, data)  
Write data to port
bdos(func, val)  
Perform bdos call (CP/M)
msdos(func, val, val, ...)  
Perform msdos call
msdoscx(func, val, val, ...)  
Alternate msdos call
intdos(ip, op)  
Execute DOS interrupt
intdosx(ip, op, sp)  
Execute DOS interrupt
segread(sp)  
Get segment register values
int86(int, ip, op)  
Execute software interrupt
int86x(int, ip, op, sp)  
Execute software interrupt
bios(n, c)  
Call bios entry (CP/M)
ei()  
Enable interrupts
di()  
Disable interrupts
set_vector(vec, func)  
Set an interrupt vector
assert(e)  
Run time assertion
getenv(s)  
Get environment string (MS-DOS)