FAQ

svn commit: r885636 - in /lucene/lucy/trunk/core/Lucy/Object: Err.bp Err.c

Marvin
Dec 1, 2009 at 12:51 am
Author: marvin
Date: Tue Dec 1 00:50:36 2009
New Revision: 885636

URL: http://svn.apache.org/viewvc?rev=885636&view=rev
Log:
Add Err_win_error(), which is something like strerror(errno) for Windows.

Modified:
lucene/lucy/trunk/core/Lucy/Object/Err.bp
lucene/lucy/trunk/core/Lucy/Object/Err.c

Modified: lucene/lucy/trunk/core/Lucy/Object/Err.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Err.bp?rev=885636&r1=885635&r2=885636&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Err.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Err.bp Tue Dec 1 00:50:36 2009
@@ -130,6 +130,12 @@
*/
inert inline void
abstract_class_check(Obj *obj, VTable *vtable);
+
+ /** On Windows, return a newly allocated buffer containing the string
+ * description for the the last error in the thread.
+ */
+ inert char*
+ win_error();
}

__C__

Modified: lucene/lucy/trunk/core/Lucy/Object/Err.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Err.c?rev=885636&r1=885635&r2=885636&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Err.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Err.c Tue Dec 1 00:50:36 2009
@@ -11,6 +11,7 @@
#include "Lucy/Object/Err.h"
#include "Lucy/Object/CharBuf.h"
#include "Lucy/Object/VTable.h"
+#include "Lucy/Util/Memory.h"

Err*
Err_new(CharBuf *mess)
@@ -217,6 +218,45 @@
return obj;
}

+#ifdef CHY_HAS_WINDOWS_H
+
+#include <windows.h>
+
+char*
+Err_win_error()
+{
+ size_t buf_size = 256;
+ char *buf = (char*)MALLOCATE(buf_size);
+ size_t message_len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, /* message source table */
+ GetLastError(),
+ 0, /* language id */
+ buf,
+ buf_size,
+ NULL /* empty va_list */
+ );
+ if (message_len == 0) {
+ char unknown[] = "Unknown error";
+ size_t len = sizeof(unknown);
+ strncpy(buf, unknown, len);
+ }
+ else if (message_len > 1) {
+ /* Kill stupid newline. */
+ buf[message_len - 2] = '\0';
+ }
+ return buf;
+}
+
+#else
+
+char*
+Err_win_error()
+{
+ return NULL; /* Never called. */
+}
+
+#endif /* CHY_HAS_WINDOWS_H */
+
/* Copyright 2009 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
reply

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post

1 user in discussion

Marvin: 1 post