]> rtime.felk.cvut.cz Git - orte.git/blob - orte/include/rtai/compat.h
Reformat the sources with orte/uncrustify script
[orte.git] / orte / include / rtai / compat.h
1 /*
2  *  $Id: compat.h,v 0.0.0.1             2004/11/14
3  *
4  *  -------------------------------------------------------------------
5  *                                ORTE
6  *                      Open Real-Time Ethernet
7  *
8  *                      Copyright (C) 2001-2006
9  *  Department of Control Engineering FEE CTU Prague, Czech Republic
10  *                      http://dce.felk.cvut.cz
11  *                      http://www.ocera.org
12  *
13  *  Author:              Petr Smolik       petr@smoliku.cz
14  *  Author - this code:  Jan Kiszka        jan.kiszka@web.de
15  *  Advisor:             Pavel Pisa
16  *  Project Responsible: Zdenek Hanzalek
17  *  --------------------------------------------------------------------
18  *
19  *  This program is free software; you can redistribute it and/or modify
20  *  it under the terms of the GNU General Public License as published by
21  *  the Free Software Foundation; either version 2 of the License, or
22  *  (at your option) any later version.
23  *
24  *  This program is distributed in the hope that it will be useful,
25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *  GNU General Public License for more details.
28  *
29  */
30
31 #ifndef _COMPAT_H
32 #define _COMPAT_H
33
34 #include <linux/if.h>
35 #include <linux/in.h>
36 #include <rtnet.h>
37 #include "rtai_posix.h.patched"
38 #include <defines.h>  //macro MALLOC
39
40 /* This should become a bit more generic for all platforms... */
41 #define rtl_printf  rt_printk
42 #define printf      rt_printk /* catch some probably forgotten printf's */
43 #define malloc      rt_malloc
44 #define free        rt_free
45
46 typedef __u32 in_addr_t;
47
48 static inline in_addr_t
49 inet_addr(const char *cp)
50 {
51   return rt_inet_aton(cp);
52 }
53
54
55 static char inet_ntoa_buf[16];
56
57 static inline char *
58 inet_ntoa(struct in_addr in)
59 {
60   unsigned char *octet;
61
62   octet = (unsigned char *)&(in.s_addr);
63   sprintf(inet_ntoa_buf, "%u.%u.%u.%u", octet[0], octet[1], octet[2], octet[3]);
64
65   return inet_ntoa_buf;
66 }
67
68
69 #define CLOCK_REALTIME  0
70
71 static inline void
72 clock_gettime(int dummy, struct timespec *time)
73 {
74   count2timespec(rt_get_time(), time);
75 }
76
77
78 static inline int
79 atoi(const char *nptr)
80 {
81   return simple_strtol(nptr, (char **)NULL, 10);
82 }
83
84
85 #define sem_init                    sem_init_rt
86 #define sem_destroy                 sem_destroy_rt
87 #define sem_timedwait               sem_timedwait_rt
88 #define sem_post                    sem_post_rt
89 #define sem_getvalue                sem_getvalue_rt
90
91 #define pthread_rwlock_init         pthread_rwlock_init_rt
92 #define pthread_rwlock_rdlock       pthread_rwlock_rdlock_rt
93 #define pthread_rwlock_wrlock       pthread_rwlock_wrlock_rt
94 #define pthread_rwlock_unlock       pthread_rwlock_unlock_rt
95 #define pthread_rwlock_destroy      pthread_rwlock_destroy_rt
96
97 #define pthread_mutex_init          pthread_mutex_init_rt
98 #define pthread_mutex_lock          pthread_mutex_lock_rt
99 #define pthread_mutex_timedlock     pthread_mutex_timedlock_rt
100 #define pthread_mutex_unlock        pthread_mutex_unlock_rt
101 #define pthread_mutex_destroy       pthread_mutex_destroy_rt
102
103 #define pthread_create              pthread_create_rt
104 #define pthread_join                pthread_join_rt
105 #define pthread_exit                pthread_exit_rt
106
107 #define pthread_cond_init           pthread_cond_init_rt
108 #define pthread_cond_timedwait      pthread_cond_timedwait_rt
109 #define pthread_cond_signal         pthread_cond_signal_rt
110 #define pthread_cond_destroy        pthread_cond_destroy_rt
111
112 #define socket                      socket_rt
113 #define setsockopt                  setsockopt_rt
114 #define getsockopt                  getsockopt_rt
115 #define ioctl                       ioctl_rt
116 #define bind                        bind_rt
117 #define getsockname                 getsockname_rt
118 #define recvfrom                    recvfrom_rt
119 #define sendto                      sendto_rt
120
121 static inline int
122 close(int s)
123 {
124   int result;
125
126   while ((result = close_rt(s)) == -EAGAIN)
127     rt_sleep(nano2count(100000000));
128   return result;
129 }
130
131 #endif /* _COMPAT_H */