[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

api[libc] index

SwikiCodeRobot @> #apiLibcIndex

Prerequisites

"Check FFI is actually included in the image"
(Smalltalk includesKey: #S8FFI) ifFalse: [
    self print: '// Require S8FFI framework'.
    self abort
]

API implementation

FFIDynamicLibrary subclass: #LibC category: #LibC!
LibC comment: '
	Wrapper to LIBC
	Ref. http://www.gnu.org/software/libc/manual/html_mono/libc.html
'!

! LibC class methodsFor: #spec !
libraryName
	" Private - Returns the name of library file. "

	^NodeJS process platform = #win32
		ifTrue: [ #msvcrt ]
		ifFalse:[ #libc   ]! !

! LibC class methodsFor: #spec !
timeUtilitiesLiteral
	" Private - Returns the specification literal for this functions"

	^#(
	#(clock #(clock_t #()))
	)! !
! LibC class methodsFor: #spec !
specLiteral
	" Private - Returns the specification literal of library file. "

	^self memoryLiteral
	,self characterHandlingLiteral
	,self stringAndArrayUtilitiesLiteral
	,self timeUtilitiesLiteral! !

"	There is a lot of API to be implemented See reference manual
	http://www.gnu.org/software/libc/manual/html_mono/libc.html

Error Reporting			How library functions report errors.
Memory				Allocating virtual memory and controlling paging.
Character Handling		Character testing and conversion functions.
String and Array Utilities	Utilities for copying and comparing strings and arrays.
Character Set Handling		Support for extended character sets.
Locales				The country and language can affect the behavior of library functions.
Message Translation		How to make the program speak the user’s language.
Searching and Sorting		General searching and sorting functions.
Pattern Matching		Matching shell “globs” and regular expressions.
I/O Overview			Introduction to the I/O facilities.
I/O on Streams			High-level, portable I/O facilities.
Low-Level I/O			Low-level, less portable I/O.
File System Interface		Functions for manipulating files.
Pipes and FIFOs			A simple interprocess communication mechanism.
Sockets				A more complicated IPC mechanism, with networking support.
Low-Level Terminal Interface	How to change the characteristics of a terminal device.
Syslog				System logging and messaging.
Mathematics			Math functions, useful constants, random numbers.
Arithmetic			Low level arithmetic functions.
Date and Time			Functions for getting the date and time and formatting them nicely.
Resource Usage And Limitation	Functions for examining resource usage and getting and setting limits.
Non-Local Exits			Jumping out of nested function calls.
Signal Handling			How to send, block, and handle signals.
Program Basics			Writing the beginning and end of your program.
Processes			How to create processes and run other programs.
Inter-Process Communication	All about inter-process communication.
Job Control			All about process groups and sessions.
Name Service Switch		Accessing system databases.
Users and Groups		How users are identified and classified.
System Management		Controlling the system and getting information about it.
System Configuration		Parameters describing operating system limits.
Cryptographic Functions		DES encryption and password handling.
Debugging Support		Functions to help debugging applications.
POSIX Threads			POSIX Threads.
Internal Probes			Probes to monitor libc internal behavior.
"!

! LibC class methodsFor: #spec !
memoryLiteral
	" Private - Returns the specification literal for this functions"

	^#(
	#(malloc	#('void*' #(#(size size_t))))
	#(free		#(void #(#(#(ptr json) 'void*'))))
	#(realloc	#('void*' #(#(#(ptr json) 'void*') #(size size_t))))
	#(calloc	#('void*' #(#(count int) #(size size_t))))
	#(posix_memalign	#(int #(#(#(memptr json) 'void**') #(alignment size_t) #(size size_t))))
	#(valloc	#('void*' #(#(size size_t))))
"	#(aligned_alloc	#('void*' #(#(alignment size_t) #(size size_t))))
	#(memalign	#('void*' #(#(boundary int) #(size size_t))))
	#(mallopt	#(int #(#(param int) #(value int))))
	#(mcheck 	#(int #(#(#(callback json) 'void*'))))
	#(alloca	#('void*' #(#(size size_t))))
"	#(mlock		#(int #(#(#(addr json) 'void*') #(size size_t))))
	)! !

! LibC class methodsFor: #spec !
characterHandlingLiteral
	" Private - Returns the specification literal for this functions"

	^#(
	#(islower #(bool #(#(c int))))
	#(isupper #(bool #(#(c int))))
	#(isalpha #(bool #(#(c int))))
	#(isdigit #(bool #(#(c int))))
	#(isalnum #(bool #(#(c int))))
	#(isxdigit #(bool #(#(c int))))
	#(ispunct #(bool #(#(c int))))
	#(isspace #(bool #(#(c int))))
	#(isblank #(bool #(#(c int))))
	#(isgraph #(bool #(#(c int))))
	#(isprint #(bool #(#(c int))))
	#(iscntrl #(bool #(#(c int))))
	#(isascii #(bool #(#(c int))))
	#(tolower #(int #(#(c int))))
	#(tolower #(int #(#(c int))))
	#(toupper #(int #(#(c int))))
	#(toascii #(int #(#(c int))))
	)! !

! LibC class methodsFor: #spec !
stringAndArrayUtilitiesLiteral
	" Private - Returns the specification literal for this functions"

	^#(
	#(strlen #(size_t #(#(s 'char*'))))
	#(strnlen #(size_t #(#(s 'char*') #(maxlen int))))
	#(memcpy #('void*' #(#(to 'char*') #(from 'char*') #(size size_t))))
	#(memmove #('void*' #(#(to 'char*') #(from 'char*') #(size size_t))))
	#(memset #('void*' #(#(dest 'char*') #(c int) #(size size_t))))
	#(strcpy #('void*' #(#(to 'char*') #(from 'char*'))))
	#(strdup #('void*' #(#(s 'char*'))))
	#(stpcpy #('void*' #(#(to 'char*') #(from 'char*'))))
	#(strcat #('void*' #(#(to 'char*') #(from 'char*'))))
	#(memcmp #(int #(#(a1 'void*') #(a2 'void*') #(size size_t))))
	#(strcmp #(int #(#(s1 'void*') #(s2 'void*'))))
	#(memchr #('void*' #(#(s 'void*') #(c int) #(size size_t))))
	#(strchr #('void*' #(#(s 'char*') #(c int))))
	#(strrchr #('void*' #(#(s 'char*') #(c int))))
	#(strncpy #('void*' #(#(to 'char*') #(from 'char*'))))
	)! !

! LibC class methodsFor: #spec !
validFFITypeFor: selector
	" Private - Validate the type selector and returns the FFI type for selector.
	The default implementation do simple type conversion.
	This method can be refined to validate the existence (and creation on demmand) of the type.
	"

	| answer |
	answer := super validFFITypeFor: selector.
	selector isString ifFalse: [ self error: 'Type selector must be a String' ].
	answer = #clock_t ifTrue: [ ^#long ].
	^answer! !

! LibC class methodsFor: #spec !
argumentTypeFromFFI: ffiType
	" Private - Return the API type for ffiType. "

	ffiType = #clock_t ifTrue: [ ^#long ].
	^super argumentTypeFromFFI: ffiType ! !


LibC buildFromLiteral!

References