File: error_windows.go

package info (click to toggle)
golang-github-bmatsuo-lmdb-go 1.8.0%2Bgit20170215.a14b5a3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 840 kB
  • sloc: ansic: 8,247; makefile: 19
file content (43 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package lmdb

/*
#include <errno.h>
#include "lmdb.h"
*/
import "C"
import "syscall"

func operrno(op string, ret C.int) error {
	if ret == C.MDB_SUCCESS {
		return nil
	}
	if minErrno <= ret && ret <= maxErrno {
		return &OpError{Op: op, Errno: Errno(ret)}
	}

	// translate C errors into corresponding syscall.Errno values so that
	// IsErrnoSys functions correctly, a kludge unknowning inherited from LMDB.
	// the errno in the returned OpError cannot be passed to C.mdb_strerror.
	// see the implementation of C.mdb_strerror for information about how the
	// following table was generated.
	var errno syscall.Errno
	switch ret {
	case C.ENOENT:
		errno = syscall.ENOENT /* 2, FILE_NOT_FOUND */
	case C.EIO:
		errno = syscall.EIO /* 5, ACCESS_DENIED */
	case C.ENOMEM:
		errno = syscall.ENOMEM /* 12, INVALID_ACCESS */
	case C.EACCES:
		errno = syscall.EACCES /* 13, INVALID_DATA */
	case C.EBUSY:
		errno = syscall.EBUSY /* 16, CURRENT_DIRECTORY */
	case C.EINVAL:
		errno = syscall.EINVAL /* 22, BAD_COMMAND */
	case C.ENOSPC:
		errno = syscall.ENOSPC /* 28, OUT_OF_PAPER */
	default:
		errno = syscall.Errno(ret)
	}
	return &OpError{Op: op, Errno: errno}
}