On Monday, 26 March 2007 15:40, Stefan Seyfried wrote: > On Mon, Mar 26, 2007 at 12:36:09PM +0200, Rafael J. Wysocki wrote: > > On Monday, 26 March 2007 11:07, Stefan Seyfried wrote: > > > Hi, > > > > > > after reading this thread, i got the impression that we do not report > > > errors verbosely enough. I mean - we normally never see those messages, > > > but if we do, due to an error having happened, we always need to start > > > adding more debugging printf's before we know what happened. > > > > > > Oh, yes, and pm-ops->* can only return -1 or 0, so telling the user > > > that it returned "-1" is also pretty pointless, let's tell him whats > > > in errno instead. > > > > > > So i came up with this one, comments are appreciated: > > > > Looks good at first sight, although I'd prefer to use an inline function > > instead of the #define for suspend_error(). > > This would probably look like this (the "##args" can be there or absent, > which is pretty nicely handled by the preprocessor): > > static inline void suspend_error(err, const char *msg, ...) { > va_list varpointer; > char *buffer = NULL; > char *format = NULL; > > if (!msg) > return; > > if (!(buffer = malloc(strlen(msg) + 256))) > return; > if (!(format = malloc(strlen(msg) + 256))) { > free(buffer); > return; > } > > va_start(varpointer, msg); > > sprintf(format, "suspend: %s", msg); > vsprintf(buffer, format, varpointer); > > fprintf(stderr, "%s Reason: %s\n", buffer, strerror(err)); > > va_end(varpointer); > > free(buffer); > } > > And i don't like it. I'd rather have the preprocesor do this.
OK > Pavel's suggestion about %m is a good one, though. > > Version 2: Looks good. Greetings, Rafael ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Suspend-devel mailing list Suspend-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/suspend-devel