19 #if _SQUID_WINDOWS_ && !_SQUID_CYGWIN_
21 #define sys_nerr _sys_nerr
28 #include <sys/timeb.h>
36 THREADLOCAL
int ws32_result;
39 void GetProcessName(pid_t,
char *);
41 #if HAVE_GETPAGESIZE > 1
45 static DWORD system_pagesize = 0;
46 if (!system_pagesize) {
47 SYSTEM_INFO system_info;
48 GetSystemInfo(&system_info);
49 system_pagesize = system_info.dwPageSize;
51 return system_pagesize;
56 chroot(
const char *dirname)
58 if (SetCurrentDirectory(dirname))
61 return GetLastError();
65 GetProcessName(pid_t
pid,
char *ProcessName)
67 strcpy(ProcessName,
"unknown");
68 #if defined(PSAPI_VERSION)
70 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
pid);
76 if (EnumProcessModules(hProcess, &hMod,
sizeof(hMod), &cbNeeded))
77 GetModuleBaseName(hProcess, hMod, ProcessName,
sizeof(ProcessName));
79 CloseHandle(hProcess);
84 CloseHandle(hProcess);
89 kill(pid_t
pid,
int sig)
92 char MyProcessName[MAX_PATH];
93 char ProcessNameToCheck[MAX_PATH];
96 if (!(hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
pid)))
99 CloseHandle(hProcess);
100 GetProcessName(getpid(), MyProcessName);
101 GetProcessName(
pid, ProcessNameToCheck);
102 if (strcmp(MyProcessName, ProcessNameToCheck) == 0)
110 #if !HAVE_GETTIMEOFDAY
112 gettimeofday(
struct timeval *pcur_time,
void *tzp)
114 struct _timeb current;
115 struct timezone *tz = (
struct timezone *) tzp;
119 pcur_time->tv_sec = current.time;
120 pcur_time->tv_usec = current.millitm * 1000L;
122 tz->tz_minuteswest = current.timezone;
123 tz->tz_dsttime = current.dstflag;
130 WIN32_ftruncate(
int fd, off_t
size)
138 hfile = (HANDLE) _get_osfhandle(fd);
139 curpos = SetFilePointer(hfile, 0,
nullptr, FILE_CURRENT);
140 if (curpos == 0xFFFFFFFF
141 || SetFilePointer(hfile,
size,
nullptr, FILE_BEGIN) == 0xFFFFFFFF
142 || !SetEndOfFile(hfile)) {
143 int error = GetLastError();
146 case ERROR_INVALID_HANDLE:
160 WIN32_truncate(
const char *pathname, off_t length)
164 const auto fd =
xopen(pathname, O_RDWR);
169 res = WIN32_ftruncate(fd, length);
177 getpwnam(
char *unused) {
178 static struct passwd pwd = {
nullptr,
nullptr, 100, 100,
nullptr,
nullptr,
nullptr};
183 getgrnam(
char *unused) {
184 static struct group grp = {
nullptr,
nullptr, 100,
nullptr};
189 static HANDLE ms_eventlog;
192 openlog(
const char *ident,
int logopt,
int facility)
197 ms_eventlog = RegisterEventSourceA(
nullptr, ident);
202 #define SYSLOG_MAX_MSG_SIZE 1024
205 syslog(
int priority,
const char *fmt, ...)
215 auto buf = std::make_unique<char[]>(SYSLOG_MAX_MSG_SIZE);
216 str_len = vsnprintf(buf.get(), SYSLOG_MAX_MSG_SIZE, fmt, ap);
229 logtype = EVENTLOG_ERROR_TYPE;
233 logtype = EVENTLOG_WARNING_TYPE;
240 logtype = EVENTLOG_INFORMATION_TYPE;
245 const auto strings[1] = { buf.get() };
246 ReportEventA(ms_eventlog, logtype, 0, 0,
nullptr, 1, 0,