int flock (int fd,int op) { HANDLE hdl = (HANDLE) _get_osfhandle (fd); DWORD flags = (op & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0; OVERLAPPED offset = {NIL,NIL,0,0,NIL}; int ret = -1; blocknotify_t bn = (blocknotify_t) ((op & LOCK_NB) ? NIL : mail_parameters (NIL,GET_BLOCKNOTIFY,NIL)); if (hdl < 0) errno = EBADF; /* error in file descriptor */ else switch (op & ~LOCK_NB) { /* translate to LockFileEx() op */ case LOCK_EX: /* exclusive */ flags |= LOCKFILE_EXCLUSIVE_LOCK; case LOCK_SH: /* shared */ if (!check_nt ()) return 0; /* always succeeds if not NT */ if (bn) (*bn) (BLOCK_FILELOCK,NIL); /* bug for bug compatible with Unix */ UnlockFileEx (hdl,NIL,1,0,&offset); /* lock the file as requested */ if (LockFileEx (hdl,flags,NIL,1,0,&offset)) ret = 0; if (bn) (*bn) (BLOCK_NONE,NIL); /* if failed */ if (ret) errno = (op & LOCK_NB) ? EAGAIN : EBADF; break; case LOCK_UN: /* unlock */ if (check_nt ()) UnlockFileEx (hdl,NIL,1,0,&offset); ret = 0; /* always succeeds */ default: /* default */ errno = EINVAL; /* bad call */ break; } return ret; }
int main(int, char *[]) { check_nt(0.0); check_nt(CGAL::Kinetic::Default_field_nt(1)); typedef CGAL::Kinetic::Exact_simulation_traits Tr; Tr tr(0,1000000); Tr::Simulator::Function_kernel::Function fn= tr.kinetic_kernel_object().function_kernel_object().construct_function_object()(1,0,-2); check_nt(Tr::Simulator::Time(-1)); if (CGAL::Kinetic::internal::get_static_audit_failures() != 0) return EXIT_FAILURE; else return EXIT_SUCCESS; }
void syslog (int priority,const char *message,...) { va_list args; LPTSTR strs[2]; char tmp[MAILTMPLEN]; /* callers must be careful not to pop this */ unsigned short etype; if (!check_nt ()) return; /* no-op on non-NT system */ /* default event source */ if (!loghdl) openlog ("c-client",LOG_PID,LOG_MAIL); switch (priority) { /* translate UNIX type into NT type */ case LOG_ALERT: etype = EVENTLOG_ERROR_TYPE; break; case LOG_INFO: etype = EVENTLOG_INFORMATION_TYPE; break; default: etype = EVENTLOG_WARNING_TYPE; } va_start (args,message); /* initialize vararg mechanism */ vsprintf (tmp,message,args); /* build message */ strs[0] = loghdr; /* write header */ strs[1] = tmp; /* then the message */ /* report the event */ ReportEvent (loghdl,etype,(unsigned short) priority,2000,NIL,2,0,strs,NIL); va_end (args); }
void openlog (const char *ident,int logopt,int facility) { char tmp[MAILTMPLEN]; if (!check_nt ()) return; /* no-op on non-NT system */ if (loghdl) fatal ("Duplicate openlog()!"); loghdl = RegisterEventSource (NIL,ident); sprintf (tmp,(logopt & LOG_PID) ? "%s[%d]" : "%s",ident,getpid ()); loghdr = cpystr (tmp); /* save header for later */ }