![]() |
| | #1 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Xlib perversity Code: #include <stdio.h>
#include <X11/Xlib.h>
int main(void) {
Display *display = NULL;
perror("Now");
if ((display = XOpenDisplay(":0.0")) == NULL) {
perror("Can't connect to server");
}
printf("%p\n",display);
perror("Now");
XBell(display,100);
perror("Now");
return 0;
}
What's weird to my mind here is this output: Now: Success 0xf3a010 Now: Resource temporarily unavailable Now: Resource temporarily unavailable Apparently errno is getting set before the XBell call, but XOpenDisplay returned a valid pointer...
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| It might seem odd, but this is normal behavior for errno. You are never expected to clear errno upon success, only to set it upon failure. The general rule is to rely on the API's method for reporting error status, and ONLY if an error occurred can you examine errno. For the scant few functions where errno is the only way of indicating failure, you should actually set errno = 0 yourself before calling those functions. Probably, inside XOpenDisplay(), the client tries several different strategies to find the server, and one or more of these resulted in an error. Ask yourself, have you made it a habit to continuously set errno to 0 whenever you try something and it succeeds? Nobody else does that either, including library code.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #3 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
Anyway my bell still doesn't ring!
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is offline | |
| | #4 | |
| Jaxom's & Imriel's Dad Join Date: Aug 2006 Location: Alabama
Posts: 801
| I would guess that XOpenDisplay() doesn't set errno. I would think it would be more on the lines of errno is set by a function that XOpenDisplay() uses. I'm basing this on the following Quote:
| |
| Kennedy is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is XLib included in all Linux Distros? What about Solaris/OSX? | 6tr6tr | Linux Programming | 1 | 11-11-2008 11:24 AM |
| Xlib Fullscreen and/or borderless | IsmAvatar2 | Linux Programming | 0 | 06-17-2008 11:25 AM |
| XLib documentation | Series X4 1.0 | Linux Programming | 1 | 03-20-2005 06:31 PM |
| problems with gtk+, and xlib | Ian | Linux Programming | 3 | 12-02-2001 06:43 AM |