diff -r d0aa9e0a6d04 -r 2d8fecb8f024 librazor/atomic.c --- a/librazor/atomic.c Thu Feb 09 20:42:08 2012 +0000 +++ b/librazor/atomic.c Fri Mar 23 20:24:09 2012 +0000 @@ -56,30 +56,23 @@ RAZOR_EXPORT const char * razor_atomic_get_error_msg(struct razor_atomic *atomic) { - if (!atomic->error_msg) { - if (atomic->error_path) - atomic->error_msg = razor_concat(atomic->error_path, - ": ", - atomic->error_str, - NULL); - else - atomic->error_msg = strdup(atomic->error_str); - } - - return atomic->error_msg; + if (atomic->error) + return razor_error_get_msg(atomic->error); + else + return NULL; } RAZOR_EXPORT void razor_atomic_abort(struct razor_atomic *atomic, const char *error_msg) { - if (!atomic->error_str) - razor_atomic_set_error_str(atomic, NULL, error_msg); + if (!atomic->error) + atomic->error = razor_error_new_str(NULL, error_msg); } RAZOR_EXPORT int razor_atomic_in_error_state(struct razor_atomic *atomic) { - return atomic->error_str && !atomic->in_undo; + return atomic->error && !atomic->in_undo; } #if !HAVE_WINDOWS_KTM @@ -110,41 +103,6 @@ #endif } -#ifdef MSWIN_API -void -razor_atomic_set_error_mswin(struct razor_atomic *atomic, const wchar_t *path, - DWORD error) -{ - wchar_t *buf; - - assert(!atomic->error_str); - - free(atomic->error_path); - - if (path) - atomic->error_path = razor_utf16_to_utf8(path, -1); - else - atomic->error_path = NULL; - - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER| - FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), - (LPWSTR)&buf, 0, NULL); - atomic->error_str = razor_utf16_to_utf8(buf, -1); - LocalFree(buf); -} -#endif - -void -razor_atomic_set_error_str(struct razor_atomic *atomic, const char *path, - const char *str) -{ - assert(!atomic->error_str); - - atomic->error_path = path ? strdup(path) : NULL; - atomic->error_str = strdup(str); -} - RAZOR_EXPORT int razor_atomic_write(struct razor_atomic *atomic, int fd, const void *data, size_t size) @@ -157,8 +115,8 @@ while(size) { written = write(fd, data, size); if (written < 0) { - razor_atomic_set_error_str(atomic, NULL, - strerror(errno)); + atomic->error = razor_error_new_str(NULL, + strerror(errno)); (void)close(fd); @@ -179,13 +137,10 @@ return -1; if (fsync(handle) < 0) { - razor_atomic_set_error_str(atomic, NULL, strerror(errno)); + atomic->error = razor_error_new_str(NULL, strerror(errno)); return -1; } - free(atomic->error_path); - atomic->error_path = NULL; - return 0; } @@ -196,13 +151,10 @@ return -1; if (close(fd) < 0) { - razor_atomic_set_error_str(atomic, NULL, strerror(errno)); + atomic->error = razor_error_new_str(NULL, strerror(errno)); return -1; } - free(atomic->error_path); - atomic->error_path = NULL; - return 0; }