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.335 by root, Tue Mar 9 09:02:03 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 *
553ev_realloc_emul (void *ptr, long size) 571ev_realloc_emul (void *ptr, long size)
554{ 572{
573#if __GLIBC__
574 return realloc (ptr, size);
575#else
555 /* some systems, notably openbsd and darwin, fail to properly 576 /* some systems, notably openbsd and darwin, fail to properly
556 * implement realloc (x, 0) (as required by both ansi c-98 and 577 * implement realloc (x, 0) (as required by both ansi c-89 and
557 * the single unix specification, so work around them here. 578 * the single unix specification, so work around them here.
558 */ 579 */
559 580
560 if (size) 581 if (size)
561 return realloc (ptr, size); 582 return realloc (ptr, size);
562 583
563 free (ptr); 584 free (ptr);
564 return 0; 585 return 0;
586#endif
565} 587}
566 588
567static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 589static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
568 590
569void 591void
577{ 599{
578 ptr = alloc (ptr, size); 600 ptr = alloc (ptr, size);
579 601
580 if (!ptr && size) 602 if (!ptr && size)
581 { 603 {
604#if EV_AVOID_STDIO
605 ev_printerr ("libev: memory allocation failed, aborting.\n");
606#else
582 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 607 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
608#endif
583 abort (); 609 abort ();
584 } 610 }
585 611
586 return ptr; 612 return ptr;
587} 613}
2992 infy_wd (EV_A_ ev->wd, ev->wd, ev); 3018 infy_wd (EV_A_ ev->wd, ev->wd, ev);
2993 ofs += sizeof (struct inotify_event) + ev->len; 3019 ofs += sizeof (struct inotify_event) + ev->len;
2994 } 3020 }
2995} 3021}
2996 3022
3023inline_size unsigned int
3024ev_linux_version (void)
3025{
3026 struct utsname buf;
3027 unsigned int v;
3028 int i;
3029 char *p = buf.release;
3030
3031 if (uname (&buf))
3032 return 0;
3033
3034 for (i = 3+1; --i; )
3035 {
3036 unsigned int c = 0;
3037
3038 for (;;)
3039 {
3040 if (*p >= '0' && *p <= '9')
3041 c = c * 10 + *p++ - '0';
3042 else
3043 {
3044 p += *p == '.';
3045 break;
3046 }
3047 }
3048
3049 v = (v << 8) | c;
3050 }
3051
3052 return v;
3053}
3054
2997inline_size void 3055inline_size void
2998check_2625 (EV_P) 3056ev_check_2625 (EV_P)
2999{ 3057{
3000 /* kernels < 2.6.25 are borked 3058 /* kernels < 2.6.25 are borked
3001 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 3059 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
3002 */ 3060 */
3003 struct utsname buf; 3061 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; 3062 return;
3016 3063
3017 fs_2625 = 1; 3064 fs_2625 = 1;
3018} 3065}
3019 3066
3034 if (fs_fd != -2) 3081 if (fs_fd != -2)
3035 return; 3082 return;
3036 3083
3037 fs_fd = -1; 3084 fs_fd = -1;
3038 3085
3039 check_2625 (EV_A); 3086 ev_check_2625 (EV_A);
3040 3087
3041 fs_fd = infy_newfd (); 3088 fs_fd = infy_newfd ();
3042 3089
3043 if (fs_fd >= 0) 3090 if (fs_fd >= 0)
3044 { 3091 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines