sys_unix.c File Reference

This handles abstract system level calls. More...

#include "config.h"
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/file.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include "misc.h"
#include "sys_generic.h"
#include "debug.h"

Include dependency graph for sys_unix.c:

Go to the source code of this file.

Functions

INTERNAL int SYS_Initialize (void)
 Make system wide initialization.
INTERNAL int SYS_Mkdir (const char *path, int perms)
 Attempts to create a directory with some permissions.
INTERNAL int SYS_GetPID (void)
 Gets the running process's ID.
INTERNAL int SYS_Sleep (int iTimeVal)
 Makes the current process sleep for some seconds.
INTERNAL int SYS_USleep (int iTimeVal)
 Makes the current process sleep for some microseconds.
INTERNAL int SYS_OpenFile (const char *pcFile, int flags, int mode)
 Opens/creates a file.
INTERNAL int SYS_CloseFile (int iHandle)
 Opens/creates a file.
INTERNAL int SYS_RemoveFile (const char *pcFile)
 Removes a file.
INTERNAL int SYS_Chmod (const char *path, int mode)
INTERNAL int SYS_Chdir (const char *path)
INTERNAL int SYS_GetUID (void)
INTERNAL int SYS_GetGID (void)
INTERNAL int SYS_SeekFile (int iHandle, int iSeekLength)
INTERNAL int SYS_ReadFile (int iHandle, char *pcBuffer, int iLength)
INTERNAL int SYS_WriteFile (int iHandle, const char *pcBuffer, int iLength)
INTERNAL int SYS_GetPageSize (void)
 Gets the memory page size.
INTERNAL void * SYS_MemoryMap (int iSize, int iFid, int iOffset)
 Map the file iFid in memory for reading and writing.
INTERNAL void * SYS_PublicMemoryMap (int iSize, int iFid, int iOffset)
 Map the file iFid in memory only for reading.
INTERNAL void SYS_PublicMemoryUnmap (void *ptr, int iSize)
 Unmap a memory segment.
INTERNAL int SYS_MMapSynchronize (void *begin, int length)
 Writes the changes made in a memory map to the disk mapped file.
INTERNAL int SYS_Fork (void)
INTERNAL int SYS_Daemon (int nochdir, int noclose)
 put the process to run in the background.
INTERNAL int SYS_Stat (const char *pcFile, struct stat *psStatus)
INTERNAL int SYS_RandomInt (int fStart, int fEnd)
INTERNAL int SYS_GetSeed (void)
INTERNAL void SYS_Exit (int iRetVal)


Detailed Description

This handles abstract system level calls.

Definition in file sys_unix.c.


Function Documentation

INTERNAL int SYS_CloseFile ( int  iHandle  ) 

Opens/creates a file.

Parameters:
[in] iHandle File descriptor.
Returns:
Error code.
Return values:
0 Success.
-1 An error ocurred.

Definition at line 143 of file sys_unix.c.

Referenced by CreateContextThread(), SCardEstablishContextTH(), SCardUnload(), SHMCleanupSharedSegment(), SHMClientCloseSession(), SHMClientSetupSession(), SHMProcessCommonChannelRequest(), SHMProcessEventsContext(), StatSynchronize(), StatSynchronizeContext(), and SYS_Daemon().

INTERNAL int SYS_Daemon ( int  nochdir,
int  noclose 
)

put the process to run in the background.

Parameters:
[in] nochdir if zero, change the current directory to "/".
[in] noclose if zero, redirect standard imput/output/error to /dev/nulll.
Returns:
error code.
Return values:
0 success.
-1 an error ocurred.

Definition at line 318 of file sys_unix.c.

References SYS_CloseFile().

Here is the call graph for this function:

INTERNAL int SYS_GetPageSize ( void   ) 

Gets the memory page size.

The page size is used when calling the SYS_MemoryMap() and SYS_PublicMemoryMap() functions.

Returns:
Number of bytes per page.

Definition at line 207 of file sys_unix.c.

Referenced by SCardEstablishContextTH(), and StatSynchronize().

