librazor/atomic.c
changeset 426 2e896ad9754b
parent 416 d0aa9e0a6d04
child 439 f28bb31024b4
     1.1 --- a/librazor/atomic.c	Thu Feb 09 20:42:08 2012 +0000
     1.2 +++ b/librazor/atomic.c	Fri Feb 17 18:35:10 2012 +0000
     1.3 @@ -56,30 +56,23 @@
     1.4  RAZOR_EXPORT const char *
     1.5  razor_atomic_get_error_msg(struct razor_atomic *atomic)
     1.6  {
     1.7 -	if (!atomic->error_msg) {
     1.8 -		if (atomic->error_path)
     1.9 -			atomic->error_msg = razor_concat(atomic->error_path,
    1.10 -							 ": ",
    1.11 -							 atomic->error_str,
    1.12 -							 NULL);
    1.13 -		else
    1.14 -			atomic->error_msg = strdup(atomic->error_str);
    1.15 -	}
    1.16 -
    1.17 -	return atomic->error_msg;
    1.18 +	if (atomic->error)
    1.19 +		return razor_error_get_msg(atomic->error);
    1.20 +	else
    1.21 +		return NULL;
    1.22  }
    1.23  
    1.24  RAZOR_EXPORT void
    1.25  razor_atomic_abort(struct razor_atomic *atomic, const char *error_msg)
    1.26  {
    1.27 -	if (!atomic->error_str)
    1.28 -		razor_atomic_set_error_str(atomic, NULL, error_msg);
    1.29 +	if (!atomic->error)
    1.30 +		atomic->error = razor_error_new_str(NULL, error_msg);
    1.31  }
    1.32  
    1.33  RAZOR_EXPORT int
    1.34  razor_atomic_in_error_state(struct razor_atomic *atomic)
    1.35  {
    1.36 -	return atomic->error_str && !atomic->in_undo;
    1.37 +	return atomic->error && !atomic->in_undo;
    1.38  }
    1.39  
    1.40  #if !HAVE_WINDOWS_KTM
    1.41 @@ -110,41 +103,6 @@
    1.42  #endif
    1.43  }
    1.44  
    1.45 -#ifdef MSWIN_API
    1.46 -void
    1.47 -razor_atomic_set_error_mswin(struct razor_atomic *atomic, const wchar_t *path,
    1.48 -			     DWORD error)
    1.49 -{
    1.50 -	wchar_t *buf;
    1.51 -
    1.52 -	assert(!atomic->error_str);
    1.53 -
    1.54 -	free(atomic->error_path);
    1.55 -
    1.56 -	if (path)
    1.57 -		atomic->error_path = razor_utf16_to_utf8(path, -1);
    1.58 -	else
    1.59 -		atomic->error_path = NULL;
    1.60 -
    1.61 -	FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|
    1.62 -		       FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
    1.63 -		       NULL, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
    1.64 -		       (LPWSTR)&buf, 0, NULL);
    1.65 -	atomic->error_str = razor_utf16_to_utf8(buf, -1);
    1.66 -	LocalFree(buf);
    1.67 -}
    1.68 -#endif
    1.69 -
    1.70 -void
    1.71 -razor_atomic_set_error_str(struct razor_atomic *atomic, const char *path,
    1.72 -			   const char *str)
    1.73 -{
    1.74 -	assert(!atomic->error_str);
    1.75 -
    1.76 -	atomic->error_path = path ? strdup(path) : NULL;
    1.77 -	atomic->error_str = strdup(str);
    1.78 -}
    1.79 -
    1.80  RAZOR_EXPORT int
    1.81  razor_atomic_write(struct razor_atomic *atomic, int fd, const void *data,
    1.82  		   size_t size)
    1.83 @@ -157,8 +115,8 @@
    1.84  	while(size) {
    1.85  		written = write(fd, data, size);
    1.86  		if (written < 0) {
    1.87 -			razor_atomic_set_error_str(atomic, NULL,
    1.88 -						   strerror(errno));
    1.89 +			atomic->error = razor_error_new_str(NULL,
    1.90 +							    strerror(errno));
    1.91  
    1.92  			(void)close(fd);
    1.93  
    1.94 @@ -179,13 +137,10 @@
    1.95  		return -1;
    1.96  
    1.97  	if (fsync(handle) < 0) {
    1.98 -		razor_atomic_set_error_str(atomic, NULL, strerror(errno));
    1.99 +		atomic->error = razor_error_new_str(NULL, strerror(errno));
   1.100  		return -1;
   1.101  	}
   1.102  
   1.103 -	free(atomic->error_path);
   1.104 -	atomic->error_path = NULL;
   1.105 -
   1.106  	return 0;
   1.107  }
   1.108  
   1.109 @@ -196,13 +151,10 @@
   1.110  		return -1;
   1.111  
   1.112  	if (close(fd) < 0) {
   1.113 -		razor_atomic_set_error_str(atomic, NULL, strerror(errno));
   1.114 +		atomic->error = razor_error_new_str(NULL, strerror(errno));
   1.115  		return -1;
   1.116  	}
   1.117  
   1.118 -	free(atomic->error_path);
   1.119 -	atomic->error_path = NULL;
   1.120 -
   1.121  	return 0;
   1.122  }
   1.123