17#if _SQUID_WINDOWS_ && !_SQUID_CYGWIN_
19#define sys_nerr _sys_nerr
33THREADLOCAL
int ws32_result;
36void GetProcessName(pid_t,
char *);
38#if HAVE_GETPAGESIZE > 1
42 static DWORD system_pagesize = 0;
43 if (!system_pagesize) {
44 SYSTEM_INFO system_info;
45 GetSystemInfo(&system_info);
46 system_pagesize = system_info.dwPageSize;
48 return system_pagesize;
53chroot(
const char *dirname)
55 if (SetCurrentDirectory(dirname))
58 return GetLastError();
62GetProcessName(pid_t
pid,
char *ProcessName)
64 strcpy(ProcessName,
"unknown");
65#if defined(PSAPI_VERSION)
67 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
pid);
73 if (EnumProcessModules(hProcess, &hMod,
sizeof(hMod), &cbNeeded))
74 GetModuleBaseName(hProcess, hMod, ProcessName,
sizeof(ProcessName));
76 CloseHandle(hProcess);
81 CloseHandle(hProcess);
86kill(pid_t
pid,
int sig)
89 char MyProcessName[MAX_PATH];
90 char ProcessNameToCheck[MAX_PATH];
93 if (!(hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
pid)))
96 CloseHandle(hProcess);
97 GetProcessName(getpid(), MyProcessName);
98 GetProcessName(
pid, ProcessNameToCheck);
99 if (strcmp(MyProcessName, ProcessNameToCheck) == 0)
107#if !HAVE_GETTIMEOFDAY
109gettimeofday(
struct timeval *pcur_time,
void *tzp)
111 struct _timeb current;
112 struct timezone *tz = (
struct timezone *) tzp;
116 pcur_time->tv_sec = current.time;
117 pcur_time->tv_usec = current.millitm * 1000L;
119 tz->tz_minuteswest = current.timezone;
120 tz->tz_dsttime = current.dstflag;
127WIN32_ftruncate(
int fd, off_t
size)
135 hfile = (HANDLE) _get_osfhandle(fd);
136 curpos = SetFilePointer(hfile, 0,
nullptr, FILE_CURRENT);
137 if (curpos == 0xFFFFFFFF
138 || SetFilePointer(hfile,
size,
nullptr, FILE_BEGIN) == 0xFFFFFFFF
139 || !SetEndOfFile(hfile)) {
140 int error = GetLastError();
143 case ERROR_INVALID_HANDLE:
157WIN32_truncate(
const char *pathname, off_t length)
162 fd = open(pathname, O_RDWR);
167 res = WIN32_ftruncate(fd, length);
175getpwnam(
char *unused) {
176 static struct passwd pwd = {
nullptr,
nullptr, 100, 100,
nullptr,
nullptr,
nullptr};
181getgrnam(
char *unused) {
182 static struct group grp = {
nullptr,
nullptr, 100,
nullptr};
187 unsigned long WIN32_code;
191static struct errorentry errortable[] = {
192 {ERROR_INVALID_FUNCTION, EINVAL},
193 {ERROR_FILE_NOT_FOUND, ENOENT},
194 {ERROR_PATH_NOT_FOUND, ENOENT},
195 {ERROR_TOO_MANY_OPEN_FILES, EMFILE},
196 {ERROR_ACCESS_DENIED, EACCES},
197 {ERROR_INVALID_HANDLE, EBADF},
198 {ERROR_ARENA_TRASHED, ENOMEM},
199 {ERROR_NOT_ENOUGH_MEMORY, ENOMEM},
200 {ERROR_INVALID_BLOCK, ENOMEM},
201 {ERROR_BAD_ENVIRONMENT, E2BIG},
202 {ERROR_BAD_FORMAT, ENOEXEC},
203 {ERROR_INVALID_ACCESS, EINVAL},
204 {ERROR_INVALID_DATA, EINVAL},
205 {ERROR_INVALID_DRIVE, ENOENT},
206 {ERROR_CURRENT_DIRECTORY, EACCES},
207 {ERROR_NOT_SAME_DEVICE, EXDEV},
208 {ERROR_NO_MORE_FILES, ENOENT},
209 {ERROR_LOCK_VIOLATION, EACCES},
210 {ERROR_BAD_NETPATH, ENOENT},
211 {ERROR_NETWORK_ACCESS_DENIED, EACCES},
212 {ERROR_BAD_NET_NAME, ENOENT},
213 {ERROR_FILE_EXISTS, EEXIST},
214 {ERROR_CANNOT_MAKE, EACCES},
215 {ERROR_FAIL_I24, EACCES},
216 {ERROR_INVALID_PARAMETER, EINVAL},
217 {ERROR_NO_PROC_SLOTS, EAGAIN},
218 {ERROR_DRIVE_LOCKED, EACCES},
219 {ERROR_BROKEN_PIPE, EPIPE},
220 {ERROR_DISK_FULL, ENOSPC},
221 {ERROR_INVALID_TARGET_HANDLE, EBADF},
222 {ERROR_INVALID_HANDLE, EINVAL},
223 {ERROR_WAIT_NO_CHILDREN, ECHILD},
224 {ERROR_CHILD_NOT_COMPLETE, ECHILD},
225 {ERROR_DIRECT_ACCESS_HANDLE, EBADF},
226 {ERROR_NEGATIVE_SEEK, EINVAL},
227 {ERROR_SEEK_ON_DEVICE, EACCES},
228 {ERROR_DIR_NOT_EMPTY, ENOTEMPTY},
229 {ERROR_NOT_LOCKED, EACCES},
230 {ERROR_BAD_PATHNAME, ENOENT},
231 {ERROR_MAX_THRDS_REACHED, EAGAIN},
232 {ERROR_LOCK_FAILED, EACCES},
233 {ERROR_ALREADY_EXISTS, EEXIST},
234 {ERROR_FILENAME_EXCED_RANGE, ENOENT},
235 {ERROR_NESTING_NOT_ALLOWED, EAGAIN},
236 {ERROR_NOT_ENOUGH_QUOTA, ENOMEM}
239#define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
240#define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
242#define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
243#define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
246WIN32_maperror(
unsigned long WIN32_oserrno)
248 _doserrno = WIN32_oserrno;
249 for (
size_t i = 0; i < (
sizeof(errortable) /
sizeof(
struct errorentry)); ++i) {
250 if (WIN32_oserrno == errortable[i].WIN32_code) {
251 errno = errortable[i].POSIX_errno;
255 if (WIN32_oserrno >= MIN_EACCES_RANGE && WIN32_oserrno <= MAX_EACCES_RANGE)
257 else if (WIN32_oserrno >= MIN_EXEC_ERROR && WIN32_oserrno <= MAX_EXEC_ERROR)
264static HANDLE ms_eventlog;
267openlog(
const char *ident,
int logopt,
int facility)
272 ms_eventlog = RegisterEventSourceA(
nullptr, ident);
277#define SYSLOG_MAX_MSG_SIZE 1024
280syslog(
int priority,
const char *fmt, ...)
283 char *str=
static_cast<char *
>(
xmalloc(SYSLOG_MAX_MSG_SIZE));
291 str_len = vsnprintf(str, SYSLOG_MAX_MSG_SIZE-1, fmt, ap);
304 logtype = EVENTLOG_ERROR_TYPE;
308 logtype = EVENTLOG_WARNING_TYPE;
315 logtype = EVENTLOG_INFORMATION_TYPE;
320 ReportEventA(ms_eventlog, logtype, 0, 0,
nullptr, 1, 0,
321 const_cast<const char **
>(&str),
nullptr);
SQUIDCEXTERN LPCRITICAL_SECTION dbg_mutex
void error(char *format,...)