ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.329 by root, Tue Feb 16 09:32:39 2010 UTC vs.
Revision 1.332 by root, Tue Mar 9 08:58:17 2010 UTC

184# define WIN32_LEAN_AND_MEAN 184# define WIN32_LEAN_AND_MEAN
185# include <windows.h> 185# include <windows.h>
186# ifndef EV_SELECT_IS_WINSOCKET 186# ifndef EV_SELECT_IS_WINSOCKET
187# define EV_SELECT_IS_WINSOCKET 1 187# define EV_SELECT_IS_WINSOCKET 1
188# endif 188# endif
189# undef EV_AVOID_STDIO
189#endif 190#endif
190 191
191/* this block tries to deduce configuration from header-defined symbols and defaults */ 192/* this block tries to deduce configuration from header-defined symbols and defaults */
192 193
193/* try to deduce the maximum number of signals on this platform */ 194/* try to deduce the maximum number of signals on this platform */
524# include "ev_win32.c" 525# include "ev_win32.c"
525#endif 526#endif
526 527
527/*****************************************************************************/ 528/*****************************************************************************/
528 529
530#if EV_AVOID_STDIO
531static void noinline
532ev_printerr (const char *msg)
533{
534 write (STDERR_FILENO, msg, strlen (msg));
535}
536#endif
537
529static void (*syserr_cb)(const char *msg); 538static void (*syserr_cb)(const char *msg);
530 539
531void 540void
532ev_set_syserr_cb (void (*cb)(const char *msg)) 541ev_set_syserr_cb (void (*cb)(const char *msg))
533{ 542{
542 551
543 if (syserr_cb) 552 if (syserr_cb)
544 syserr_cb (msg); 553 syserr_cb (msg);
545 else 554 else
546 { 555 {
556#if EV_AVOID_STDIO
557 const char *err = strerror (errno);
558
559 ev_printerr (msg);
560 ev_printerr (": ");
561 ev_printerr (err);
562 ev_printerr ("\n");
563#else
547 perror (msg); 564 perror (msg);
565#endif
548 abort (); 566 abort ();
549 } 567 }
550} 568}
551 569
552static void * 570static void *
554{ 572{
555 /* some systems, notably openbsd and darwin, fail to properly 573 /* some systems, notably openbsd and darwin, fail to properly
556 * implement realloc (x, 0) (as required by both ansi c-98 and 574 * implement realloc (x, 0) (as required by both ansi c-98 and
557 * the single unix specification, so work around them here. 575 * the single unix specification, so work around them here.
558 */ 576 */
559
560 if (size) 577 if (size)
561 return realloc (ptr, size); 578 return realloc (ptr, size);
562 579
563 free (ptr); 580 free (ptr);
564 return 0; 581 return 0;
577{ 594{
578 ptr = alloc (ptr, size); 595 ptr = alloc (ptr, size);
579 596
580 if (!ptr && size) 597 if (!ptr && size)
581 { 598 {
599#if EV_AVOID_STDIO
600 ev_printerr ("libev: memory allocation failed, aborting.\n");
601#else
582 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 602 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
603#endif
583 abort (); 604 abort ();
584 } 605 }
585 606
586 return ptr; 607 return ptr;
587} 608}
2992 infy_wd (EV_A_ ev->wd, ev->wd, ev); 3013 infy_wd (EV_A_ ev->wd, ev->wd, ev);
2993 ofs += sizeof (struct inotify_event) + ev->len; 3014 ofs += sizeof (struct inotify_event) + ev->len;
2994 } 3015 }
2995} 3016}
2996 3017
3018inline_size unsigned int
3019ev_linux_version (void)
3020{
3021 struct utsname buf;
3022 unsigned int v;
3023 int i;
3024 char *p = buf.release;
3025
3026 if (uname (&buf))
3027 return 0;
3028
3029 for (i = 3+1; --i; )
3030 {
3031 unsigned int c = 0;
3032
3033 for (;;)
3034 {
3035 if (*p >= '0' && *p <= '9')
3036 c = c * 10 + *p++ - '0';
3037 else
3038 {
3039 p += *p == '.';
3040 break;
3041 }
3042 }
3043
3044 v = (v << 8) | c;
3045 }
3046
3047 return v;
3048}
3049
2997inline_size void 3050inline_size void
2998check_2625 (EV_P) 3051ev_check_2625 (EV_P)
2999{ 3052{
3000 /* kernels < 2.6.25 are borked 3053 /* kernels < 2.6.25 are borked
3001 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 3054 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
3002 */ 3055 */
3003 struct utsname buf; 3056 if (ev_linux_version () < 0x020619)
3004 int major, minor, micro;
3005
3006 if (uname (&buf))
3007 return;
3008
3009 if (sscanf (buf.release, "%d.%d.%d", &major, &minor, &micro) != 3)
3010 return;
3011
3012 if (major < 2
3013 || (major == 2 && minor < 6)
3014 || (major == 2 && minor == 6 && micro < 25))
3015 return; 3057 return;
3016 3058
3017 fs_2625 = 1; 3059 fs_2625 = 1;
3018} 3060}
3019 3061
3034 if (fs_fd != -2) 3076 if (fs_fd != -2)
3035 return; 3077 return;
3036 3078
3037 fs_fd = -1; 3079 fs_fd = -1;
3038 3080
3039 check_2625 (EV_A); 3081 ev_check_2625 (EV_A);
3040 3082
3041 fs_fd = infy_newfd (); 3083 fs_fd = infy_newfd ();
3042 3084
3043 if (fs_fd >= 0) 3085 if (fs_fd >= 0)
3044 { 3086 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines