![]() |
RTXI 1.3
|
00001 /* 00002 Kernel compatibility header file 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #ifndef _KERNEL_COMPAT_H 00021 #define _KERNEL_COMPAT_H 00022 00023 #include_next <linux/kernel.h> 00024 #include <linux/version.h> 00025 00026 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 00027 00028 #define container_of(ptr, type, member) ({ \ 00029 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 00030 (type *)( (char *)__mptr - offsetof(type,member) );}) 00031 00032 #endif 00033 00034 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) 00035 /* Add missing strict_strtox functions. */ 00036 #include <linux/string.h> 00037 #include <linux/errno.h> 00038 00039 static inline int comedi_strict_strtoul(const char *cp, unsigned int base, 00040 unsigned long *res) 00041 { 00042 char *tail; 00043 unsigned long val; 00044 size_t len; 00045 00046 *res = 0; 00047 len = strlen(cp); 00048 if (len == 0) 00049 return -EINVAL; 00050 00051 val = simple_strtoul(cp, &tail, base); 00052 if (tail == cp) 00053 return -EINVAL; 00054 if ((*tail == '\0') || 00055 ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { 00056 *res = val; 00057 return 0; 00058 } 00059 00060 return -EINVAL; 00061 } 00062 00063 #undef strict_strtoul 00064 #define strict_strtoul(cp, base, res) comedi_strict_strtoul(cp, base, res) 00065 00066 static inline int comedi_strict_strtol(const char *cp, unsigned int base, 00067 long *res) 00068 { 00069 int ret; 00070 if (*cp == '-') { 00071 ret = comedi_strict_strtoul(cp + 1, base, (unsigned long *)res); 00072 if (!ret) 00073 *res = -(*res); 00074 } else { 00075 ret = comedi_strict_strtoul(cp, base, (unsigned long *)res); 00076 } 00077 00078 return ret; 00079 } 00080 00081 #undef strict_strtol 00082 #define strict_strtol(cp, base, res) comedi_strict_strtoul(cp, base, res) 00083 00084 static inline int comedi_strict_strtoull(const char *cp, unsigned int base, 00085 unsigned long long *res) 00086 { 00087 char *tail; 00088 unsigned long long val; 00089 size_t len; 00090 00091 *res = 0; 00092 len = strlen(cp); 00093 if (len == 0) 00094 return -EINVAL; 00095 00096 val = simple_strtoull(cp, &tail, base); 00097 if (tail == cp) 00098 return -EINVAL; 00099 if ((*tail == '\0') || 00100 ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { 00101 *res = val; 00102 return 0; 00103 } 00104 00105 return -EINVAL; 00106 } 00107 00108 #undef strict_strtoull 00109 #define strict_strtoull(cp, base, res) comedi_strict_strtoul(cp, base, res) 00110 00111 static inline int comedi_strict_strtoll(const char *cp, unsigned int base, 00112 long long *res) 00113 { 00114 int ret; 00115 if (*cp == '-') { 00116 ret = comedi_strict_strtoull(cp + 1, base, (unsigned long long *)res); 00117 if (!ret) 00118 *res = -(*res); 00119 } else { 00120 ret = comedi_strict_strtoull(cp, base, (unsigned long long *)res); 00121 } 00122 00123 return ret; 00124 } 00125 00126 #undef strict_strtoll 00127 #define strict_strtoll(cp, base, res) comedi_strict_strtoul(cp, base, res) 00128 00129 #endif 00130 00131 #endif // _KERNEL_COMPAT_H