libndr: Add ndr_map_error2errno
authorVolker Lendecke <vl@samba.org>
Mon, 13 Feb 2012 12:27:22 +0000 (13:27 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 13 Feb 2012 14:06:28 +0000 (15:06 +0100)
Autobuild-User: Volker Lendecke <vl@samba.org>
Autobuild-Date: Mon Feb 13 15:06:29 CET 2012 on sn-devel-104

librpc/ndr/libndr.h
librpc/ndr/ndr_basic.c

index 162c10978105c5fb6f8155420db55369b4727343..36adae91c0ad09b23dfbc91ffe2ffc67b95dfc96 100644 (file)
@@ -407,6 +407,7 @@ struct sockaddr_storage;
  Map an NT error code from a NDR error code.
 *********************************************************************/
 NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err);
+int ndr_map_error2errno(enum ndr_err_code ndr_err);
 const char *ndr_map_error2string(enum ndr_err_code ndr_err);
 #define ndr_errstr ndr_map_error2string
 
index 7b164385d47482a15d0ffbba974069c44d5e4c03..7a4e22ad700f1783cc51c467b789ba02da7e019e 100644 (file)
@@ -1339,6 +1339,31 @@ _PUBLIC_ NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err)
        return NT_STATUS_INVALID_PARAMETER;
 }
 
+_PUBLIC_ int ndr_map_error2errno(enum ndr_err_code ndr_err)
+{
+       switch (ndr_err) {
+       case NDR_ERR_SUCCESS:
+               return 0;
+       case NDR_ERR_BUFSIZE:
+               return ENOSPC;
+       case NDR_ERR_TOKEN:
+               return EINVAL;
+       case NDR_ERR_ALLOC:
+               return ENOMEM;
+       case NDR_ERR_ARRAY_SIZE:
+               return EMSGSIZE;
+       case NDR_ERR_INVALID_POINTER:
+               return EINVAL;
+       case NDR_ERR_UNREAD_BYTES:
+               return EOVERFLOW;
+       default:
+               break;
+       }
+
+       /* we should map all error codes to different status codes */
+       return EINVAL;
+}
+
 _PUBLIC_ enum ndr_err_code ndr_push_timespec(struct ndr_push *ndr,
                                             int ndr_flags,
                                             const struct timespec *t)