File: compat.h

package info (click to toggle)
streamripper 1.64.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,904 kB
  • sloc: ansic: 11,699; sh: 8,548; makefile: 421; perl: 34
file content (121 lines) | stat: -rw-r--r-- 3,734 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* compat.h
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#ifndef __COMPAT_H__
#define __COMPAT_H__

#if WIN32
#include <direct.h>
#include <windows.h>
#include <process.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <semaphore.h>
#include <pthread.h>
#endif

//
// This file handles all portablity issues with streamripper
//

// File Routines
////////////////////////////////////////// 

#ifdef WIN32

#define FHANDLE	HANDLE
#define OpenFile(_filename_)	CreateFile(_filename_, GENERIC_READ,  	\
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 	\
		FILE_ATTRIBUTE_NORMAL, NULL)
// #define CloseFile(_fhandle_) 	CloseHandle(_fhandle_)
#define TruncateFile(_filename_) \
       CloseFile(CreateFile(_filename_, GENERIC_WRITE, \
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, \
                TRUNCATE_EXISTING, \
		FILE_ATTRIBUTE_NORMAL, NULL))
//#define MoveFile(_oldfile_, _newfile_)     MoveFile(_oldfile_, _newfile_)
#define INVALID_FHANDLE 	INVALID_HANDLE_VALUE

#define close _close

#elif __UNIX__

#define FHANDLE	int
// #define OpenFile(_filename_)	open(_filename_, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
// #define CloseFile(_fhandle_) 	close(_fhandle_)
// #define TruncateFile(_filename_)	CloseFile(open(_filename_, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))
// #define MoveFile(_oldfile_, _newfile_)     rename(_oldfile_, _newfile_)
// #define DeleteFile(_file_)  	(!unlink(_file_))
#define INVALID_FHANDLE 	-1

#endif 

// Thread Routines
#if WIN32
#define THREAD_HANDLE	HANDLE
#define BeginThread(_thandle_, callback, arg) \
               {_thandle_ = (THREAD_HANDLE)_beginthread((void*) callback, 0, (void*) arg);}
#define WaitForThread(_thandle_)	WaitForSingleObject(_thandle_, INFINITE);
#define DestroyThread(_thandle_)	CloseHandle(_thandle_)

#define HSEM			HANDLE
#define	SemInit(_s_)	{_s_ = CreateEvent(NULL, TRUE, FALSE, NULL);}
#define	SemWait(_s_)	{WaitForSingleObject(_s_, INFINITE); ResetEvent(_s_);}
#define	SemPost(_s_)	SetEvent(_s_)
#define	SemDestroy(_s_)	CloseHandle(_s_)
#define sleep(x) 	Sleep(1000*x)


#elif __UNIX__

#define THREAD_HANDLE		pthread_t
#define BeginThread(_thandle_, callback, arg) \
               pthread_create(&_thandle_, NULL, \
                          (void *)callback, (void *)arg)
#define WaitForThread(_thandle_)	pthread_join(_thandle_, NULL)
#define DestroyThread(_thandle_)	// is there one for unix?
#define HSEM		sem_t
#define	SemInit(_s_)	sem_init(&(_s_), 0, 0)
#define	SemWait(_s_)	sem_wait(&(_s_))
#define	SemPost(_s_)	sem_post(&(_s_))
#define	SemDestroy(_s_)	sem_destroy(&(_s_))
#define Sleep(x) 	usleep(1000*x)

#endif

// Socket Routines
////////////////////////////////////////// 

#if WIN32
//#define EAGAIN          WSAEWOULDBLOCK
#define EWOULDBLOCK     WSAEWOULDBLOCK
#elif __UNIX__
#define closesocket     close
#define SOCKET_ERROR	-1
#define WSACleanup()
#endif

// Other stuff
////////////////////////////////////////// 

#if WIN32
#define snprintf _snprintf
#endif

#endif // __COMPAT_H__