17 #if _SQUID_WINDOWS_ && !_SQUID_CYGWIN_
19 #define sys_nerr _sys_nerr
25 #include <sys/timeb.h>
33 THREADLOCAL
int ws32_result;
36 void 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;
53 chroot(
const char *dirname)
55 if (SetCurrentDirectory(dirname))
58 return GetLastError();
62 GetProcessName(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);
86 kill(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
109 gettimeofday(
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;
127 WIN32_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:
157 WIN32_truncate(
const char *pathname, off_t length)
162 fd = open(pathname, O_RDWR);
167 res = WIN32_ftruncate(fd, length);
175 getpwnam(
char *unused) {
176 static struct passwd pwd = {
nullptr,
nullptr, 100, 100,
nullptr,
nullptr,
nullptr};
181 getgrnam(
char *unused) {
182 static struct group grp = {
nullptr,
nullptr, 100,
nullptr};
187 static HANDLE ms_eventlog;
190 openlog(
const char *ident,
int logopt,
int facility)
195 ms_eventlog = RegisterEventSourceA(
nullptr, ident);
200 #define SYSLOG_MAX_MSG_SIZE 1024
203 syslog(
int priority,
const char *fmt, ...)
206 char *str=
static_cast<char *
>(
xmalloc(SYSLOG_MAX_MSG_SIZE));
214 str_len = vsnprintf(str, SYSLOG_MAX_MSG_SIZE-1, fmt, ap);
227 logtype = EVENTLOG_ERROR_TYPE;
231 logtype = EVENTLOG_WARNING_TYPE;
238 logtype = EVENTLOG_INFORMATION_TYPE;
243 ReportEventA(ms_eventlog, logtype, 0, 0,
nullptr, 1, 0,
244 const_cast<const char **
>(&str),
nullptr);