libclu/util: Move get_friendly_nt_error_msg() in common.
authorAndrew Bartlett <abartlet@samba.org>
Thu, 16 Jun 2011 03:00:09 +0000 (13:00 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 17 Jun 2011 07:08:59 +0000 (17:08 +1000)
Andrew Bartlett

Signed-off-by: Andrew Tridgell <tridge@samba.org>
libcli/util/nterr.c
libcli/util/ntstatus.h
source3/libsmb/nterr.c
source4/libcli/util/nterr.c

index 5f31c3c0c2a16a8b855c5948c6d487fee305083e..1e84e81878338c6d2600762036920487747167bf 100644 (file)
@@ -906,3 +906,46 @@ NTSTATUS nt_status_squash(NTSTATUS nt_status)
                return nt_status;
        }
 }
+
+/*****************************************************************************
+ Returns an NT error message.  not amazingly helpful, but better than a number.
+
+ This version is const, and so neither allocates memory nor uses a
+ static variable for unknown errors.
+ *****************************************************************************/
+
+const char *nt_errstr_const(NTSTATUS nt_code)
+{
+       static char msg[40];
+       int idx = 0;
+
+       while (nt_errs[idx].nt_errstr != NULL) {
+               if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
+                   NT_STATUS_V(nt_code)) {
+                       return nt_errs[idx].nt_errstr;
+               }
+               idx++;
+       }
+
+       return "unknown NT_STATUS error";
+}
+
+/************************************************************************
+ Print friendler version fo NT error code
+ ***********************************************************************/
+
+const char *get_friendly_nt_error_msg(NTSTATUS nt_code)
+{
+       int idx = 0;
+
+       while (nt_err_desc[idx].nt_errstr != NULL) {
+               if (NT_STATUS_V(nt_err_desc[idx].nt_errcode) == NT_STATUS_V(nt_code)) {
+                       return nt_err_desc[idx].nt_errstr;
+               }
+               idx++;
+       }
+
+       /* fall back to NT_STATUS_XXX string */
+
+       return nt_errstr_const(nt_code);
+}
index 13ce733ca31aac84088b67a6cd4402d7fdac3810..2f1635093b85a04e734c85c5b38e74f52c6a64c8 100644 (file)
@@ -628,6 +628,15 @@ typedef uint32_t NTSTATUS;
  * this means we need a torture test */
 #define NT_STATUS_FOOBAR NT_STATUS_UNSUCCESSFUL
 
+/*****************************************************************************
+ Returns an NT error message.  not amazingly helpful, but better than a number.
+
+ This version is const, and so neither allocates memory nor uses a
+ static variable for unknown errors.
+ *****************************************************************************/
+
+const char *nt_errstr_const(NTSTATUS nt_code);
+
 /*****************************************************************************
  returns an NT error message.  not amazingly helpful, but better than a number.
  *****************************************************************************/
index 7d0b3d08fd4802943b7cf79470e1e2cc9afbd675..a4a388303dfd0cafddfb95359c6996dd644241a0 100644 (file)
@@ -55,23 +55,3 @@ const char *nt_errstr(NTSTATUS nt_code)
        return result;
 }
 
-/************************************************************************
- Print friendler version fo NT error code
- ***********************************************************************/
-
-const char *get_friendly_nt_error_msg(NTSTATUS nt_code)
-{
-       int idx = 0;
-
-       while (nt_err_desc[idx].nt_errstr != NULL) {
-               if (NT_STATUS_V(nt_err_desc[idx].nt_errcode) == NT_STATUS_V(nt_code)) {
-                       return nt_err_desc[idx].nt_errstr;
-               }
-               idx++;
-       }
-
-       /* fall back to NT_STATUS_XXX string */
-
-       return nt_errstr(nt_code);
-}
-
index ea8c0fcd35e80df6633f39083042cb9671e9c2c1..1532b5b787caab8c8de6a753fd59ba69c1a6e372 100644 (file)
@@ -52,23 +52,3 @@ const char *nt_errstr(NTSTATUS nt_code)
 
        return msg;
 }
-
-/************************************************************************
- Print friendler version fo NT error code
- ***********************************************************************/
-
-const char *get_friendly_nt_error_msg(NTSTATUS nt_code)
-{
-       int idx = 0;
-
-       while (nt_err_desc[idx].nt_errstr != NULL) {
-               if (NT_STATUS_V(nt_err_desc[idx].nt_errcode) == NT_STATUS_V(nt_code)) {
-                       return nt_err_desc[idx].nt_errstr;
-               }
-               idx++;
-       }
-
-       /* fall back to NT_STATUS_XXX string */
-
-       return nt_errstr(nt_code);
-}