INTERNAL int SYS_GetPID ( void   ) 

Gets the running process's ID.

Returns:
PID.

Definition at line 71 of file sys_unix.c.

Referenced by StatSynchronizeContext().

INTERNAL int SYS_Initialize ( void   ) 

Make system wide initialization.

Returns:
Eror code.
Return values:
0 Success.

Definition at line 43 of file sys_unix.c.

Referenced by SCardEstablishContextTH().

INTERNAL void* SYS_MemoryMap ( int  iSize,
int  iFid,
int  iOffset 
)

Map the file iFid in memory for reading and writing.

Parameters:
[in] iSize Size of the memmory mapped.
[in] iFid File which will be mapped in memory.
[in] iOffset Start point of the file to be mapped in memory.
Returns:
Address of the memory map.
Return values:
MAP_FAILED in case of error

Definition at line 227 of file sys_unix.c.

INTERNAL int SYS_Mkdir ( const char *  path,
int  perms 
)

Attempts to create a directory with some permissions.

Parameters:
[in] path Path of the directory to be created.
[in] perms Permissions to the new directory.
Returns:
Eror code.
Return values:
0 Success.
-1 An error occurred.

Definition at line 61 of file sys_unix.c.

INTERNAL int SYS_MMapSynchronize ( void *  begin,
int  length 
)

Writes the changes made in a memory map to the disk mapped file.

Parameters:
[in] begin Start of the block to be written
[in] length Lenght of the block to be written
Returns:
Error code.
Return values:
0 Success.
-1 An error ocurred.

Definition at line 293 of file sys_unix.c.

Referenced by StatSynchronize().

INTERNAL int SYS_OpenFile ( const char *  pcFile,
int  flags,
int  mode 
)

Opens/creates a file.

Parameters:
[in] pcFile path to the file.
[in] flags Open and read/write choices.
[in] mode Permissions to the file.
Returns:
File descriptor.
Return values:
>0 The file descriptor.
-1 An error ocurred.

Definition at line 127 of file sys_unix.c.

Referenced by SCardEstablishContextTH(), StatSynchronize(), and StatSynchronizeContext().

INTERNAL void* SYS_PublicMemoryMap ( int  iSize,
int  iFid,
int  iOffset 
)

Map the file iFid in memory only for reading.

Parameters:
[in] iSize Size of the memmory mapped.
[in] iFid File which will be mapped in memory.
[in] iOffset Start point of the file to be mapped in memory.
Returns:
Address of the memory map.

Definition at line 255 of file sys_unix.c.

Referenced by SCardEstablishContextTH().

INTERNAL void SYS_PublicMemoryUnmap ( void *  ptr,
int  iSize 
)

Unmap a memory segment.

Parameters:
ptr pointer returned by SYS_PublicMemoryMap()
iSize size of the memory segment

Definition at line 278 of file sys_unix.c.

Referenced by SCardUnload().

INTERNAL int SYS_RemoveFile ( const char *  pcFile  ) 

Removes a file.

Parameters:
[in] pcFile path to the file.
Returns:
Error code.
Return values:
0 Success.
-1 An error ocurred.

Definition at line 157 of file sys_unix.c.

Referenced by SHMCleanupSharedSegment(), and SHMInitializeCommonSegment().

INTERNAL int SYS_Sleep ( int  iTimeVal  ) 

Makes the current process sleep for some seconds.

Parameters:
[in] iTimeVal Number of seconds to sleep.

Definition at line 81 of file sys_unix.c.

Referenced by SVCServiceRunLoop().

INTERNAL int SYS_USleep ( int  iTimeVal  ) 

Makes the current process sleep for some microseconds.

Parameters:
[in] iTimeVal Number of microseconds to sleep.

Definition at line 99 of file sys_unix.c.

Referenced by IFDCloseIFD(), SCardBeginTransaction(), SCardConnect(), SCardDisconnect(), SCardEndTransaction(), and SCardGetStatusChange().


Generated on Mon Aug 17 01:00:15 2009 for pcsc-lite by  doxygen 1.5.9