1
/******************************************************************
3
MUSCLE SmartCard Development ( http://www.linuxnet.com )
6
Author : David Corcoran
8
License: Copyright (C) 1999 David Corcoran
9
<corcoran@linuxnet.com>
10
Purpose: This handles abstract system level calls.
12
********************************************************************/
14
#include <sys_generic.h>
15
#include <sys/types.h>
29
int SYS_Initialize( ) {
30
/* Nothing done here */
34
int SYS_Mkdir( char *path, int perms ) {
35
return mkdir(path, perms);
42
int SYS_Sleep( int iTimeVal ) {
43
struct timespec mrqtp;
44
mrqtp.tv_sec = iTimeVal;
47
return nanosleep( &mrqtp, NULL );
50
int SYS_USleep( int iTimeVal ) {
51
struct timespec mrqtp;
53
mrqtp.tv_nsec = iTimeVal * 1000;
55
return nanosleep( &mrqtp, NULL );
58
int SYS_OpenFile( char *pcFile, int flags, int mode ) {
59
return open( pcFile, flags, mode );
62
int SYS_CloseFile( int iHandle ) {
63
return close( iHandle );
66
int SYS_RemoveFile( char *pcFile ) {
67
return remove( pcFile );
70
int SYS_Chmod( const char *path, int mode ) {
71
return chmod( path, mode );
74
int SYS_Mkfifo( const char *path, int mode ) {
75
return mkfifo( path, mode );
78
int SYS_Mknod( const char *path, int mode, int dev ) {
79
return mknod( path, mode, dev );
90
int SYS_Chown( const char *fname, int uid, int gid ) {
91
return chown( fname, uid, gid );
94
int SYS_ChangePermissions( char *pcFile, int mode ) {
95
return chmod( pcFile, mode );
98
int SYS_LockFile( int iHandle ) {
101
lock_s.l_type = F_WRLCK;
106
return fcntl( iHandle, F_SETLK, &lock_s );
109
int SYS_LockAndBlock( int iHandle ) {
112
lock_s.l_type = F_RDLCK;
117
return fcntl( iHandle, F_SETLKW, &lock_s );
120
int SYS_UnlockFile( int iHandle ) {
123
lock_s.l_type = F_UNLCK;
128
return fcntl( iHandle, F_SETLK, &lock_s );
131
int SYS_SeekFile( int iHandle, int iSeekLength ) {
133
iOffset = lseek( iHandle, iSeekLength, SEEK_SET );
137
int SYS_ReadFile( int iHandle, char *pcBuffer, int iLength ) {
138
return read( iHandle, pcBuffer, iLength );
141
int SYS_WriteFile( int iHandle, char *pcBuffer, int iLength ) {
142
return write( iHandle, pcBuffer, iLength );
145
int SYS_GetPageSize( void ) {
146
return getpagesize();
149
void *SYS_MemoryMap( int iSize, int iFid, int iOffset ) {
154
vAddress = mmap( 0, iSize, PROT_READ | PROT_WRITE,
155
MAP_SHARED, iFid, iOffset );
157
/* Here are some common error types:
179
void *SYS_PublicMemoryMap( int iSize, int iFid, int iOffset ) {
184
vAddress = mmap( 0, iSize, PROT_READ,
185
MAP_SHARED, iFid, iOffset );
189
int SYS_MMapSynchronize( void *begin, int length ) {
190
return msync(begin, length, MS_SYNC);
197
int SYS_Wait( int iPid, int iWait ) {
198
return waitpid( -1, 0, WNOHANG );
201
int SYS_Stat( char *pcFile, struct stat *psStatus ) {
202
return stat( pcFile, psStatus );
205
int SYS_Fstat( int iFd ) {
207
return fstat( iFd, &sStatus );
210
int SYS_Random( int iSeed, float fStart, float fEnd ) {
218
iRandNum = 1+(int)(fEnd*rand()/(RAND_MAX+fStart));
229
tz.tz_minuteswest = 0;
231
if (gettimeofday(&tv, &tz) == 0) {
234
myseed = (long ) time(NULL);
239
int SYS_Exit( int iRetVal ) {
243
int SYS_Rmdir( char *pcFile )
245
return rmdir(pcFile);
248
int SYS_Unlink( char *pcFile )
250
return unlink(pcFile);