~ubuntu-branches/ubuntu/jaunty/pcsc-lite/jaunty-security

« back to all changes in this revision

Viewing changes to src/sys_hpux.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2004-06-13 21:45:56 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040613214556-zio7hrzkz9wwtffx
Tags: 1.2.9-beta2-2
* debian/rules: add -lpthread to LDFLAGS so that pthread_* symbols are
  included in the library (problem only seen on mips and mipsel).
  Closes: #253629
* debian/control: make libpcsclite-dev and libpcsclite1 at Priority:
  optional so that other packages at Priority: optional can use them.
  Closes: #249374

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************
2
 
 
3
 
        MUSCLE SmartCard Development ( http://www.linuxnet.com )
4
 
            Title  : sys_unix.c
5
 
            Package: pcsc lite
6
 
            Author : David Corcoran
7
 
            Date   : 11/8/99
8
 
            License: Copyright (C) 1999 David Corcoran
9
 
                     <corcoran@linuxnet.com>
10
 
            Purpose: This handles abstract system level calls. 
11
 
                    
12
 
********************************************************************/
13
 
 
14
 
#include <sys_generic.h>
15
 
#include <sys/types.h>
16
 
#include <sys/mman.h>
17
 
#include <sys/stat.h>
18
 
#include <sys/wait.h>
19
 
#include <sys/time.h>
20
 
#include <fcntl.h>
21
 
#include <errno.h>
22
 
#include <unistd.h>
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
#include <signal.h>
26
 
 
27
 
#include "config.h"
28
 
 
29
 
int SYS_Initialize( ) {
30
 
  /* Nothing done here */
31
 
        return 0;
32
 
}
33
 
 
34
 
int SYS_Mkdir( char *path, int perms ) {
35
 
  return mkdir(path, perms);
36
 
}
37
 
 
38
 
int SYS_GetPID() {
39
 
  return getpid();
40
 
}
41
 
 
42
 
int SYS_Sleep( int iTimeVal ) {
43
 
  struct timespec mrqtp;
44
 
  mrqtp.tv_sec  = iTimeVal;
45
 
  mrqtp.tv_nsec = 0;
46
 
 
47
 
  return nanosleep( &mrqtp, NULL );
48
 
}
49
 
 
50
 
int SYS_USleep( int iTimeVal ) {
51
 
  struct timespec mrqtp;
52
 
  mrqtp.tv_sec  = 0;
53
 
  mrqtp.tv_nsec = iTimeVal * 1000;
54
 
 
55
 
  return nanosleep( &mrqtp, NULL );
56
 
}
57
 
 
58
 
int SYS_OpenFile( char *pcFile, int flags, int mode ) {
59
 
  return open( pcFile, flags, mode );
60
 
}
61
 
 
62
 
int SYS_CloseFile( int iHandle ) {
63
 
  return close( iHandle );
64
 
}
65
 
 
66
 
int SYS_RemoveFile( char *pcFile ) {
67
 
  return remove( pcFile );
68
 
}
69
 
 
70
 
int SYS_Chmod( const char *path, int mode ) {
71
 
  return chmod( path, mode );
72
 
}
73
 
 
74
 
int SYS_Mkfifo( const char *path, int mode ) {
75
 
  return mkfifo( path, mode );
76
 
}
77
 
 
78
 
int SYS_Mknod( const char *path, int mode, int dev ) {
79
 
  return mknod( path, mode, dev );
80
 
}
81
 
 
82
 
int SYS_GetUID() {
83
 
  return getuid();
84
 
}
85
 
 
86
 
int SYS_GetGID() {
87
 
  return getgid();
88
 
}
89
 
 
90
 
int SYS_Chown( const char *fname, int uid, int gid ) {
91
 
  return chown( fname, uid, gid );
92
 
}
93
 
 
94
 
int SYS_ChangePermissions( char *pcFile, int mode ) {
95
 
  return chmod( pcFile, mode );
96
 
}
97
 
 
98
 
int SYS_LockFile( int iHandle ) {
99
 
  struct flock lock_s;
100
 
 
101
 
  lock_s.l_type   = F_WRLCK;
102
 
  lock_s.l_whence = 0;
103
 
  lock_s.l_start  = 0L;
104
 
  lock_s.l_len    = 0L;
105
 
 
106
 
  return fcntl( iHandle, F_SETLK, &lock_s );
107
 
}
108
 
 
109
 
int SYS_LockAndBlock( int iHandle ) {
110
 
  struct flock lock_s;
111
 
 
112
 
  lock_s.l_type   = F_RDLCK;
113
 
  lock_s.l_whence = 0;
114
 
  lock_s.l_start  = 0L;
115
 
  lock_s.l_len    = 0L;
116
 
 
117
 
  return fcntl( iHandle, F_SETLKW, &lock_s );
118
 
}
119
 
 
120
 
int SYS_UnlockFile( int iHandle ) {
121
 
  struct flock lock_s;
122
 
 
123
 
  lock_s.l_type   = F_UNLCK;
124
 
  lock_s.l_whence = 0;
125
 
  lock_s.l_start  = 0L;
126
 
  lock_s.l_len    = 0L;
127
 
 
128
 
  return fcntl( iHandle, F_SETLK, &lock_s );
129
 
}
130
 
 
131
 
int SYS_SeekFile( int iHandle, int iSeekLength ) {
132
 
  int iOffset;
133
 
  iOffset = lseek( iHandle, iSeekLength, SEEK_SET );
134
 
  return iOffset;
135
 
}
136
 
 
137
 
int SYS_ReadFile( int iHandle, char *pcBuffer, int iLength ) {
138
 
  return read( iHandle, pcBuffer, iLength );
139
 
}
140
 
 
141
 
int SYS_WriteFile( int iHandle, char *pcBuffer, int iLength ) {
142
 
  return write( iHandle, pcBuffer, iLength );
143
 
}
144
 
 
145
 
int SYS_GetPageSize( void ) {
146
 
  return getpagesize();
147
 
}
148
 
 
149
 
void *SYS_MemoryMap( int iSize, int iFid, int iOffset ) {
150
 
 
151
 
  void *vAddress;
152
 
 
153
 
  vAddress = 0;
154
 
  vAddress = mmap( 0, iSize, PROT_READ | PROT_WRITE,
155
 
                   MAP_SHARED, iFid, iOffset ); 
156
 
 
157
 
  /* Here are some common error types:
158
 
  switch( errno ) {
159
 
  case EINVAL:
160
 
    printf("EINVAL");
161
 
  case EBADF:
162
 
    printf("EBADF");
163
 
    break;
164
 
  case EACCES:
165
 
    printf("EACCES");
166
 
    break;
167
 
  case EAGAIN:
168
 
    printf("EAGAIN");
169
 
    break;
170
 
  case ENOMEM:
171
 
    printf("ENOMEM");
172
 
    break;
173
 
  }
174
 
  */
175
 
 
176
 
  return vAddress;
177
 
}
178
 
 
179
 
void *SYS_PublicMemoryMap( int iSize, int iFid, int iOffset ) {
180
 
 
181
 
  void *vAddress;
182
 
 
183
 
  vAddress = 0;
184
 
  vAddress = mmap( 0, iSize, PROT_READ,
185
 
                   MAP_SHARED, iFid, iOffset ); 
186
 
  return vAddress;
187
 
}
188
 
 
189
 
int SYS_MMapSynchronize( void *begin, int length ) {
190
 
  return msync(begin, length, MS_SYNC);
191
 
}
192
 
 
193
 
int SYS_Fork() {
194
 
  return fork();
195
 
}
196
 
 
197
 
int SYS_Wait( int iPid, int iWait ) {
198
 
 return waitpid( -1, 0, WNOHANG );
199
 
}
200
 
 
201
 
int SYS_Stat( char *pcFile, struct stat *psStatus ) {
202
 
  return stat( pcFile, psStatus );
203
 
}
204
 
 
205
 
int SYS_Fstat( int iFd ) {
206
 
  struct stat sStatus;
207
 
  return fstat( iFd, &sStatus );
208
 
}
209
 
 
210
 
int SYS_Random( int iSeed, float fStart, float fEnd ) {
211
 
 
212
 
  int iRandNum = 0;
213
 
 
214
 
  if ( iSeed != 0 ) {
215
 
    srand( iSeed );
216
 
  }
217
 
 
218
 
  iRandNum = 1+(int)(fEnd*rand()/(RAND_MAX+fStart)); 
219
 
  srand( iRandNum );
220
 
 
221
 
  return iRandNum;
222
 
}
223
 
 
224
 
int SYS_GetSeed() {
225
 
  struct timeval tv;
226
 
  struct timezone tz;
227
 
  long myseed = 0;  
228
 
 
229
 
  tz.tz_minuteswest = 0;
230
 
  tz.tz_dsttime = 0;
231
 
  if (gettimeofday(&tv, &tz) == 0) {
232
 
    myseed = tv.tv_usec;
233
 
  } else {
234
 
    myseed = (long ) time(NULL);
235
 
  }                                   
236
 
  return myseed;
237
 
}
238
 
 
239
 
int SYS_Exit( int iRetVal ) {
240
 
  _exit( iRetVal );
241
 
}
242
 
 
243
 
int SYS_Rmdir( char *pcFile )
244
 
{
245
 
        return rmdir(pcFile);
246
 
}
247
 
 
248
 
int SYS_Unlink( char *pcFile )
249
 
{
250
 
        return unlink(pcFile);
251
 
}
252