Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenadns_unix_calls.c
Go to the documentation of this file.
00001 00002 /* 00003 * adns_unix_calls.c 00004 * - Simple implementation of requiered UNIX system calls and 00005 * library functions. 00006 */ 00007 /* 00008 * This file is 00009 * Copyright (C) 2000, 2002 Jarle (jgaa) Aase <jgaa@jgaa.com> 00010 * 00011 * It is part of adns, which is 00012 * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk> 00013 * Copyright (C) 1999 Tony Finch <dot@dotat.at> 00014 * 00015 * This program is free software; you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License as published by 00017 * the Free Software Foundation; either version 2, or (at your option) 00018 * any later version. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with this program; if not, write to the Free Software Foundation, 00027 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00028 */ 00029 00030 00031 #include "adns.h" 00032 00033 int adns_writev(int FileDescriptor, const struct iovec * iov, int iovCount) 00034 { 00035 size_t total_len = 0; 00036 int i = 0, r = 0; 00037 char *buf = NULL, *p = NULL; 00038 00039 for(; i < iovCount; i++) 00040 total_len += iov[i].iov_len; 00041 00042 p = buf = (char *)_alloca(total_len); 00043 00044 for(; i < iovCount; i++) 00045 { 00046 memcpy(p, iov[i].iov_base, iov[i].iov_len); 00047 p += iov[i].iov_len; 00048 } 00049 00050 ADNS_CLEAR_ERRNO 00051 r = send(FileDescriptor, buf, total_len, 0); 00052 ADNS_CAPTURE_ERRNO; 00053 return r; 00054 } 00055 00056 int adns_inet_aton(const char *cp, struct in_addr *inp) 00057 { 00058 if (!cp || !*cp || !inp) 00059 { 00060 errno = EINVAL; 00061 return -1; 00062 } 00063 00064 if (!strcmp(cp, "255.255.255.255")) 00065 { 00066 // Special case 00067 inp->s_addr = INADDR_NONE; 00068 return 0; 00069 } 00070 00071 inp->s_addr = inet_addr(cp); 00072 return (inp->s_addr == INADDR_NONE) ? -1 : 0; 00073 } 00074 00075 int adns_getpid() 00076 { 00077 return GetCurrentProcessId(); 00078 } 00079 00080 int gettimeofday(struct timeval *tv, struct timezone *tz) 00081 { 00082 static __int64 Adjustment; 00083 __int64 now = 0; 00084 00085 if (!Adjustment) 00086 { 00087 SYSTEMTIME st = {1970,1,0,1,0,0,0}; 00088 SystemTimeToFileTime(&st, (LPFILETIME)&Adjustment); 00089 } 00090 00091 if (tz) 00092 { 00093 errno = EINVAL; 00094 return -1; 00095 } 00096 00097 GetSystemTimeAsFileTime((LPFILETIME)&now); 00098 now -= Adjustment; 00099 00100 tv->tv_sec = (long)(now / 10000000); 00101 tv->tv_usec = (long)((now % 10000000) / 10); 00102 00103 return 0; 00104 } 00105 00106 /* Memory allocated in the DLL must be freed in the dll, so 00107 we provide memory manegement functions. */ 00108 00109 #ifdef ADNS_DLL 00110 00111 #undef malloc 00112 #undef realloc 00113 #undef free 00114 00115 void *adns_malloc(const size_t bytes) 00116 { 00117 return malloc(bytes); 00118 } 00119 00120 void *adns_realloc(void *ptr, const size_t bytes) 00121 { 00122 return realloc(ptr, bytes); 00123 } 00124 00125 void adns_free(void *ptr) 00126 { 00127 free(ptr); 00128 } 00129 00130 #endif /* ADNS_DLL */ Generated on Fri May 25 2012 04:31:58 for ReactOS by
1.7.6.1
|