19 #if _SQUID_WINDOWS_ && !_SQUID_CYGWIN_
21 #define sys_nerr _sys_nerr
27 #include <sys/timeb.h>
35 THREADLOCAL
int ws32_result;
38 void GetProcessName(pid_t,
char *);
40 #if HAVE_GETPAGESIZE > 1
44 static DWORD system_pagesize = 0;
45 if (!system_pagesize) {
46 SYSTEM_INFO system_info;
47 GetSystemInfo(&system_info);
48 system_pagesize = system_info.dwPageSize;
50 return system_pagesize;
55 chroot(
const char *dirname)
57 if (SetCurrentDirectory(dirname))
60 return GetLastError();
64 GetProcessName(pid_t
pid,
char *ProcessName)
66 strcpy(ProcessName,
"unknown");
67 #if defined(PSAPI_VERSION)
69 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
pid);
75 if (EnumProcessModules(hProcess, &hMod,
sizeof(hMod), &cbNeeded))
76 GetModuleBaseName(hProcess, hMod, ProcessName,
sizeof(ProcessName));
78 CloseHandle(hProcess);
83 CloseHandle(hProcess);
88 kill(pid_t
pid,
int sig)
91 char MyProcessName[MAX_PATH];
92 char ProcessNameToCheck[MAX_PATH];
95 if (!(hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
pid)))
98 CloseHandle(hProcess);
99 GetProcessName(getpid(), MyProcessName);
100 GetProcessName(
pid, ProcessNameToCheck);
101 if (strcmp(MyProcessName, ProcessNameToCheck) == 0)
109 #if !HAVE_GETTIMEOFDAY
111 gettimeofday(
struct timeval *pcur_time,
void *tzp)
113 struct _timeb current;
114 struct timezone *tz = (
struct timezone *) tzp;
118 pcur_time->tv_sec = current.time;
119 pcur_time->tv_usec = current.millitm * 1000L;
121 tz->tz_minuteswest = current.timezone;
122 tz->tz_dsttime = current.dstflag;
129 WIN32_ftruncate(
int fd, off_t
size)
137 hfile = (HANDLE) _get_osfhandle(fd);
138 curpos = SetFilePointer(hfile, 0,
nullptr, FILE_CURRENT);
139 if (curpos == 0xFFFFFFFF
140 || SetFilePointer(hfile,
size,
nullptr, FILE_BEGIN) == 0xFFFFFFFF
141 || !SetEndOfFile(hfile)) {
142 int error = GetLastError();
145 case ERROR_INVALID_HANDLE:
159 WIN32_truncate(
const char *pathname, off_t length)
163 const auto fd =
xopen(pathname, O_RDWR);
168 res = WIN32_ftruncate(fd, length);
176 getpwnam(
char *unused) {
177 static struct passwd pwd = {
nullptr,
nullptr, 100, 100,
nullptr,
nullptr,
nullptr};
182 getgrnam(
char *unused) {
183 static struct group grp = {
nullptr,
nullptr, 100,
nullptr};
188 static HANDLE ms_eventlog;
191 openlog(
const char *ident,
int logopt,
int facility)
196 ms_eventlog = RegisterEventSourceA(
nullptr, ident);
201 #define SYSLOG_MAX_MSG_SIZE 1024
204 syslog(
int priority,
const char *fmt, ...)
207 char *str=
static_cast<char *
>(
xmalloc(SYSLOG_MAX_MSG_SIZE));
215 str_len = vsnprintf(str, SYSLOG_MAX_MSG_SIZE-1, fmt, ap);
228 logtype = EVENTLOG_ERROR_TYPE;
232 logtype = EVENTLOG_WARNING_TYPE;
239 logtype = EVENTLOG_INFORMATION_TYPE;
244 ReportEventA(ms_eventlog, logtype, 0, 0,
nullptr, 1, 0,
245 const_cast<const char **
>(&str),
nullptr);